Exemple #1
0
 def say_last_message(self):
     if self.success == 'Yes':
         template = console.get_template('success_last_message.txt', self.color)
         print(template.substitute({}))
     if self.success == 'No':
         template = console.get_template('failure_last_message.txt', self.color)
         print(template.substitute({}))
Exemple #2
0
    def input_new_vocabulary(self):
        new_vocabulary = {}

        template = console.get_template('english_vocabulary.txt',
                                        self.speak_color)
        new_vocabulary["en"] = input(
            template.substitute({
                'robot_name': self.name,
                'user_name': self.user_name,
            }))

        template = console.get_template('japanese_meaning.txt',
                                        self.speak_color)
        new_vocabulary["ja"] = input(
            template.substitute({
                'robot_name': self.name,
                'user_name': self.user_name,
            }))

        template = console.get_template('which_parts_of_speech.txt',
                                        self.speak_color)
        parts_of_speech_num = input(
            template.substitute({
                'robot_name': self.name,
                'user_name': self.user_name,
            }))
        new_vocabulary["parts_of_speech"] = self.parts_of_speech_list[int(
            parts_of_speech_num)]

        return new_vocabulary
Exemple #3
0
    def ask_user_todo(self):
        """Collect favorite restaurant information from users."""
        while True:
            template = console.get_template('what_do.txt', self.speak_color)
            todo = input(
                template.substitute({
                    'robot_name': self.name,
                    'user_name': self.user_name,
                }))

            if int(todo) == 0:
                # all.csvかweekly.csvnのどちらに書き込むか選択
                template = console.get_template('which_all_or_weekly.txt',
                                                self.speak_color)
                want_to_do_num = int(input(template.substitute()))

                # 0の場合all_csv、1の場合weekly_csvを読み込みpracticeをする
                if want_to_do_num == 0:
                    self.practice(self.all_csv_path)
                elif want_to_do_num == 1:
                    self.practice(self.weekly_csv_path)

            elif int(todo) == 1:
                new_vocabulary = self.input_new_vocabulary()
                self.write_new_vocabulary(new_vocabulary, self.weekly_csv_path)

            elif int(todo) == 2:
                break
            else:
                print("Error. Please enter again")
Exemple #4
0
 def thank_you(self):
     """Show words of appreciation to users."""
     template = console.get_template('good_by.txt', self.speak_color)
     print(template.substitute({
         'robot_name': self.name,
         'user_name': self.user_name
     }))
Exemple #5
0
    def ask_user_name(self):
        while True:
            template = console.get_template('ask_user_name.txt', self.color)
            user_name = input(template.substitute({}))

            if user_name:
                self.user_name = user_name
                break
Exemple #6
0
    def check_and_start_timer(self):
        while True:
            template = console.get_template('check_and_start_timer.txt', self.color)
            timer_start = input(template.substitute({
                'time_limit': self.time_limit
            }))

            if timer_start == 'start':
                break
Exemple #7
0
 def timer_run_and_end(self):
     for i in range(0 + 1, self.time_limit):
         print(i)
         sleep(1)
     while True:
         templates = console.get_template('timer_end_and_ask_success.txt', self.color)
         success = input(templates.substitute({})).title()
         if success == 'Yes' or success == 'No':
             self.success = success
             break
Exemple #8
0
    def ask_user_goal(self):
        while True:
            template = console.get_template('ask_user_goal.txt', self.color)
            user_goal = input(template.substitute({
                'user_name': self.user_name.title()
            }))

            if user_goal:
                self.user_goal = user_goal
                break
Exemple #9
0
    def hello(self):
        """Returns words to the user that the robot speaks at the beginning."""
        while True:
            template = console.get_template('hello.txt', self.speak_color)
            user_name = input(template.substitute({
                'robot_name': self.name}))

            if user_name:
                self.user_name = user_name.title()
                break
Exemple #10
0
    def ask_time_limit(self):
        while True:
            template = console.get_template('ask_time_limit.txt', self.color)
            time_limit = input(template.substitute({}))

            if time_limit:
                try:
                    self.time_limit = int(time_limit)
                    break
                except:
                    continue
Exemple #11
0
    def check_mongodb_activation(self):
        """Create instance for Recording models (MongoDB)"""

        mongo_model = recording.MongoModel(None)
        if not mongo_model.get_mongo_profile():
            template = console.get_template('db_response.txt',
                                            self.speak_color)
            print(template.substitute({'db': self.db}))
            self.status = False
        else:
            self.status = True
Exemple #12
0
 def ask_user_favorite(self):
     """Collect favorite restaurant information from users."""
     while True:
         template = console.get_template(
             'which_restaurant.txt', self.speak_color)
         restaurant = input(template.substitute({
             'robot_name': self.name,
             'user_name': self.user_name
         }))
         if restaurant:
             self.ranking_model.increment(restaurant)
             break
Exemple #13
0
    def ask_for_db_activation(self):
        while True:
            template = console.get_template('db_activation.txt',
                                            self.speak_color)
            is_yes = input(template.substitute({'db': self.db}))

            if is_yes.lower() == 'y' or is_yes.lower() == 'yes':
                self.status = True
                break

            if is_yes.lower() == 'n' or is_yes.lower() == 'no':
                self.status = False
                break
Exemple #14
0
    def visualize_income_timechart(self):
        """Visualize data from json file and export a graph image """

        visual = visualizing.VisualizingModel(None)
        visual.create_base_table()
        visual.rename_columns()
        visual.sort_table()
        visual.camouflage_values(True)
        visual.save_graph_to_image()

        # dialog
        template = console.get_template('process_finished.txt',
                                        self.speak_color)
        print(template.substitute())
Exemple #15
0
    def recommend_restaurant(self):
        """Show restaurant recommended restaurant to the user."""
        new_recommend_restaurant = self.ranking_model.get_most_popular()
        if not new_recommend_restaurant:
            return None

        will_recommend_restaurants = [new_recommend_restaurant]
        while True:
            template = console.get_template('greeting.txt', self.speak_color)
            is_yes = input(template.substitute({
                'robot_name': self.name,
                'user_name': self.user_name,
                'restaurant': new_recommend_restaurant
            }))

            if is_yes.lower() == 'y' or is_yes.lower() == 'yes':
                break

            if is_yes.lower() == 'n' or is_yes.lower() == 'no':
                new_recommend_restaurant = self.ranking_model.get_most_popular(
                    not_list=will_recommend_restaurants)
                if not new_recommend_restaurant:
                    break
                will_recommend_restaurants.append(new_recommend_restaurant)
Exemple #16
0
    def practice(self, csv_file):
        """for practice vocabulary"""

        # Vocabularyの数を取得
        f = open(csv_file)
        num_lines = sum(1 for line in f)
        f.close

        # Vocabularyのcsvデータを配列にトランスフォーム
        vocaburaly_array = self.make_array(csv_file)

        # 乱数を0からnum_lines-2(colomunsの行があるのと、配列は0から始まるから)までで10個生成して、vocabularyを取得する
        for i, question_num in enumerate(
                random.randint(0, num_lines - 2) for n in range(10)):

            # 選択肢の作成
            choices = []
            for j in (random.randint(0, num_lines - 2) for n in range(3)):
                choices.append(vocaburaly_array[j][1])
            # 選択肢に正解を追加
            choices.append(vocaburaly_array[question_num][1])
            choices = random.sample(choices, 4)

            # 質問する
            template = console.get_template('question_english_meaning.txt',
                                            self.speak_color)
            answer_num = int(
                input(
                    template.substitute({
                        'robot_name':
                        self.name,
                        'user_name':
                        self.user_name,
                        'english':
                        vocaburaly_array[question_num][0],
                        'japanese':
                        vocaburaly_array[question_num][1],
                        'number':
                        i + 1,
                        'ch1':
                        choices[0],
                        'ch2':
                        choices[1],
                        'ch3':
                        choices[2],
                        'ch4':
                        choices[3]
                    })))

            # 答え合わせ
            if vocaburaly_array[question_num][1] == choices[answer_num]:
                template = console.get_template('correct.txt', 'blue')
                print(template.substitute())

            else:
                template = console.get_template('wrong.txt', 'red')
                print(
                    template.substitute({
                        'answer_e':
                        vocaburaly_array[question_num][0],
                        'answer_j':
                        vocaburaly_array[question_num][1],
                        'parts_of_speech':
                        vocaburaly_array[question_num][2]
                    }))