def test_draw_nx_graph(self):
        graph = nx.DiGraph()
        graph.add_nodes_from([1, 2, 3])
        graph.add_edge(1, 3)

        saver.draw_nx_graph(graph, self.current_directory, 'nx_graph')
        assert os.path.exists(self.current_directory + '/nx_graph.svg')
        assert os.path.isfile(self.current_directory + '/nx_graph.svg')

        os.remove(self.current_directory + '/nx_graph.svg')
Beispiel #2
0
def keywords_hits_overlap(log_directory, output_directory, channel_name):
    # Correlational: overlap for keyword digest and HITS
    for month in xrange(1, 13):
        log_data_m1 = reader.linux_input(log_directory, channel_name,
                                         "2013-" + str(month) + "-1",
                                         "2013-" + str(month) + "-31")
        nicks_m1, nick_same_list_m1 = nickTracker.nick_tracker(log_data_m1)
        message_graph_m1, top_hubs_m1, top_keyword_overlap_m1, top_auth_m1 = network.identify_hubs_and_experts(
            log_data_m1, nicks_m1, nick_same_list_m1)
        saver.draw_nx_graph(message_graph_m1, output_directory,
                            "expert-month-" + str(month))

        log_data_m2 = reader.linux_input(log_directory, channel_name,
                                         "2013-" + str(month + 1) + "-1",
                                         "2013-" + str(month + 1) + "-31")
        nicks_m2, nick_same_list_m2 = nickTracker.nick_tracker(log_data_m1)
        message_graph_m2, top_hubs_m2, top_keyword_overlap_with_score_m2, top_auth_m2 = network.identify_hubs_and_experts(
            log_data_m2, nicks_m2, nick_same_list_m2)

        print "Top 10 HUBS for Month [HITS]", month, ":", top_hubs_m1
        print "Top 10 HUBS for Month [HITS]", month + 1, ":", top_hubs_m2
        print "Number of common HUBS (from 10) between above 2 months:", len(
            list(set(top_hubs_m1).intersection(top_hubs_m2)))

        print "Top 10 Experts by keywords for Months", month, ":", top_keyword_overlap_m1
        print "Top 10 Experts by keywords for Months", month + 1, ":", top_keyword_overlap_with_score_m2
        print "Number of common Experts by keywords (from 10) between above 2 months:", len(
            list(
                set(top_keyword_overlap_m1).intersection(
                    top_keyword_overlap_with_score_m2)))

        print "Top 10 AUTH for Month [HITS]", month, ":", top_auth_m1
        print "Top 10 AUTH for Month [HITS]", month + 1, ":", top_auth_m2
        print "Number of common AUTH (from 10) between above 2 months:", len(
            list(set(top_auth_m1).intersection(top_auth_m2)))

        print "Number of users common btw HUBS from HITS and Experts by Keywords (from 10) for month", month, ":", len(
            list(set(top_keyword_overlap_m1).intersection(top_hubs_m1)))
        print "Number of users common btw AUTH from HITS and Experts by Keywords (from 10) for month", month, ":", len(
            list(set(top_keyword_overlap_m1).intersection(top_auth_m1)))
        print "Number of users common btw HUBS from HITS and AUTH from HITS (from 10) for month", month, ":", len(
            list(set(top_hubs_m1).intersection(top_auth_m1)))
        print "Number of users common btw HUBS, HITS and KEYWORDS", month, ":", len(
            set(list(set(top_keyword_overlap_m1).intersection(
                top_hubs_m1))).intersection(top_auth_m1))
Beispiel #3
0
out_degree_node_number, in_degree_node_number, total_degree_node_number = network.degree_node_number_csv(
    log_data, nicks, nick_same_list)
nick_change_graph_list = user.nick_change_graph(log_data, True)
bin_matrix, total_messages = network.message_number_bins_csv(
    log_data, nicks, nick_same_list)
conv_len, conv_ref_time = channel.conv_len_conv_refr_time(
    log_data, nicks, nick_same_list)
resp_time = channel.response_time(log_data, nicks, nick_same_list)

user.keywords_clusters(log_data, nicks, nick_same_list)
network.degree_analysis_on_graph(message_number_graph)

# adjCC_graph, adjCC_membership = community.infomap_igraph(ig_graph=None, net_file_location="/home/rohan/Desktop/adjCC.net")

# ============== OUTPUT ================
saver.draw_nx_graph(message_number_graph, output_directory,
                    "message_number_graph")
saver.save_csv(degree_anal_message_numder["out_degree"]["formatted_for_csv"],
               output_directory, "out_degree")
saver.save_csv(degree_anal_message_numder["in_degree"]["formatted_for_csv"],
               output_directory, "in_degree")
saver.save_csv(degree_anal_message_numder["total_degree"]["formatted_for_csv"],
               output_directory, "total_degree")
saver.save_csv(out_degree_node_number, output_directory,
               "node_out_degree" + starting_date + '-' + ending_date)
saver.save_csv(in_degree_node_number, output_directory,
               "node_in_degree" + starting_date + '-' + ending_date)
saver.save_csv(total_degree_node_number, output_directory,
               "node_total_degree" + starting_date + '-' + ending_date)
saver.save_csv(bin_matrix, output_directory,
               "MessageNumber_binsize_" + str(config.BIN_LENGTH_MINS))
for i in range(len(message_number_graph_day_list)):
Beispiel #4
0
    saver.save_csv( [["a","b","c", "MSE"], [conv_len_curve_fit_parameters]], output_directory,"conv_len_curve_fit_parameters-cutoff-" + str(cutoff))
    saver.save_csv( [["a","b","c", "MSE"], [resp_time_curve_fit_parameters]], output_directory,"resp_time_curve_fit_parameters-cutoff-" + str(cutoff))
    saver.save_csv( [["a","b","c", "MSE"], [conv_ref_time_curve_fit_parameters]], output_directory,"conv_ref_time_curve_fit_parameters-cutoff-"+str(cutoff))

config.CUTOFF_PERCENTILE = default_cutoff #revert back to default

user.keywords_clusters(log_data, nicks, nick_same_list, output_directory, "keywords")
network.degree_analysis_on_graph(message_number_graph)

threshold = config.THRESHOLD_MESSAGE_NUMBER_GRAPH #store original default config
cutoffs = [0, 10, 20]

for cutoff in cutoffs:
    config.THRESHOLD_MESSAGE_NUMBER_GRAPH = cutoff
    msg_graph_experts, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts(log_data, nicks, nick_same_list)
    saver.draw_nx_graph (msg_graph_experts, output_directory, "hits-cutoff-"+str(cutoff))

config.THRESHOLD_MESSAGE_NUMBER_GRAPH = threshold #revert to default config

# ============== OUTPUT ================
saver.save_net_nx_graph (message_number_graph, output_directory, "message_number_graph")
saver.draw_nx_graph(message_number_graph, output_directory, "message_number_graph")

saver.save_csv([["response_time_cutoff"], [rt_cutoff_time]], output_directory, "rt_cutoff")
saver.save_csv([["month", "users", "directed_messages"], ["Jan-2013", len(message_number_graph), int(message_number_graph.size('weight'))]], output_directory, "users_messages")

for dtype in degree_type:
    saver.save_csv(degree_anal_message_number[dtype]["formatted_for_csv"], output_directory, dtype)   

saver.save_csv(bin_matrix, output_directory, "MessageNumber_binsize_"+str(config.BIN_LENGTH_MINS)) 
Beispiel #5
0
degree_anal_message_numder = network.degree_analysis_on_graph(message_number_graph)
message_time_graph_list = network.message_time_graph(log_data, nicks, nick_same_list, True)
message_time_graph = network.message_time_graph(log_data, nicks, nick_same_list, False)
out_degree_node_number, in_degree_node_number, total_degree_node_number = network.degree_node_number_csv(log_data, nicks, nick_same_list)
nick_change_graph_list =  user.nick_change_graph(log_data, True)
bin_matrix, total_messages = network.message_number_bins_csv(log_data, nicks, nick_same_list)
conv_len, conv_ref_time = channel.conv_len_conv_refr_time(log_data, nicks, nick_same_list)
resp_time = channel.response_time(log_data, nicks, nick_same_list)

user.keywords_clusters(log_data, nicks, nick_same_list)
network.degree_analysis_on_graph(message_number_graph)

# adjCC_graph, adjCC_membership = community.infomap_igraph(ig_graph=None, net_file_location="/home/rohan/Desktop/adjCC.net")

# ============== OUTPUT ================
saver.draw_nx_graph(message_number_graph, output_directory, "message_number_graph")
saver.save_csv(degree_anal_message_numder["out_degree"]["formatted_for_csv"], output_directory, "out_degree")
saver.save_csv(degree_anal_message_numder["in_degree"]["formatted_for_csv"], output_directory, "in_degree")
saver.save_csv(degree_anal_message_numder["total_degree"]["formatted_for_csv"], output_directory, "total_degree")
saver.save_csv(out_degree_node_number, output_directory, "node_out_degree" + starting_date +'-'+ending_date)
saver.save_csv(in_degree_node_number, output_directory, "node_in_degree"+ starting_date +'-'+ending_date)
saver.save_csv(total_degree_node_number, output_directory, "node_total_degree"+ starting_date +'-'+ending_date)
saver.save_csv(bin_matrix, output_directory, "MessageNumber_binsize_"+str(config.BIN_LENGTH_MINS))
for i in range(len(message_number_graph_day_list)):
    saver.draw_nx_graph(message_number_graph_day_list[i][0], output_directory, "mng" + str(i+1))
for i in range(len(nick_change_graph_list)):
    saver.draw_nx_graph(nick_change_graph_list[i], output_directory, "ncg" + str(i+1))

saver.draw_nx_graph(message_number_graph, output_directory, "mnagg")    
saver.draw_nx_graph(message_time_graph, output_directory, "mtgagg")
saver.save_csv(conv_len, output_directory, "conv_len")
Beispiel #6
0
def keywords_hits_overlap(log_directory, output_directory, channel_name,
                          start_date, end_date):
    """
        The function iterates through the months in the given date range and produces the authorities, top keywords and
        top hubs for the current month and the next month. It also produces the overlap of authorities, top keywords and
        top hubs between the current and the next month.

    Args:
        log_directory(str): path to the location of Logs
        output_directory(str):  path to the location where the results are to be stored
        channel_name(list): channels for which the analysis is to be done
        start_date(datetime): starting date for the logs to be analysed. This has to be the beginning of the month.
        end_date(datetime): ending date for which the logs are to be analysed. This has to be the end of the month.

    Returns:
       null

    """
    start_date = start_date.strptime('%Y-%m-%d')
    end_date = end_date.strptime('%Y-%m-%d')
    for dt in rrule(MONTHLY, dtstart=start_date, until=end_date):
        last_day_of_the_month1 = dt + relativedelta(
            months=1) - datetime.timedelta(days=1)
        log_data_m1 = reader.linux_input(
            log_directory, channel_name, dt.strftime("%Y-%m-%d"),
            last_day_of_the_month1.strftime("%Y-%m-%d"))
        nicks_m1, nick_same_list_m1 = nickTracker.nick_tracker(log_data_m1)
        message_graph_m1, top_hubs_m1, top_keyword_overlap_m1, top_auth_m1 = network.identify_hubs_and_experts(
            log_data_m1, nicks_m1, nick_same_list_m1)
        saver.draw_nx_graph(message_graph_m1, output_directory,
                            "expert-month-" + str(dt.month))

        next_month_dt = dt + relativedelta(months=1)
        last_day_of_the_month2 = next_month_dt + relativedelta(
            months=1) - datetime.timedelta(days=1)
        log_data_m2 = reader.linux_input(
            log_directory, channel_name, next_month_dt.strftime("%Y-%m-%d"),
            last_day_of_the_month2.strftime("%Y-%m-%d"))
        nicks_m2, nick_same_list_m2 = nickTracker.nick_tracker(log_data_m2)
        message_graph_m2, top_hubs_m2, top_keyword_overlap_with_score_m2, top_auth_m2 = network.identify_hubs_and_experts(
            log_data_m2, nicks_m2, nick_same_list_m2)

        print "Top 10 HUBS for Month [HITS]", dt.month, ":", top_hubs_m1
        print "Top 10 HUBS for Month [HITS]", next_month_dt.month, ":", top_hubs_m2
        print "Number of common HUBS (from 10) between above 2 months:", len(
            list(set(top_hubs_m1).intersection(top_hubs_m2)))

        print "Top 10 Experts by keywords for Months", dt.month, ":", top_keyword_overlap_m1
        print "Top 10 Experts by keywords for Months", next_month_dt.month, ":", top_keyword_overlap_with_score_m2
        print "Number of common Experts by keywords (from 10) between above 2 months:", len(
            list(
                set(top_keyword_overlap_m1).intersection(
                    top_keyword_overlap_with_score_m2)))

        print "Top 10 AUTH for Month [HITS]", dt.month, ":", top_auth_m1
        print "Top 10 AUTH for Month [HITS]", next_month_dt.month, ":", top_auth_m2
        print "Number of common AUTH (from 10) between above 2 months:", len(
            list(set(top_auth_m1).intersection(top_auth_m2)))

        print "Number of users common btw HUBS from HITS and Experts by Keywords (from 10) for month", dt.month, ":", len(
            list(set(top_keyword_overlap_m1).intersection(top_hubs_m1)))
        print "Number of users common btw AUTH from HITS and Experts by Keywords (from 10) for month", dt.month, ":", len(
            list(set(top_keyword_overlap_m1).intersection(top_auth_m1)))
        print "Number of users common btw HUBS from HITS and AUTH from HITS (from 10) for month", dt.month, ":", len(
            list(set(top_hubs_m1).intersection(top_auth_m1)))
        print "Number of users common btw HUBS, HITS and KEYWORDS", dt.month, ":", len(
            set(list(set(top_keyword_overlap_m1).intersection(
                top_hubs_m1))).intersection(top_auth_m1))