def handle(self, handler_input): logger.info("HAN CP_WrongAnswerHandler") speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) CP_Attr.update_last_question_attr(handler_input, correct=False) UserStats.update_player_stats(handler_input, correct=False, player_obj=player_obj) ms_wrong = IncorrectAnsUtils.get_ms_incorrect() question = GenQuestions.get_same_question(handler_input) reprompt = question speech_list = ( ms_wrong, 1, question, ) SessionStats.update_consecutive_correct(handler_input, correct=False) ModeStats.update_mode_stats(handler_input, correct=False) WrongAnswer.record_wrong_question(handler_input) PlayerDict.save_player_obj(handler_input, player_obj) speech = get_linear_nlg(speech_list) reprompt = GenQuestions.get_same_question(handler_input) card_title, card_text = CardFuncs.get_card_info(handler_input, speech) return (handler_input.response_builder.speak(speech).ask( reprompt).set_card(SimpleCard(card_title, card_text)).response)
def handle(self, handler_input): logger.info("HAN CP_CorrectAnswerHandler") attr = handler_input.attributes_manager.session_attributes speech_list = [] practice_type = attr['practice_type'] if practice_type == custom_practice.data.PRACT_TYPES[0]: CP_Attr.remove_question_from_incorrect_questions( handler_input) ## Before updating last question CP_Attr.update_last_question_attr(handler_input, correct=True) player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats(handler_input, correct=True, player_obj=player_obj) ms_congrats = CongratUtils.get_answer_congrats(handler_input, player_obj=player_obj) ms_question = CP_Questions.get_question(handler_input, player_object=player_obj, practice_type=practice_type, first_question=False) reprompt = GenQuestions.get_same_question(handler_input) speech_list = (ms_congrats, 1, ms_question) SessionStats.update_consecutive_correct(handler_input, True) ModeStats.update_mode_stats(handler_input, True) PlayerDict.save_player_obj(handler_input, player_obj) speech = get_linear_nlg(speech_list) reprompt = GenQuestions.get_same_question(handler_input) card_title, card_text = CardFuncs.get_card_info(handler_input, speech) return (handler_input.response_builder.speak(speech).ask( reprompt).set_card(SimpleCard(card_title, card_text)).response)
def handle(self, handler_input): logger.info("HAN CP_StartHandler") player_obj = PlayerDict.load_player_obj(handler_input) ## Check Sufficient Data ## NOTE: make like to refacor this into a method that returns response object ## That will remove the nested loop below. answered_questions = player_obj.get_answered_questions() if answered_questions < custom_practice.data.MIN_DATA_REQUIRED: prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2)) speech_list = ( CP_Welcome.get_ms_need_more_data(answered_questions), 2, prompt, ) else: CP_Attr.set_attr_start_cp(handler_input) CP_Attr.set_tbl_mean_err_list_attr( handler_input, player_obj) # used in practice type ms_welcome = CP_Welcome.get_ms_welcome(handler_input, player_obj) practice_type = CP_PracticeType.get_practice_type( handler_input, allow_incorrect_problems=True) CP_Attr.save_practice_type(handler_input, practice_type) CP_Attr.set_pract_type_attr(handler_input, player_obj, practice_type) CP_Attr.update_last_question_attr(handler_input, correct=True) ms_practice_intro = CP_PractIntro.get_ms_practice_type_intro( handler_input, practice_type) question = CP_Questions.get_question(handler_input, player_obj, practice_type, first_question=True) reprompt = GenQuestions.get_same_question(handler_input) speech_list = ( ms_welcome, 2.5, ms_practice_intro, 2, question, ) speech = get_linear_nlg(speech_list) reprompt = GenQuestions.get_same_question(handler_input) card_title, card_text = CardFuncs.get_card_info(handler_input, speech) return (handler_input.response_builder.speak(speech).ask( reprompt).set_card(SimpleCard(card_title, card_text)).response)
def get_ms_practice_high_zscore_tables(handler_input) -> str: """Returns message to practice high relative error tables.""" tables_to_practice = CP_Attr.get_top_z_score_err_tables(handler_input) ms_tables_to_practice = get_str_from_list(tables_to_practice, punct=False) ms_times_tables_syn = random.choice( custom_practice.data.MT_TIMES_TABLE_SYN) + '.' speech_list_1 = list(custom_practice.data.MMT_HIGH_Z_SCORE) speech_list_2 = [ ms_tables_to_practice, ms_times_tables_syn, 1, custom_practice.data.MMT_PRACTICE_THOSE, ] speech_list = (speech_list_1 + speech_list_2 + CP_PractIntro.get_ms_num_in_row_to_complete()) return get_linear_nlg(speech_list)
def handle(self, handler_input): logger.info("HAN CP_NextPracticeHandler") attr = handler_input.attributes_manager.session_attributes speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats(handler_input, correct=True, player_obj=player_obj) CP_Attr.set_attr_new_practice(handler_input) CP_Attr.set_tbl_mean_err_list_attr(handler_input, player_obj) practice_type = attr['practice_type'] ms_end_pract_type = CP_PractEnd.get_ms_practice_type_end( handler_input, practice_type=practice_type) if practice_type == custom_practice.data.PRACT_TYPES[0]: CP_Attr.remove_question_from_incorrect_questions(handler_input) ms_congrats = CongratUtils.get_player_congrats(handler_input) if practice_type != custom_practice.data.PRACT_TYPES[-1]: practice_type = CP_PracticeType.get_practice_type( handler_input, allow_incorrect_problems=False) CP_Attr.save_practice_type(handler_input, practice_type) CP_Attr.set_pract_type_attr(handler_input, player_obj, practice_type) CP_Attr.update_last_question_attr(handler_input, correct=True) ms_practice_intro = CP_PractIntro.get_ms_practice_type_intro( handler_input, practice_type=practice_type) question = CP_Questions.get_question(handler_input, player_obj, practice_type, first_question=True) reprompt = GenQuestions.get_same_question(handler_input) speech_list = ( ms_congrats, 0.5, ms_end_pract_type, 2.5, ms_practice_intro, 2, question, ) else: UserStats.update_player_cp_stats(handler_input, player_obj) prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2)) speech_list = (ms_congrats, 0.5, ms_end_pract_type, 2, prompt) SessionStats.update_consecutive_correct(handler_input, True) ModeStats.update_mode_stats(handler_input, True) PlayerDict.save_player_obj(handler_input, player_obj) speech = get_linear_nlg(speech_list) reprompt = GenQuestions.get_same_question(handler_input) card_title, card_text = CardFuncs.get_card_info(handler_input, speech) return (handler_input.response_builder.speak(speech).ask( reprompt).set_card(SimpleCard(card_title, card_text)).response)
def can_handle(self, handler_input): attr = handler_input.attributes_manager.session_attributes return (attr.get('mode', None) == 'custom' and is_intent_name("AnswerIntent")(handler_input) and QuestionChecker.check_answer(handler_input) and CP_Attr.check_last_question(handler_input))