Example #1
0
    def get_table_bound_slots(handler_input) -> tuple:
        """Returns tuple of slots for lower & upper bounds."""
        lower_bound = SlotUtils.get_slot_val_by_name(handler_input,
                                                     "lower_bound")
        upper_bound = SlotUtils.get_slot_val_by_name(handler_input,
                                                     "upper_bound")

        if (lower_bound is not None) and (upper_bound is not None):
            lower_bound, upper_bound = sorted(
                [int(lower_bound), int(upper_bound)])
        return (lower_bound, upper_bound)
Example #2
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetNumberQuestionsHandler")
        speech_list = []

        FreePlayAttr.set_attr_free_play(
            handler_input)  # reset questions asked.
        num_questions = SlotUtils.get_slot_val_by_name(handler_input,
                                                       'num_questions')

        if num_questions is None:
            ms_can_set_questions = FPNumQuestions.get_ms_can_set_num_questions(
            )
            prompt, reprompt = (FPNumQuestions.get_q_num_questions()
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(
                ms_can_set_questions, 2, prompt)

        else:
            FreePlayAttr.set_attr_num_questions(handler_input, num_questions)

            ms_confirm = ConfirmUtils.get_random_confirmation(handler_input)
            ms_ask_num_questions = FPNumQuestions.get_ms_ask_num_questions(
                handler_input)
            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)

            speech_list += Pauser.make_ms_pause_level_list(
                ms_confirm, ms_ask_num_questions, 2, prompt)

        ModeStats.translate_mode_stats_to_sesh(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)
Example #3
0
    def check_answer(handler_input) -> bool:
        """Returns boolean if user answer is correct."""
        table_1, table_2 = QuestionAttr.get_question_tables(handler_input, True)
        answer = SlotUtils.get_slot_val_by_name(handler_input, 'answer')
        
        if not answer:
            logger.error("check_answer: No answer found.")
            ## NOTE: if this error is being thrown, need to incorporate 
            ## FallbackUtils.return_unknown_slot_response()
            return False

        return (table_1 * table_2 == int(answer))
Example #4
0
    def get_times_table_input_slots(handler_input) -> tuple:
        """Gets times table attributes:
         - lower_table
         - upper_table
         - table_query
      """
        lower_table, upper_table, query_tables = (
            SlotUtils.get_slot_val_by_name(handler_input, slot_name)
            for slot_name in free_play.data.TIMES_TABLE_SLOTS)

        query_tables = FPCleanInput.clean_query_tables(handler_input,
                                                       query_tables)
        lower_table, upper_table = FPCleanInput.clean_table_range(
            lower_table, upper_table)
        return (lower_table, upper_table, query_tables)
    def get_ms_answer(handler_input, include_correct_ans: bool = True) -> str:
        """Returns message of what the answer is.

        Format: Num1 * Num2 = Num3"""
        table_1, table_2 = QuestionAttr.get_question_tables(handler_input,
                                                            integers=True)
        user_answer = SlotUtils.get_slot_val_by_name(handler_input, 'answer')
        answer = str(table_1 * table_2) + '.'

        ms_question = check_answer.data.MS_QUESTION.format(table_1, table_2)

        speech_list = [
            ms_question,
            check_answer.data.MT_EQUALS,
            answer,
        ]
        if include_correct_ans:
            ms_ans = check_answer.data.MS_NOT_ANS.format(user_answer)
            speech_list.append(ms_ans)

        return get_linear_nlg(speech_list)