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_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): # type (HandlerInput) -> Response logger.info("HAN ExitIntentHandler") speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) ## TODO: Implement sesh performance func. ms_session_performance = ExitUtils.get_ms_session_performance( handler_input) ms_exit = ExitUtils.get_ms_exit_game() speech_list.append(ms_session_performance) speech_list.append(ms_exit) speech = ' '.join(speech_list) card_title, card_text = CardFuncs.get_card_info(handler_input, speech) ## Attr management @ very end. ExitUtils.update_player_mode_statistics(handler_input, player_obj) PlayerDict.save_player_obj(handler_input, player_obj) ExitUtils.exit_skill_attr_management(handler_input) return (handler_input.response_builder.speak(speech).set_card( SimpleCard(card_title, card_text)).set_should_end_session(True).response)
def increment_fp_plays(handler_input, player_obj: object = None) -> None: """Increments fp_plays for player.""" if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) player_obj.fp_plays += 1 PlayerDict.save_player_obj(handler_input, player_obj) return
def handle(self, handler_input): logger.info( f"SessionEndedRequest: {handler_input.request_envelope.request.reason}" ) player_obj = PlayerDict.load_player_obj(handler_input) ExitUtils.update_player_mode_statistics(handler_input, player_obj) PlayerDict.save_player_obj(handler_input, player_obj) ExitUtils.exit_skill_attr_management(handler_input) return handler_input.response_builder.response
def handle(self, handler_input): logger.info("HAN CreateUserProfileHandler") user_name = SlotUtils.get_first_slot_value(handler_input) if not user_name: logger.info("HAN RetryUserName") ms_welcome = UserProfileUtils.get_ms_welcome(handler_input) ms_retry_name = UserProfileUtils.get_ms_did_not_hear_name() prompt, reprompt = ( UserProfileUtils.get_q_retry_name() for _ in range(2)) prompt = CardFuncs.format_prompt(prompt) speech_list = ( ms_welcome, 0.5, ms_retry_name, 1.75, prompt ) else: logger.info("HAN CreatedProfile") UserProfileUtils.set_sesh_attr(handler_input, user_name) PlayerDict.create_new_player(handler_input, user_name) ms_confirm = ConfirmUtils.get_player_confirmation(handler_input) ms_created_first_profile = UserProfileUtils.get_ms_created_first_profile(handler_input) ms_overview = HelpUtils.get_ms_act_descript() prompt, reprompt = ( HelpUtils.get_q_what_todo() for _ in range(2)) prompt = CardFuncs.format_prompt(prompt) speech_list = ( ms_confirm, 1, ms_created_first_profile, 3, ms_overview, 2.25, prompt ) speech = get_linear_nlg(speech_list) 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_higher_table_difficulty( handler_input, player_obj: object = None, tables: tuple = None, answered_tables: list = None ) -> float: """Returns z_score for the table with the highest difficulty. Difficulty is a constructed measure dependent on greatness of tables, e.g., 6 > 5.""" if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) if tables is None: tables = QuestionAttr.get_question_tables(handler_input, integers=True) if answered_tables is None: answered_tables = player_obj.get_answered_tables(integers = True) inflated_mean_table = mean(answered_tables) + 1 higher_table = max( [int(table) for table in tables]) z_score = calc_z_score( data_point= higher_table, data_mean = inflated_mean_table, data= answered_tables, required_data_length= stats.data.SUF_ANSWERED_TABLES ) return z_score
def handle(self, handler_input): logger.info("HAN FP_WrongAnswerHandler") speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats(handler_input, correct=False, player_obj=player_obj) WrongAnswer.record_wrong_question(handler_input) ms_incorrect = IncorrectAnsUtils.get_buzz_and_incorrect() ms_retry_question = AllQuestionIntros.get_retry_question(handler_input) reprompt = GenQuestions.get_same_question(handler_input) speech_list += Pauser.make_ms_pause_level_list(ms_incorrect, 1, ms_retry_question) SessionStats.update_consecutive_correct(handler_input, correct=False) ModeStats.update_mode_stats(handler_input, correct=False) logger.debug(speech_list) speech = ' '.join(speech_list) 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 SM_CorrectQuestionHandler") speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats(handler_input, correct = True, player_obj= player_obj) SM_Attr.increment_sm_upper(handler_input) ms_congrats = CongratUtils.get_answer_congrats( handler_input, player_obj= player_obj, survival_mode=True) logger.debug(ms_congrats) ms_question = SMQuestions.get_question( handler_input, first_question= False, player_obj= player_obj) reprompt = GenQuestions.get_same_question(handler_input) if len(ms_congrats): sm_pause = Pauser.get_sm_pause_length(handler_input) speech_list += Pauser.make_ms_pause_level_list(ms_congrats, sm_pause) speech_list.append( ms_question) SessionStats.update_consecutive_correct(handler_input, True) ModeStats.update_mode_stats(handler_input, True) speech = ' '.join(speech_list) 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 FP_CorrectAnswerHandler") speech_list = [] 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 = FPQuestions.get_question(handler_input) reprompt = FPQuestions.get_rephrased_question(handler_input) logger.debug(ms_congrats) if ms_congrats != "": speech_list += Pauser.make_ms_pause_level_list( ms_congrats, 1, ms_question) else: speech_list.append(ms_question) SessionStats.update_consecutive_correct(handler_input, correct=True) ModeStats.update_mode_stats(handler_input, correct=True) logger.debug(speech_list) speech = ' '.join(speech_list) 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_welcome(handler_input) -> str: """Returns appropriate welcome message for survival mode.""" player = PlayerDict.load_player_obj(handler_input) sm_plays = player.sm_plays random_num = random.random() if sm_plays == 0: ms_welcome = SM_WelcomeUtils.get_ms_first_welcome() elif sm_plays == 1: ms_welcome = SM_WelcomeUtils.get_ms_long_welcome() elif (sm_plays > 5) and (random_num < 0.25): ms_welcome = SM_WelcomeUtils.get_ms_high_score_welcome(player) elif (sm_plays > 5) and (random_num < 0.5): ms_welcome = SM_WelcomeUtils.get_ms_average_score_welcome(player) elif random_num < 0.8: ms_welcome = SM_WelcomeUtils.get_ms_short_welcome() else: ms_welcome = SM_WelcomeUtils.get_ms_long_welcome() return MW_EXCITED_LOW.format(ms_welcome)
def handle(self, handler_input): logger.info("HAN SC_FinishedChallengeHandler") speech_list = [] SC_Attr.save_end_time(handler_input) sc_score_time = SC_Attr.get_sc_total_time(handler_input) player_obj = PlayerDict.load_player_obj(handler_input) SessionStats.update_consecutive_correct(handler_input, correct=True) ModeStats.update_mode_stats(handler_input, correct=True) UserStats.update_player_stats(handler_input, correct=True, player_obj=player_obj) ms_congrats = CongratUtils.get_player_congrats(handler_input, 2) ms_complete_time = SC_EndGame.get_ms_game_score( handler_input, sc_score_time) ms_score_results = SC_EndGame.get_ms_score_results( handler_input, sc_score_time=sc_score_time, player_obj=player_obj) ms_thanks = get_ms_thanks(handler_input, mode=True, excite=True) prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2)) speech_list = ( ms_congrats, 1, ms_complete_time, 1.5, ms_score_results, 1.75, ms_thanks, 4, prompt, ) SC_Attr.log_sc_stats(handler_input) ModeStats.translate_mode_stats_to_sesh(handler_input) UserStats.update_player_sc_stats(handler_input, sc_score_time=sc_score_time, player_obj=player_obj) SC_Attr.set_attr_end_sc(handler_input) PlayerDict.save_player_obj(handler_input, player_obj) speech = get_linear_nlg(speech_list) 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 update_player_sm_stats(handler_input, player_obj: object = None) -> None: """Updates the player's Survival Mode stats.""" attr = handler_input.attributes_manager.session_attributes mode = attr.get('mode', None) correct, _ = ModeStats.get_mode_stats(handler_input, mode= mode) if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) if correct > player_obj.get_sm_high_score(): player_obj.set_sm_high_score(correct) player_obj.update_sm_records(correct) player_obj.sm_plays += 1 PlayerDict.save_player_obj(handler_input, player_obj) return None
def update_player_stats(handler_input, correct: bool, player_obj: object = None) -> None: """Updates the user profile statistics. Increments the correct / incorrect counters. Updates the average tables and the info for each times table.""" attr = handler_input.attributes_manager.session_attributes tables = attr['question'] if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) player_obj.increment_answer_counter(correct) player_obj.update_average_table(tables) player_obj.update_times_tables_info_dict(tables, correct) PlayerDict.save_player_obj(handler_input, player_obj) return
def get_ms_welcome(handler_input) -> str: """Returns welcome message for Free Play mode.""" player = PlayerDict.load_player_obj(handler_input) if player.fp_plays in [0, 1]: ms_welcome = free_play.data.MS_FP_FIRST_WELCOME elif not player.fp_plays % 4: ms_welcome = free_play.data.MS_FP_INCLUDE_PARAMS else: ms_welcome = free_play.data.MS_FP_WELCOME return MW_EXCITED_LOW.format(ms_welcome)
def get_sm_z_score(handler_input, sm_score: int, player_obj: object = None) -> bool: """Returns z_score for the Survival mode score.""" if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) sm_average_records = [int(num) for num in player_obj._sm_average_records] z_score = calc_z_score( data_point= sm_score, data = sm_average_records ) return z_score
def handle(self, handler_input): logger.info("HAN SM_WrongAnswerHandler") player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats( handler_input, correct = False, player_obj= player_obj) WrongAnswer.record_wrong_question(handler_input) ms_incorrect = IncorrectAnsUtils.get_buzz_and_incorrect() ms_correct_ans = GetAnswerSpeech.get_ms_answer(handler_input) ms_score = SMEndGame.get_ms_game_score(handler_input) ms_congrats = CongratUtils.get_player_congrats(handler_input, 1) ms_results = SMEndGame.get_ms_score_results( handler_input, player_obj= player_obj) ms_thanks = get_ms_thanks(handler_input, mode = True, excite=True) prompt, reprompt = ( HelpUtils.get_q_what_todo() for _ in range(2)) speech_list = ( ms_incorrect, 1, ms_correct_ans, 2, ms_congrats, 0.75, ms_score, 1.25, ms_results, 1.75, ms_thanks, 4.5, prompt, ) SM_Attr.log_stats(handler_input) SessionStats.update_consecutive_correct(handler_input, correct= False) ModeStats.update_mode_stats(handler_input, correct= False) UserStats.update_player_sm_stats(handler_input, player_obj= player_obj) #before translating mode stats SM_Attr.set_attr_end_survival_mode(handler_input) ModeStats.translate_mode_stats_to_sesh(handler_input) speech = get_linear_nlg(speech_list) 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 update_player_sc_stats( handler_input, sc_score_time: int, player_obj: object = None) -> None: """Updates the player's Speed Challenge stats.""" attr = handler_input.attributes_manager.session_attributes sc_difficulty = attr['sc_difficulty'] if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) player_obj.set_sc_high_score(sc_difficulty, sc_score_time) player_obj.update_sc_average_record(sc_difficulty, sc_score_time) player_obj.sc_plays += 1 return None
def calculate_excite_level(handler_input, player_obj: object = None, survival_mode: bool = False) -> int: """Returns congratulations level to return to the user. Conditions checked: - Consecutive incorrect - Consecutive correct - If user has high (f) error on table - Table difficulty vs average table difficulty """ attr = handler_input.attributes_manager.session_attributes consecutive_incorrect = attr.get('consecutive_incorrect', 0) consecutive_correct = attr.get('consecutive_correct', 0) consecutive_correct = (consecutive_correct + 1) if consecutive_correct is not None else 1 excite_level = 0 if consecutive_incorrect and (not survival_mode): return consecutive_incorrect - (1 - random.random()) elif ((consecutive_correct) % 5 == 0) and (not survival_mode): return CongratLevel.get_level_consecutive_correct( consecutive_correct) tables = QuestionAttr.get_question_tables(handler_input, integers=False) if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) ## Check table error frequency higher_f_error = UserStats.get_higher_table_error_freq( handler_input, player_obj=player_obj, tables=tables) logger.debug(f"higher_f_error {higher_f_error}") if higher_f_error >= 1.5: ## Arbitrary value. NOTE: Revist. return higher_f_error ## Check Relative Table difficulty higher_table_difficulty = UserStats.get_higher_table_difficulty( handler_input, player_obj=player_obj, tables=tables) logger.debug(f"higher_table_difficulty {higher_table_difficulty}") if higher_table_difficulty > 1.5: return higher_table_difficulty return excite_level
def get_ms_question_intro(handler_input, first_question: bool, player_obj: object = None) -> str: """Returns message for the question introduction. NOTE: No confirmation in this mode.""" attr = handler_input.attributes_manager.session_attributes flag_double_digits = attr.get('flag_double_digits', False) flag_upper_hit_avg = attr.get('flag_upper_hit_avg', False) flag_cntr_hit_avg = attr.get('flag_cntr_hit_avg', False) sm_upper = int(attr.get('sm_upper', 0)) sm_center = int(sm_upper / 1.1) questions_answered = attr.get('questions_answered', 0) if first_question: return AllQuestionIntros.get_first_question_intro() elif (sm_upper == 10) and flag_double_digits: attr['flag_double_digits'] = False return SMQuestions.get_ms_upper_as_ten() ## Load objs to avoid repetitive loads. if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) answered_tables = player_obj.get_answered_tables(integers=True) inflated_average_table = int( mean(answered_tables)) + 2 ## Note a truth average log_all(sm_upper, sm_center, inflated_average_table, questions_answered) if (sm_upper == inflated_average_table - 2 ) and flag_upper_hit_avg: ## when sm_upper is uninflated_average. attr['flag_upper_hit_avg'] = False return SMQuestions.get_ms_upper_as_average_table() elif (sm_center == inflated_average_table) and flag_cntr_hit_avg: attr['flag_cntr_hit_avg'] = False return SMQuestions.get_ms_freq_average_table() return SMQuestions.get_ms_relative_difficulty( handler_input, player_obj=player_obj, answered_tables=answered_tables)
def handle(self, handler_input): logger.info("HAN ModeStatsHandler") attr = handler_input.attributes_manager.session_attributes speech_list = [] player_obj = PlayerDict.load_player_obj(handler_input) mode = attr.get('mode', None) activity = SlotUtils.get_resolved_value(handler_input, 'activity') activity = activity if activity else mode difficulty = True if activity == 'survival': speech_list += ModeSpeech.get_ms_sm_stats(player_obj, activity) elif activity == 'speed': difficulty = SlotUtils.get_resolved_value(handler_input, 'difficulty') sc_difficulty = difficulty if difficulty else attr.get( 'sc_difficulty', None) if (difficulty in speed_challenge.data.SC_DIFFICULTIES): speech_list += ModeSpeech.get_ms_sc_stats( player_obj, sc_difficulty, activity) else: reprompt = ModeSpeech.get_ms_sc_what_difficulty() speech_list += reprompt reprompt = get_linear_nlg(reprompt) else: ms_can_tell_record = ModeSpeech.get_ms_can_tell_record() ms_example_saying = ModeSpeech.get_example_hear_records() speech_list = [ms_can_tell_record, 2, ms_example_saying] reprompt = HelpUtils.get_q_what_todo() if activity in ('survival', 'speed') and (difficulty): prompt, reprompt = (LastPrompt.get_last_prompt(handler_input) for _ in range(2)) speech_list += Pauser.make_ms_pause_level_list(3, prompt) speech = get_linear_nlg(speech_list) 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 SC_CorrectAnswerHandler") ## TODO: Check sc attr and if anything needs to be incremented?? player_obj = PlayerDict.load_player_obj(handler_input) UserStats.update_player_stats(handler_input, correct=True, player_obj=player_obj) question = SC_Questions.get_question(handler_input) reprompt = question SessionStats.update_consecutive_correct(handler_input, correct=True) ModeStats.update_mode_stats(handler_input, correct=True) speech = question 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_higher_table_error_freq( handler_input, player_obj: object = None, tables: tuple = None ) -> float: """Returns z_score for the highest error tables.""" if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) if tables is None: tables = QuestionAttr.get_question_tables(handler_input, integers=False) times_tables_info = player_obj.get_times_table_info() times_tables_mean_err_list = [] for table in times_tables_info.keys(): table_mean = float(times_tables_info[table]['mean']) table_data = times_tables_info[table]['table_data'] if len(table_data) > stats.data.SUF_TABLE_DATA: times_tables_mean_err_list.append(1 - table_mean) # inversed, so errors are higher. ## Exit if not enough data. if len(times_tables_mean_err_list) <= stats.data.SUF_ERR_LIST: return 0 question_tables_err = [] for table in tables: table = str(table) table_info = float( times_tables_info[table]['mean']) table_info = (1 - table_info) # inverse mean. question_tables_err.append( table_info) max_table_err = max(question_tables_err) z_score = calc_z_score( data_point= max_table_err, data= times_tables_mean_err_list, ) return ( z_score)
def handle(self, handler_input): logger.info("HAN SC_StartHandler") speech_list = [] SC_Attr.set_attr_start_sc(handler_input) player_obj = PlayerDict.load_player_obj(handler_input) difficulty = SlotUtils.get_resolved_value(handler_input, 'difficulty') if not difficulty: ms_welcome = SC_WelcomeUtils.get_ms_welcome(player_obj) q_difficulty, reprompt = ( SC_Difficulty.get_q_sc_difficulty(player_obj) for _ in range(2)) speech_list += Pauser.make_ms_pause_level_list( ms_welcome, 2, q_difficulty) elif difficulty: SC_Attr.set_sc_diff(handler_input, difficulty) ms_confirmation = ConfirmUtils.get_confirmation(True) ms_use_difficulty = SC_Difficulty.get_ms_using_difficulty( difficulty) SC_Questions.load_sc_questions(handler_input) ms_start_timer = SC_WelcomeUtils.get_ms_starting_time() question = SC_Questions.get_question(handler_input, first_question=True) reprompt = question speech_list += Pauser.make_ms_pause_level_list( ms_confirmation, 0.5, ms_use_difficulty, 2, ms_start_timer, question) SC_Attr.save_start_time(handler_input) speech = ' '.join(speech_list) 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_score_results(handler_input, player_obj: object = None) -> str: """Returns message about the user's relative SM score.""" attr = handler_input.attributes_manager.session_attributes mode = attr.get('mode', None) if not player_obj: player_obj = PlayerDict.load_player_obj(handler_input) sm_high_score = player_obj.get_sm_high_score() sm_score, _ = ModeStats.get_mode_stats(handler_input, mode= mode) if SM_Attr.check_sm_highscore(sm_high_score, sm_score): if SM_Attr.check_first_highscore(sm_high_score, sm_score): return SMEndGame.get_ms_first_highscore(sm_score) return SMEndGame.get_ms_new_highscore(sm_score, sm_high_score) elif SM_Attr.check_sm_tie_highscore(sm_high_score, sm_score): return SMEndGame.get_ms_tied_highscore(sm_high_score) else: return SMEndGame.get_ms_relative_attempt_success( handler_input, sm_score, player_obj= player_obj)
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)