def test_truncate_table_with_short_table(): resp_time = [(0, 9), (1, 12), (2, 3), (3, 1), (4, 1), (5, 5), (6, 0), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1), (12, 0), (13, 0), (14, 1), (15, 0), (16, 0), (17, 1), (18, 0), (19, 0), (20, 1)] expected_cutoff_time = 14 cutoff_percentile = 5.0 truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile) assert cutoff_time == expected_cutoff_time, \ "Error in computing percentile cutoff value" cutoff_percentile = 1.0 expected_cutoff_time = 17 truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile) assert cutoff_time == expected_cutoff_time, \ "Error in computing percentile cutoff value"
def test_truncate_table_with_long_table(): resp_time = util.load_from_disk(current_directory+ "/data/resp_time") expected_cutoff_time = 989 cutoff_percentile = 5 truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile) assert cutoff_time == expected_cutoff_time, \ "Error in computing percentile cutoff value" cutoff_percentile = 1 expected_cutoff_time = 1436 truncated_table, cutoff_time = channel.truncate_table(resp_time, cutoff_percentile) assert cutoff_time == expected_cutoff_time, \ "Error in computing percentile cutoff value"
def test_truncate_table_with_long_table(self): resp_time = util.load_from_disk(self.test_data_dir + "/channel/resp_time") expected_cutoff_time = 989 cutoff_percentile = 5 truncated_table, cutoff_time = channel.truncate_table( resp_time, cutoff_percentile) self.assertEqual(cutoff_time, expected_cutoff_time, \ "Error in computing percentile cutoff value") cutoff_percentile = 1 expected_cutoff_time = 1436 truncated_table, cutoff_time = channel.truncate_table( resp_time, cutoff_percentile) self.assertEqual(cutoff_time, expected_cutoff_time, \ "Error in computing percentile cutoff value")
def test_degree_distribution_multi_channel(self): log_data = reader.linux_input(self.log_data_dir, ["ALL"], self.start_date, self.end_date) expected_result_CC_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/CC_degree_curve_fit') expected_result_CU_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/CU_degree_curve_fit') expected_result_UU_degree_curve_fit = util.load_from_disk( self.current_directory + '/data/output/UU_degree_curve_fit') nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash = nickTracker.nick_tracker( log_data, True) dict_out, graph = network.channel_user_presence_graph_and_csv( nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash) degree_anal_message_number_CC = network.degree_analysis_on_graph( dict_out["CC"]["graph"], directed=False) degree_anal_message_number_UU = network.degree_analysis_on_graph( dict_out["UU"]["graph"], directed=False) degree_anal_message_number_CU = network.degree_analysis_on_graph( dict_out["CU"]["graph"], directed=False) Y = degree_anal_message_number_CU["degree"]["raw_for_vis"][1:] data = [(i, Y[i]) for i in range(len(Y))] CU_truncated, cutoff = channel.truncate_table(data, 0.5) CU_T = [data[1] for data in list(CU_truncated)] expected_output_CC_degree_curve_fit = vis.generate_log_plots( degree_anal_message_number_CC["degree"]["raw_for_vis"], self.current_directory, "CC_degree_curve_fit") expected_output_CU_degree_curve_fit = vis.generate_log_plots( CU_T, self.current_directory, "CU_degree_curve_fit") expected_output_UU_degree_curve_fit = vis.generate_log_plots( degree_anal_message_number_UU["degree"]["raw_for_vis"], self.current_directory, "UU_degree_curve_fit") os.remove(self.current_directory + "/CC_degree_curve_fit" + ".png") os.remove(self.current_directory + "/CU_degree_curve_fit" + ".png") os.remove(self.current_directory + "/UU_degree_curve_fit" + ".png") self.assertEqual(expected_result_CC_degree_curve_fit, expected_output_CC_degree_curve_fit) self.assertEqual(expected_result_CU_degree_curve_fit, expected_output_CU_degree_curve_fit) self.assertEqual(expected_result_UU_degree_curve_fit, expected_output_UU_degree_curve_fit)
vis.plot_infomap_igraph(adj_graph, adj_comm.membership, output_directory, "adj"+ptype+"_infomaps-full") degree_anal_message_number_CC = network.degree_analysis_on_graph(dict_out["CC"]["graph"], directed=False) saver.save_csv(degree_anal_message_number_CC["degree"]["formatted_for_csv"], output_directory, "CC_degree") degree_anal_message_number_UU = network.degree_analysis_on_graph(dict_out["UU"]["graph"], directed = False) saver.save_csv(degree_anal_message_number_UU["degree"]["formatted_for_csv"], output_directory, "UU_degree") degree_anal_message_number_CU = network.degree_analysis_on_graph(dict_out["CU"]["graph"], directed=False) saver.save_csv(degree_anal_message_number_CU["degree"]["formatted_for_csv"], output_directory, "CU_degree") slope,intercept,r_square,mse = vis.generate_log_plots(degree_anal_message_number_CC["degree"]["raw_for_vis"], output_directory, "CC_degree_curve_fit") saver.save_csv( [["Y","K","R^2", "MSE"], [slope,intercept,r_square,mse]], output_directory,"CC-degree-curve-fit") Y = degree_anal_message_number_CU["degree"]["raw_for_vis"][1:] data = [(i, Y[i]) for i in range(len(Y))] CU_truncated, cutoff = channel.truncate_table(data, 0.5) CU_T = [ data[1] for data in list(CU_truncated)] slope,intercept,r_square,mse = vis.generate_log_plots(CU_T, output_directory, "CU_degre_curve_fit") saver.save_csv( [["Y","K","R^2", "MSE"], [slope,intercept,r_square,mse]], output_directory,"CU-degree-curve-fit") slope,intercept,r_square,mse = vis.generate_log_plots(degree_anal_message_number_UU["degree"]["raw_for_vis"], output_directory, "UU_degree_curve_fit") saver.save_csv( [["Y","K","R^2", "MSE"], [slope,intercept,r_square,mse]], output_directory,"UU-degree-curve-fit") # ======================== Heatmap ========================= log_data = reader.linux_input(log_directory, ["#kubuntu-devel"], "2013-1-1", "2013-12-31") nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash = nickTracker.nick_tracker(log_data, True) bin_matrix, total_messages = network.message_number_bins_csv(log_data, nicks, nick_same_list) saver.save_csv(bin_matrix, output_directory, "heatmap") vis.matplotlob_csv_heatmap_generator(output_directory +"heatmap.csv", output_directory, "heatmap-plot")