Esempio n. 1
0
 def load_graphs_from_folder(self):
     graph_list = []
     # Goren - notice the path to the graph defined by graphs_folder in the config file. is this where your graphs are?
     graph_folder = path.join(getcwd(),
                              self.config['Default']['graphs_folder'])
     #for testing
     #graph_folder = path.join(getcwd(), self.config['Default']['tester_graphs_folder'])
     if self.sm.size[1] < 1000:
         screen_type = 'small'
     else:
         screen_type = 'large'
     file_list = [
         item for item in listdir(graph_folder)
         if item.endswith(".json") and screen_type in item
     ]
     KL.log.insert(action=LogAction.data,
                   obj='screen_type',
                   comment=screen_type,
                   sync=True)
     for graph_name in file_list:
         try:
             graph_file_path = path.join(".", graph_folder, str(graph_name))
             if GET_RANDOM_QUESTIONS:
                 self.add_random_questions(5, graph_file_path)
             current_graph = load_graph_from_json(graph_file_path)
             graph_list.append(current_graph)
         except Exception as e:
             print(e)
     #randomize
     shuffle(graph_list)
     return graph_list
Esempio n. 2
0
def main():
    print("sdsdsds")
    GLogger('file', 'graph_validator_logger.txt', 'ERROR')
    Window.size = (1920, 1090)

    Utils.read_game_config_file(MAIN_CONFIG_FILE_PATH)
    Utils.read_graph_config_file(GRAPH_CONFIG_FILE)
    Utils.image_folder = path.join("..", Utils.image_folder)

    max_turns = int(Utils.game_config_data['Default']['max_turns'])
    it = itertools.product('1234', repeat=max_turns)
    number_of_successful_runs = 0
    # use line 30 to test all the graphs in SAVED_GRAPH_PATH; use line 31 to only test the graphs specified in 'graphs_names'
    # for current_graph in [item for item in listdir(SAVED_GRAPH_PATH) if item.endswith(".xml")]:
    for current_graph in graphs_names:
        curr_path = path.join(SAVED_GRAPH_PATH, current_graph)
        graph = load_graph_from_json(curr_path)
        with open("{}_saved_steps.txt".format(curr_path[:-5]), 'w') as f:
            num_of_graph_nodes = len(graph.node_list)
            f.write("The graph contains {} nodes\n".format(
                str(num_of_graph_nodes)))
            while True:
                try:
                    buttons = it.next()
                except StopIteration:
                    break
                answer, number_of_nodes_seen = run_buttons_on_graph(
                    graph, buttons)
                number_of_successful_runs += answer
                f.write("steps: {}, seen nodes: {} \n".format(
                    str(buttons), str(number_of_nodes_seen)))

            f.write("number of successful runs = {0}\n".format(
                number_of_successful_runs))
Esempio n. 3
0
    def add_random_questions(self, number_of_random_questios, graph_file_path):
        current_graph = load_graph_from_json(graph_file_path)
        store = JsonStore("Json/questions.json", encoding='utf-8')
        question_one_red = QuestionObject(
            store['questionnaire']['ques']['q01'][::-1].replace(
                "X", store['questionnaire']['ques_parameters']['X_red'][::-1]),
            QuestionTypes['NUMBER'], 1, Colours['red'])
        question_one_blue = QuestionObject(
            store['questionnaire']['ques']['q01'][::-1].replace(
                "X",
                store['questionnaire']['ques_parameters']['X_blue'][::-1]),
            QuestionTypes['NUMBER'], 1, Colours['blue'])
        question_one_yellow = QuestionObject(
            store['questionnaire']['ques']['q01'][::-1].replace(
                "X",
                store['questionnaire']['ques_parameters']['X_yellow'][::-1]),
            QuestionTypes['NUMBER'], 1, Colours['yellow'])
        question_two = QuestionObject(
            store['questionnaire']['ques']['q03'][::-1],
            QuestionTypes['MULTIPLE_CHOICE'], 3)
        question_three = QuestionObject(
            store['questionnaire']['ques']['q06'][::-1],
            QuestionTypes['MULTIPLE_CHOICE'], 6)
        question_six = QuestionObject(
            store['questionnaire']['ques']['q16'][::-1],
            QuestionTypes['MULTIPLE_CHOICE'], 16)
        question_seven = QuestionObject(
            store['questionnaire']['ques']['q17'][::-1],
            QuestionTypes['MULTIPLE_CHOICE'], 17)
        q_nums = range(5)
        shuffle(q_nums)
        all_questions_graph = []
        for i in range(number_of_random_questios):
            if q_nums[i] == 0:
                q1_list = [
                    question_one_red, question_one_blue, question_one_yellow
                ]
                shuffle(q1_list)
                all_questions_graph.append(q1_list[0])
            elif q_nums[i] == 1:
                all_questions_graph.append(question_two)
            elif q_nums[i] == 2:
                all_questions_graph.append(question_three)
            elif q_nums[i] == 3:
                all_questions_graph.append(question_six)
            elif q_nums[i] == 4:
                all_questions_graph.append(question_seven)

        current_graph.question_object_list = all_questions_graph
        save_graph_json(current_graph, graph_file_path)
Esempio n. 4
0
 def load_graphs_from_folder(self):
     graph_list = []
     # Goren - notice the path to the graph defined by graphs_folder in the config file. is this where your graphs are?
     graph_folder = path.join(getcwd(),
                              self.config['Default']['graphs_folder'])
     #for testing
     #graph_folder = path.join(getcwd(), self.config['Default']['tester_graphs_folder'])
     file_list = [
         item for item in listdir(graph_folder) if item.endswith(".json")
     ]
     for graph_name in file_list:
         try:
             graph_file_path = path.join(".", graph_folder, str(graph_name))
             if GET_RANDOM_QUESTIONS:
                 self.add_random_questions(5, graph_file_path)
             current_graph = load_graph_from_json(graph_file_path)
             graph_list.append(current_graph)
         except Exception as e:
             print(e)
     #randomize
     shuffle(graph_list)
     return graph_list
Esempio n. 5
0

class GameType(Enum):
    VIEW_ONLY = 1
    ALLOW_PLAY = 2


def main(game_type, graph_data):
    GLogger('file', 'graph_runner_logger.txt', 'ERROR')
    if game_type == GameType.VIEW_ONLY:
        game = DisplayApp(graph_data)
    elif game_type == GameType.ALLOW_PLAY:
        button_presses = []
        # This needs to be more versatile
        test_screen = TestScreen(graph_data, button_presses, 0.2)
        test_screen.graph_config = "../GraphsData/graph_config.txt"
        game = GraphGameApp(test_screen)
    game.run()


if __name__ == "__main__":
    Utils.read_game_config_file(CONFIG_FILE_PATH)
    Utils.read_graph_config_file(GRAPH_CONFIG_PATH)
    Utils.image_folder = path.join("..", Utils.image_folder)

    # ALLOW_PLAY, VIEW_ONLY
    game_type = GameType.ALLOW_PLAY

    graph = load_graph_from_json(graph_file_path)
    main(game_type, graph)