Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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_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 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
Exemplo n.º 9
0
    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)