def get_res_json(): """ Gets the resulting plots JSON :return: """ jsonDict = dict() # get the results tuples from the logic class function results_tuples = logic.return_top_ranks(current_lists, current_user_X_start, current_user_X_end, current_user_Y_end, current_user_Y_start) rank1_category = results_tuples[0][0] rank2_category = "" rank3_category = "" # only provide rank category names if they exist if (len(results_tuples) > 1): rank2_category = results_tuples[1][0] if (len(results_tuples) > 2): rank3_category = results_tuples[2][0] rank1_list = [] rank2_list = [] rank3_list = [] # traverse the rows and get respective rank values for row in current_array_of_rows: pair = {} pair['xValue'] = row.xValue pair['category'] = row.category pair['yValue'] = row.yValue if row.category == rank1_category: rank1_list.append(pair) if row.category == rank2_category: rank2_list.append(pair) if row.category == rank3_category: rank3_list.append(pair) # construct the dictionary jsonDict['datalist1'] = rank1_list jsonDict['datalist2'] = rank2_list jsonDict['datalist3'] = rank3_list return json.dumps(jsonDict)
def test_get_top_ranks(self): result = "iris-setosa" data_from_file = logic.get_data_dict(skip_header=1) dataset = data_from_file['dataset'] x_axis_number = 0 y_axis_number = 1 category_number = 4 current_array_of_rows = logic.make_row_objects(dataset, x_axis_number, y_axis_number, category_number) current_user_X_start = 2 current_user_Y_start = 0 current_user_X_end = 3 current_user_Y_end = 3 current_lists = logic.return_sorted_list(current_array_of_rows) results_tuples = logic.return_top_ranks(current_lists, current_user_X_start, current_user_X_end, current_user_Y_end, current_user_Y_start) print(results_tuples) self.assertEqual(result, "iris-setosa", "yes")