def main(): questionOne = QuestionObject("how many red nodes there are?", QuestionTypes['NUMBER'], 111) questionThree = QuestionObject( "what is the color that contain the node with the maximun links in the graph?", QuestionTypes['MULTIPLE_CHOICE'], 222) questionFive = QuestionObject( "how many red nodes do not have links blue nodes?", QuestionTypes['NUMBER'], 4) questionNine = QuestionObject( "does every node at color yellow have link to a node of color red?", QuestionTypes['BOOLEAN'], 12) questionTen = QuestionObject("is there more red nodes than yellow nodes?", QuestionTypes['BOOLEAN'], 14) questionList = [ questionOne, questionThree, questionFive, questionNine, questionTen ] q = Queue() display = QuestionDisplay(questionList, q) display.run() user_answers = q.get() for item in user_answers: print("question #{} - {}".format(item.question_number, item.get_answer()))
def test_upper(self): #prepare user_graph = create_draft_graph_1() true_graph = create_draft_graph_1() question_data = QuestionObject("how many {} nodes there are?", QuestionTypes['NUMBER'], 1, Colours.get("red")) question = IntSpinner(question=question_data) user_answers = [AnswerObject(question_object=question, user_seen_graph=user_graph, real_graph=true_graph), AnswerObject(question_object=question, user_seen_graph=user_graph, real_graph=true_graph)] user_answers[0].user_answer = ["1"] user_answers[0].user_graph_answer = ["1"] user_answers[0].real_answer = ["1"] user_answers[1].user_answer = ["yellow", "blue"] user_answers[1].user_graph_answer = ["red"] user_answers[1].real_answer = ["blue", "red"] #act results_dict_0 = ResultWidget.calculate_percentage([user_answers[0]]) print (results_dict_0) possible_score_0 = results_dict_0.get("possible_score") user_score_0 = results_dict_0.get("user_score") results_dict_1 = ResultWidget.calculate_percentage([user_answers[1]]) possible_score_1 = results_dict_1.get("possible_score") user_score_1 = results_dict_1.get("user_score") print (results_dict_1) #assert self.assertEqual(possible_score_0,5) self.assertEqual(user_score_0,5) self.assertEqual(possible_score_1,0) self.assertEqual(user_score_1,0)
def create_questions(): """ Creates a list of QuestionObject """ from KivyFiles.Questions.QuestionObject import QuestionObject question_one = QuestionObject("how many red nodes there are?", QuestionTypes['NUMBER'], 1, Colours['red']) question_three = QuestionObject("how many yellow nodes there are?", QuestionTypes['NUMBER'], 1, Colours['yellow']) question_five = QuestionObject("how many blue nodes there are?", QuestionTypes['NUMBER'], 1, Colours['blue']) question_list = [question_one, question_three, question_five] return question_list
def load_graph_from_json(file_name): if not path.exists(file_name): raise IOError("File not found", path=file_name) new_graph = GraphObject() new_graph.source_file = file_name with open(file_name) as f: data = json.loads(f.read()) new_graph.size["max_x"] = data["size"]["max_x"] new_graph.size["max_y"] = data["size"]["max_y"] new_graph.extra_distance = data["extra_distance"] new_graph.center_node = data["center_node"] new_graph.max_neighbors = data["max_neighbors"] new_graph.line_colour = data["line_colour"] new_graph.node_count = data["node_count"] new_graph.connections = [(str(item[0]), str(item[1])) for item in data["connections"]] new_graph.question_object_list = [] new_graph.node_list = [] for node in data["node_list"]: node_shape = data["node_list"][node]["shape"] node_size = data["node_list"][node]["node_size"] node_location = { 'x': data["node_list"][node]["node_x"], 'y': data["node_list"][node]["node_y"] } node_colour = Colours[data["node_list"][node]["colour"]] node_neighbors = set( json.loads(data["node_list"][node]["neighbors"])) possible_neighbors = set( json.loads(data["node_list"][node]["possible_neighbors"])) new_node = NodeObject(node, node_location, node_size, node_colour, node_shape) new_node.neighbors = node_neighbors new_node.possible_neighbors = possible_neighbors new_graph.node_list.append(new_node) for question in data["question_object_list"]: question_type_number = data["question_object_list"][question][ "question_type_number"] question_string = data["question_object_list"][question][ "question_string"] question_id = data["question_object_list"][question]["question_id"] args = json.loads(data["question_object_list"][question]["args"]) question_object = QuestionObject(question_string, question_type_number, question_id, *args) new_graph.question_object_list.append(question_object) return new_graph
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)
def main(): question_data = QuestionObject("how many {} nodes there are?", QuestionTypes['NUMBER'], 1, Colours.red) question = IntSpinner(question=question_data) question.text = '6' graph_user = create_rand_graph("{}\..\GraphsData\config.ini".format( os.getcwd())) graph_real = create_rand_graph("{}\..\GraphsData\config.ini".format( os.getcwd())) for i in range(len(graph_user.node_list)): graph_user.node_list[i].colour = Colours.yellow['name'] graph_real.node_list[i].colour = Colours.red['name'] for i in range(len(graph_user.node_list) - 5): graph_user.node_list[i].colour = Colours.red answer = AnswerObject(question_object=question, user_seen_graph=graph_user, real_graph=graph_real) print(answer)
def main(): user_graph = create_rand_graph("{}\..\GraphsData\config.ini".format(os.getcwd())) true_graph = create_rand_graph("{}\..\GraphsData\config.ini".format(os.getcwd())) for i in range(len(user_graph.node_list)): user_graph.node_list[i].colour = Colours.yellow['name'] true_graph.node_list[i].colour = Colours.red['name'] for i in range(len(user_graph.node_list)-5): user_graph.node_list[i].colour = Colours.red['name'] answer_list = [] for i in range(10): question_data = QuestionObject("how many {} nodes there are?", QuestionTypes['NUMBER'], 1, Colours.red) question = IntSpinner(question=question_data) question.text = '6' answer = AnswerObject(question_object=question, user_seen_graph=user_graph, real_graph=true_graph) answer_list.append(answer) display = ResultDisplay(answer_list, user_graph, true_graph) display.run()
def create_draft_graph_1_rotate(): GLogger('file', 'handmade_graph_logger.txt', 'ERROR') draft_graph = GraphObject(max_x=2850, max_y=2750, node_count=15, max_neighbors=5, extra_distance=1) draft_graph.add_node(x_loc=687, y_loc=2169, node_colour=Colours['yellow'], serial='n1') draft_graph.add_node(x_loc=58, y_loc=2450, node_colour=Colours['red'], serial='n2') draft_graph.add_node(x_loc=294, y_loc=1255, node_colour=Colours['blue'], serial='n3') draft_graph.add_node(x_loc=939, y_loc=1879, node_colour=Colours['blue'], serial='n4') draft_graph.add_node(x_loc=730, y_loc=772, node_colour=Colours['red'], serial='n5') draft_graph.add_node(x_loc=1394, y_loc=343, node_colour=Colours['red'], serial='n6') draft_graph.add_node(x_loc=839, y_loc=319, node_colour=Colours['yellow'], serial='n7') draft_graph.add_node(x_loc=2109, y_loc=902, node_colour=Colours['blue'], serial='n8') draft_graph.add_node(x_loc=2017, y_loc=345, node_colour=Colours['red'], serial='n9') draft_graph.add_node(x_loc=1319, y_loc=1322, node_colour=Colours['red'], serial='n10') draft_graph.add_node(x_loc=1973, y_loc=2006, node_colour=Colours['blue'], serial='n11') draft_graph.add_node(x_loc=2476, y_loc=2289, node_colour=Colours['red'], serial='n12') draft_graph.add_node(x_loc=1737, y_loc=1514, node_colour=Colours['yellow'], serial='n13') draft_graph.add_node(x_loc=1768, y_loc=2676, node_colour=Colours['yellow'], serial='n14') draft_graph.add_node(x_loc=416, y_loc=748, node_colour=Colours['blue'], serial='n15') draft_graph.center_node = "n1" for node in draft_graph.node_list: draft_graph.get_possible_connections(node.serial_num) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n2")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n3")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n5")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n7")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n12"), draft_graph.get_node_by_serial("n11")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n6")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n11"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n14"), draft_graph.get_node_by_serial("n12")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n7"), draft_graph.get_node_by_serial("n15")) question_one = QuestionObject( "How many red nodes do not have links to yellow nodes?", QuestionTypes['NUMBER'], 5, Colours['red'], Colours['yellow']) question_two = QuestionObject("Is the number of red nodes even?", QuestionTypes['BOOLEAN'], 15, Colours['red'], 0) question_three = QuestionObject( "Does all the blue nodes have an odd number of links?", QuestionTypes['BOOLEAN'], 13, Colours['blue'], 1) question_four = QuestionObject( "What is the color that contains the smallest total number of links?", QuestionTypes['MULTIPLE_CHOICE'], 7) question_five = QuestionObject( "Does every yellow node have a link to a red node?", QuestionTypes['BOOLEAN'], 9, Colours['yellow'], Colours['red']) question_six = QuestionObject( "Are there more blue nodes than yellow nodes?", QuestionTypes['BOOLEAN'], 10, Colours['blue'], Colours['yellow']) question_seven = QuestionObject( "Is there a red nodes that has a link to another red node?", QuestionTypes['BOOLEAN'], 8, Colours['red']) draft_graph.question_object_list = [ question_one, question_two, question_three, question_four, question_five, question_six, question_seven ] save_graph_json(draft_graph, "Graph_1_rotate.json") #create_draft_graph_1_Transpose() #create_draft_graph_1_rotate() #create_draft_graph_1() #create_draft_graph_2() #create_draft_graph_3() #create_draft_graph_4() #create_draft_graph_5()
def create_draft_graph_5(): GLogger('file', 'handmade_graph_logger.txt', 'ERROR') draft_graph = GraphObject(max_x=2350, max_y=3050, node_count=15, max_neighbors=5, extra_distance=1) draft_graph.add_node(x_loc=405, y_loc=2786, node_colour=Colours['red'], serial='n1') draft_graph.add_node(x_loc=340, y_loc=441, node_colour=Colours['red'], serial='n2') draft_graph.add_node(x_loc=657, y_loc=1902, node_colour=Colours['red'], serial='n3') draft_graph.add_node(x_loc=187, y_loc=2512, node_colour=Colours['blue'], serial='n4') draft_graph.add_node(x_loc=336, y_loc=1153, node_colour=Colours['blue'], serial='n5') draft_graph.add_node(x_loc=1747, y_loc=2763, node_colour=Colours['yellow'], serial='n6') draft_graph.add_node(x_loc=1809, y_loc=514, node_colour=Colours['blue'], serial='n7') draft_graph.add_node(x_loc=1845, y_loc=2169, node_colour=Colours['blue'], serial='n8') draft_graph.add_node(x_loc=1125, y_loc=2383, node_colour=Colours['blue'], serial='n9') draft_graph.add_node(x_loc=1681, y_loc=1621, node_colour=Colours['yellow'], serial='n10') draft_graph.add_node(x_loc=1456, y_loc=152, node_colour=Colours['blue'], serial='n11') draft_graph.add_node(x_loc=2011, y_loc=1486, node_colour=Colours['red'], serial='n12') draft_graph.add_node(x_loc=2008, y_loc=345, node_colour=Colours['yellow'], serial='n13') draft_graph.add_node(x_loc=1449, y_loc=2993, node_colour=Colours['red'], serial='n14') draft_graph.add_node(x_loc=2296, y_loc=812, node_colour=Colours['red'], serial='n15') draft_graph.center_node = "n5" for node in draft_graph.node_list: draft_graph.get_possible_connections(node.serial_num) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n3")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n2")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n12"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n12"), draft_graph.get_node_by_serial("n11")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n12"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n13"), draft_graph.get_node_by_serial("n15")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n7"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n14"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n12")) question_one = QuestionObject( 'Is there a yellow node that has at least 3 links to another yellow node?', QuestionTypes['BOOLEAN'], 11, Colours['yellow'], 3) question_two = QuestionObject( 'Does all the red nodes have an odd number of links?', QuestionTypes['BOOLEAN'], 13, Colours['red'], 1) question_three = QuestionObject('How many yellow nodes are there?', QuestionTypes['NUMBER'], 1, Colours['yellow']) question_four = QuestionObject( 'What is the color that contains the smallest total number of links?', QuestionTypes['MULTIPLE_CHOICE'], 7) question_five = QuestionObject( 'Does every blue node have a link to a yellow node?', QuestionTypes['BOOLEAN'], 9, Colours['blue'], Colours['yellow']) question_six = QuestionObject('Is the number of blue nodes even?', QuestionTypes['BOOLEAN'], 15, Colours['blue'], 0) question_seven = QuestionObject( 'How many yellow nodes do not have links to red nodes?', QuestionTypes['NUMBER'], 5, Colours['yellow'], Colours['red']) draft_graph.question_object_list = [ question_one, question_two, question_three, question_four, question_five, question_six, question_seven ] save_graph_json(draft_graph, "Graph_5.json")
def create_draft_graph_4(): GLogger('file', 'handmade_graph_logger.txt', 'ERROR') draft_graph = GraphObject(max_x=4750, max_y=2400, node_count=15, max_neighbors=5, extra_distance=1) draft_graph.add_node(x_loc=936, y_loc=1671, node_colour=Colours['blue'], serial='n1') draft_graph.add_node(x_loc=480, y_loc=1998, node_colour=Colours['yellow'], serial='n2') draft_graph.add_node(x_loc=96, y_loc=908, node_colour=Colours['blue'], serial='n3') draft_graph.add_node(x_loc=1668, y_loc=2007, node_colour=Colours['red'], serial='n4') draft_graph.add_node(x_loc=2112, y_loc=1816, node_colour=Colours['yellow'], serial='n5') draft_graph.add_node(x_loc=2976, y_loc=1825, node_colour=Colours['yellow'], serial='n6') draft_graph.add_node(x_loc=2392, y_loc=2356, node_colour=Colours['blue'], serial='n7') draft_graph.add_node(x_loc=3360, y_loc=1271, node_colour=Colours['blue'], serial='n8') draft_graph.add_node(x_loc=1788, y_loc=1453, node_colour=Colours['red'], serial='n9') draft_graph.add_node(x_loc=4440, y_loc=1280, node_colour=Colours['blue'], serial='n10') draft_graph.add_node(x_loc=3600, y_loc=1734, node_colour=Colours['yellow'], serial='n11') draft_graph.add_node(x_loc=4680, y_loc=1635, node_colour=Colours['red'], serial='n12') draft_graph.add_node(x_loc=480, y_loc=1380, node_colour=Colours['red'], serial='n13') draft_graph.add_node(x_loc=2880, y_loc=566, node_colour=Colours['red'], serial='n14') draft_graph.add_node(x_loc=3372, y_loc=1998, node_colour=Colours['red'], serial='n15') draft_graph.center_node = "n1" for node in draft_graph.node_list: draft_graph.get_possible_connections(node.serial_num) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n2")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n2"), draft_graph.get_node_by_serial("n3")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n2"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n4"), draft_graph.get_node_by_serial("n5")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n7")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n11")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n15")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n7")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n7"), draft_graph.get_node_by_serial("n15")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n14")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n12")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n14")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n15")) question_one = QuestionObject( 'Is there a red node that has at least two links to another red node?', QuestionTypes['BOOLEAN'], 11, Colours['red'], 2) question_two = QuestionObject( 'Is the sum of the links of all the red nodes even?', QuestionTypes['BOOLEAN'], 14, Colours['red'], 0) question_three = QuestionObject( 'Which color has the largest number of nodes?', QuestionTypes['MULTIPLE_CHOICE'], 16) question_four = QuestionObject( 'How many blue nodes have links to yellow nodes?', QuestionTypes['NUMBER'], 2, Colours['blue'], Colours['yellow']) question_five = QuestionObject( 'What is the color that contains the largest total number of links?', QuestionTypes['MULTIPLE_CHOICE'], 4) question_six = QuestionObject( 'Does every yellow node have a link to a red node?', QuestionTypes['BOOLEAN'], 9, Colours['yellow'], Colours['red']) question_seven = QuestionObject( 'Are there more blue nodes than yellow nodes?', QuestionTypes['BOOLEAN'], 10, Colours['blue'], Colours['yellow']) draft_graph.question_object_list = [ question_one, question_two, question_three, question_four, question_five, question_six, question_seven ] save_graph_json(draft_graph, "Graph_4.json")
def create_draft_graph_3(): GLogger('file', 'handmade_graph_logger.txt', 'ERROR') draft_graph = GraphObject(max_x=2950, max_y=2850, node_count=15, max_neighbors=5, extra_distance=1) draft_graph.add_node(x_loc=62, y_loc=90, node_colour=Colours['yellow'], serial='n1') draft_graph.add_node(x_loc=1082, y_loc=726, node_colour=Colours['blue'], serial='n2') draft_graph.add_node(x_loc=482, y_loc=944, node_colour=Colours['blue'], serial='n3') draft_graph.add_node(x_loc=1800, y_loc=581, node_colour=Colours['blue'], serial='n4') draft_graph.add_node(x_loc=1584, y_loc=1358, node_colour=Colours['yellow'], serial='n5') draft_graph.add_node(x_loc=2880, y_loc=726, node_colour=Colours['red'], serial='n6') draft_graph.add_node(x_loc=1896, y_loc=90, node_colour=Colours['yellow'], serial='n7') draft_graph.add_node(x_loc=2090, y_loc=1911, node_colour=Colours['yellow'], serial='n8') draft_graph.add_node(x_loc=2496, y_loc=1235, node_colour=Colours['blue'], serial='n9') draft_graph.add_node(x_loc=1130, y_loc=2147, node_colour=Colours['red'], serial='n10') draft_graph.add_node(x_loc=2904, y_loc=2328, node_colour=Colours['red'], serial='n11') draft_graph.add_node(x_loc=132, y_loc=1653, node_colour=Colours['blue'], serial='n12') draft_graph.add_node(x_loc=484, y_loc=2610, node_colour=Colours['yellow'], serial='n13') draft_graph.add_node(x_loc=1586, y_loc=2739, node_colour=Colours['red'], serial='n14') draft_graph.add_node(x_loc=2378, y_loc=2801, node_colour=Colours['blue'], serial='n15') draft_graph.center_node = "n2" for node in draft_graph.node_list: draft_graph.get_possible_connections(node.serial_num) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n2")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n3")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n2"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n4"), draft_graph.get_node_by_serial("n5")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n4"), draft_graph.get_node_by_serial("n6")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n7")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n11"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n5")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n9"), draft_graph.get_node_by_serial("n11")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n12")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n13"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n14")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n15"), draft_graph.get_node_by_serial("n14")) question_one = QuestionObject( 'Is there a red node with an odd number of links?', QuestionTypes['BOOLEAN'], 12, Colours['red'], 1) question_two = QuestionObject( 'Which color has the smallest number of nodes?', QuestionTypes['MULTIPLE_CHOICE'], 17) question_three = QuestionObject('How many blue nodes are there?', QuestionTypes['NUMBER'], 1, Colours['blue']) question_four = QuestionObject( 'What is the color of the node with the largest number of links?', QuestionTypes['MULTIPLE_CHOICE'], 3) question_five = QuestionObject( 'Does every red node have a link to a yellow node?', QuestionTypes['BOOLEAN'], 9, Colours['red'], Colours['yellow']) question_six = QuestionObject( 'Does all the blue nodes have an even number of links?', QuestionTypes['BOOLEAN'], 13, Colours['blue'], 0) question_seven = QuestionObject( 'Are there more red nodes than blue nodes?', QuestionTypes['BOOLEAN'], 10, Colours['red'], Colours['blue']) draft_graph.question_object_list = [ question_one, question_two, question_three, question_four, question_five, question_six, question_seven ] save_graph_json(draft_graph, "Graph_3.json")
def create_draft_graph_2(): draft_graph = GraphObject(max_x=2450, max_y=3200, node_count=15, max_neighbors=5, extra_distance=1) draft_graph.add_node(x_loc=144, y_loc=2252, node_colour=Colours['blue'], serial='n1') draft_graph.add_node(x_loc=506, y_loc=2525, node_colour=Colours['yellow'], serial='n2') draft_graph.add_node(x_loc=1224, y_loc=2052, node_colour=Colours['blue'], serial='n3') draft_graph.add_node(x_loc=1704, y_loc=2434, node_colour=Colours['blue'], serial='n4') draft_graph.add_node(x_loc=1824, y_loc=1526, node_colour=Colours['red'], serial='n5') draft_graph.add_node(x_loc=2064, y_loc=1071, node_colour=Colours['red'], serial='n6') draft_graph.add_node(x_loc=1344, y_loc=890, node_colour=Colours['red'], serial='n7') draft_graph.add_node(x_loc=1464, y_loc=617, node_colour=Colours['blue'], serial='n8') draft_graph.add_node(x_loc=2376, y_loc=617, node_colour=Colours['yellow'], serial='n9') draft_graph.add_node(x_loc=746, y_loc=981, node_colour=Colours['blue'], serial='n10') draft_graph.add_node(x_loc=360, y_loc=1529, node_colour=Colours['red'], serial='n11') draft_graph.add_node(x_loc=72, y_loc=1635, node_colour=Colours['yellow'], serial='n12') draft_graph.add_node(x_loc=508, y_loc=1689, node_colour=Colours['blue'], serial='n13') draft_graph.add_node(x_loc=1226, y_loc=163, node_colour=Colours['red'], serial='n14') draft_graph.add_node(x_loc=196, y_loc=3161, node_colour=Colours['blue'], serial='n15') draft_graph.center_node = "n2" for node in draft_graph.node_list: draft_graph.get_possible_connections(node.serial_num) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n1"), draft_graph.get_node_by_serial("n2")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n2"), draft_graph.get_node_by_serial("n3")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n4")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n3"), draft_graph.get_node_by_serial("n5")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n5"), draft_graph.get_node_by_serial("n6")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n6"), draft_graph.get_node_by_serial("n9")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n10")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n10"), draft_graph.get_node_by_serial("n11")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n11"), draft_graph.get_node_by_serial("n12")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n11"), draft_graph.get_node_by_serial("n13")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n8"), draft_graph.get_node_by_serial("n14")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n7"), draft_graph.get_node_by_serial("n8")) draft_graph.connect_nodes(draft_graph.get_node_by_serial("n2"), draft_graph.get_node_by_serial("n15")) question_one = QuestionObject("How many red nodes are there?", QuestionTypes['NUMBER'], 1, Colours['red']) question_two = QuestionObject( "How many blue nodes do not have links to yellow nodes", QuestionTypes['NUMBER'], 5, Colours['blue'], Colours['yellow']) question_three = QuestionObject( "Which color has the largest number of nodes?", QuestionTypes['MULTIPLE_CHOICE'], 16) question_four = QuestionObject( "Is there a blue node that has at least 2 links to another blue node?", QuestionTypes['BOOLEAN'], 11, Colours['blue'], 2) question_five = QuestionObject( "What is the color of the node with the largest number of links?", QuestionTypes['MULTIPLE_CHOICE'], 3) question_six = QuestionObject("Is every blue node linked to a red node?", QuestionTypes['BOOLEAN'], 9, Colours['blue'], Colours['red']) question_seven = QuestionObject("Is there an even number of yellow nodes?", QuestionTypes['BOOLEAN'], 15, Colours['yellow'], 0) draft_graph.question_object_list = [ question_one, question_two, question_three, question_four, question_five, question_six, question_seven ] save_graph_json(draft_graph, "Graph_2.json")