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 get_question(handler_input,
                     first_question: bool = False,
                     player_obj: object = None) -> str:
        """Returns a question for survival mode."""
        if not first_question:
            QuestionAttr.increment_questions_answered(handler_input)

        ## Get new question
        flag_get_new_question = True
        while flag_get_new_question:
            new_question = SMQuestions.get_sampled_num(handler_input)

            if not GenQuestions.check_same_question(handler_input,
                                                    new_question):
                flag_get_new_question = False

        ## Save question
        QuestionAttr.save_question(handler_input, new_question)

        ## Messages
        ms_question_intro = SMQuestions.get_ms_question_intro(
            handler_input,
            first_question=first_question,
            player_obj=player_obj)
        ms_question = GenQuestions.format_question(new_question)

        speech_list = (ms_question_intro, ms_question)
        return get_linear_nlg(speech_list)
    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)
Exemple #5
0
    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 get_retry_question(handler_input) -> str:
     """Returns the same question to retry."""
     question = GenQuestions.get_same_question(handler_input)
     
     ms_retry = AllQuestionIntros.get_ms_retry_question(handler_input)
     speech_list = (ms_retry, question)
     return ' '.join(speech_list)
    def get_ms_question_intro(
        handler_input,
        player_object: object,
        practice_type: str,
        first_question: bool,
        question: tuple,
    ) -> str:
        """Returns message for beginning of question."""

        if first_question:
            return AllQuestionIntros.get_first_question_intro()

        elif (practice_type == custom_practice.data.PRACT_TYPES[0]
              and GenQuestions.check_same_question(handler_input, question)):
            return CP_Questions.get_ms_practice_incorrect_problem_more()

        random_num = random.random()
        if random_num < 0.4:
            return AllQuestionIntros.get_question_intro_as_interrogative(
                handler_input)

        elif random_num < 0.7:
            return AllQuestionIntros.get_ms_intro_long()

        ## NOTE: numbering can be confusing with different practices.
        # elif random_num < 0.7:
        #     return AllQuestionIntros.get_ms_intro_question_num(handler_input)

        else:
            return ''
    def get_question(
        handler_input,
        player_object: object,
        practice_type: str,
        first_question: bool = False,
    ) -> str:
        """Asks the user a multiplication question based on custom practice type."""
        attr = handler_input.attributes_manager.session_attributes
        if not first_question:
            QuestionAttr.increment_questions_answered(handler_input)

        flag_get_new_question = True
        while flag_get_new_question:
            new_question = CP_QuestionByType.get_question_type(
                handler_input, player_object, practice_type)

            if (not GenQuestions.check_same_question(handler_input,
                                                     new_question)
                    or practice_type == custom_practice.data.PRACT_TYPES[
                        0]  # can repeat on incorrect from date.
                ):
                flag_get_new_question = False

        ## Message Intro
        ms_intro = CP_Questions.get_ms_question_intro(handler_input,
                                                      player_object,
                                                      practice_type,
                                                      first_question,
                                                      new_question)

        ## Save Question
        QuestionAttr.save_question(
            handler_input, new_question
        )  # NOTE: Save question after for duplicates on incorrect-problems.
        ms_question = GenQuestions.format_question(new_question)

        ## Punct for interrogative
        if attr.get('interrogative_question', False):
            punct = '?'
            attr['interrogative_question'] = False
        else:
            punct = ''

        speech_list = (ms_intro, ' ', ms_question, punct)
        speech = ''.join(speech_list)
        return CardFuncs.format_prompt(speech)
Exemple #10
0
    def get_q_fp_setup_reprompt(handler_input) -> str:
        """Returns reprompt for freeplay setup handlers."""
        attr = handler_input.attributes_manager.session_attributes
        if (attr.get('mode', None) == "free_play"
                and attr.get('times_tables', None) not in (None, [])):
            prompt = GenQuestions.get_same_question(handler_input)
        else:
            prompt = HelpUtils.get_q_what_todo()

        return CardFuncs.format_prompt(prompt)
    def get_question(handler_input, first_question: bool = False) -> str:
        """Returns question for the user."""
        attr = handler_input.attributes_manager.session_attributes

        if not first_question:
            QuestionAttr.increment_questions_answered(handler_input)

        sc_questions = attr['sc_questions']
        question = sc_questions.pop()

        attr['sc_questions'] = sc_questions
        QuestionAttr.save_question(handler_input, question)

        return GenQuestions.format_question(question)
Exemple #12
0
    def get_last_prompt(handler_input) -> str:
        """Returns the prompt used in the previous response.
        
        first checks if existing question to be asked. If so, asks the question.

        If function saved, uses function.
        Elif str prompt saved, uses cached from response interceptor.
        Else, uses HelpUtils.get_corresponding_message.
        """
        attr = handler_input.attributes_manager.session_attributes

        ## Free Play Questions
        question = attr.get('question', None)
        flag_in_game = attr.get(
            'mode', None) in aux_data.skill_data.MODE_ACT_DICT.keys()
        log_all(question, flag_in_game)
        if (question and flag_in_game):
            prompt_user = GenQuestions.get_same_question(handler_input)

        ## Don't repeat help
        elif is_intent_name("AMAZON.HelpIntent")(handler_input):
            prompt_user = HelpUtils.get_q_what_todo()

        ## Standard questions
        ## NOTE: May like to save function references in the future.
        # saving functions may create more variety.
        # elif attr.get('prompt_func', False):
        #     prompt_user = attr['prompt_func']
        #     attr['prompt_func'] = None
        # elif attr.get('prompt_ms', False):
        #     prompt_user = attr['prompt_ms']
        #     attr['prompt_ms'] = None
        # else:
        #     prompt_user = HelpUtils.get_ms_corresponding_help(handler_input)

        else:
            prompt_user = HelpUtils.get_q_what_todo()

        return CardFuncs.format_prompt(prompt_user)
    def handle(self, handler_input):
        logger.info("HAN    SM_StartHandler")
        speech_list = []

        SM_Attr.set_attr_start_survival_mode(handler_input)
        ModeStats.translate_mode_stats_to_sesh(handler_input)

        ms_welcome = SM_WelcomeUtils.get_ms_welcome(handler_input)
        ms_question = SMQuestions.get_question(handler_input, first_question= True)
        reprompt = GenQuestions.get_same_question(handler_input)
        
        speech_list += Pauser.make_ms_pause_level_list( 
            ms_welcome, 2, ms_question)

        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 return_unknown_slot_response(handler_input) -> object:
        """If cannot find answer slot, returns same response prompt.
        
        NOTE: Can probably just return last response object.
        """
        speech_list = []
        attr = handler_input.attributes_manager.session_attributes

        ms_not_understand = get_linear_nlg(fallback.data.MMT_NOT_UNDERSTAND)

        if attr.get('mode', None) == 'free_play':
            prompt, reprompt = (GenQuestions.get_same_question(handler_input)
                                for _ in range(2))
        else:
            prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                                for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_not_understand, 2,
                                                       prompt)

        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    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)