[docs]classFinalizingState(BaseState):"""State for finalizing the assessment after all questions have been answered."""RESPONSE_VARIATIONS=["Okay, we've finished with those questions. Thanks so much for sharing all of that with me – it really does take courage to open up. Just a gentle reminder, if things ever feel too heavy, talking things through with a professional can make a real difference.","That's the end of that set of questions. Thanks for taking the time to reflect and answer. Understanding how we're feeling is a really important step. And remember, if you feel you need more support down the line, professionals are there to help.","We made it through all the questions! Thank you for putting in the effort to think about and answer them, I appreciate your honesty. Please keep in mind that reaching out for professional support is always an option if you feel you need it.","Alright, that's all of them! Seriously, thanks for walking through that with me. Talking helps, right? And just so you know, if things ever feel overwhelming, chatting with a professional is always a solid choice.","Finished! Thanks for being open and answering those questions. It's really positive that you're checking in with your feelings. Just wanted to gently add, reaching out to a professional is a strong step to take if you ever feel you need extra support.","Okay, we're done with those questions for now. Thanks for sharing your thoughts. And hey, never hesitate to seek professional help if you feel it could be useful, okay?"]
[docs]defgenerate_response(self,user_input,conversation_id,assessment_id):# Calculating the total score based on the answerstotal_score=self.context.assess_repo.calculate_total_score(assessment_id)total_score=total_scoreiftotal_scoreisnotNoneelse0print(f"Total score calculated: {total_score}")# Get total-score interpretationassessment=self.context.assess_repo.get_assessment(assessment_id)interpretations=self.context.questionnaires[assessment.assessment_type]['interpretations']interpretation_text="Not available"forinterpretation_range,interpretationininterpretations.items():# Split the range into lower and upper boundslower,upper=map(int,interpretation_range.split('-'))# Check if the score is within the rangeiflower<=total_score<=upper:interpretation_text=interpretationbreakprint(f"Interpretation text: {interpretation_text}")# Closing the assessmentself.context.assess_repo.update_assessment(assessment_id,end_time=datetime.now(timezone.utc),total_score=total_score,interpretation=interpretation_text,current_state=self.context.STATE_FINISHED,last_free_text=None)# Returning assesment object to the initial state# In case another assessment is startedfromkusibot.chatbot.assesment_states.asking_question_stateimportAskingQuestionStateself.context._transition_to_next_state(AskingQuestionState())# Get the final messagereturnrandom.choice(self.RESPONSE_VARIATIONS)