# Path: lib/analysis/network.py
# def message_number_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def msg_no_analysis_helper(rec_list, corrected_nick, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def channel_user_presence_graph_and_csv(nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash):
#     def create_adj_matrix(hashed_list1, hashed_list2):
#     def add_channel_weighted_edge(graph, adjlist, nicks_hash, channels_hash, channel):
#     def add_common_users_weighted_edge(graph, index1, index2, common_users):
#     def print_node_degree(nodes, max_degree_possible):
#     def inc_degree(degree_list, nodes, max_degree_possible):        
#     def get_top_indices(sum_list, how_many_vals):        
#     def get_indices_to_delete(hash_list, top_indices):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None, directed = True):
#     def nodes_with_degree_populator(degree_values, label): 
#     def give_userlist_where_degree_helper(degree_dict, degree):
#     def raw_node_append(nodes, raw, degree_type):        
# def message_time_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def compare_spliced_nick(nick_to_compare, spliced_nick, nick_name, line):
# def message_number_bins_csv(log_dict, nicks, nick_same_list):
#     def bin_increment(nick_name, messager, nick_spliced, bins, bin_index):
# def degree_node_number_csv(log_dict, nicks, nick_same_list):
#     def format_degree_list(degree_list, max_range, degree_type):
# def nick_receiver_from_conn_comp(nick, conn_comp_list):
# def identify_hubs_and_experts(log_dict, nicks, nick_same_list):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)
# 
# Path: lib/analysis/channel.py
# def conv_len_conv_refr_time(log_dict, nicks, nick_same_list, rt_cutoff_time, cutoff_percentile):
#     def build_conversation(rec_list, nick, send_time, nick_to_search,
#                            nick_receiver, nick_sender, dateadd,
#                            conversations, conn_comp_list, line):
#     def conv_helper(rec, nick, send_time, nick_to_search, nick_receiver,
#                     nick_sender, dateadd, conversations, conn_comp_list, line):
#     def conv_mat_diff(i,j,conversations):
#     def conv_append(conversations, index, dateadd, line):
#     def parse_log_lines_for_conv(log_dict, nicks, conn_comp_list, conversations):
# def response_time(log_dict, nicks, nick_same_list, cutoff_percentile):
#     def build_mean_list(conversations, index, mean_list):
#     def resp_helper(rec, nick, send_time, nick_to_search, nick_receiver, nick_sender, conversations, conn_comp_list):
# def build_stat_dist(number_list):
# def truncate_table(table, cutoff_percentile):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)
# 
# Path: lib/analysis/community.py
# def infomap_igraph(ig_graph, net_file_location=None):
# 
# Path: lib/in_out/reader.py
# def linux_input(log_directory, channels_requested, starting_date, ending_date):
#     def check_if_path_and_file_is_valid(work_path, channels_requested):
# 
# Path: lib/in_out/saver.py
# def check_if_dir_exists(output_directory):
# def draw_nx_graph(nx_graph, output_directory, output_file_name):
# def save_net_nx_graph(nx_graph, output_directory, output_file_name):
# def save_csv(matrix, output_directory, output_file_name):
# def save_js_arc(reduced_CC_graph, channels_hash, output_directory, output_file_name):
#     A = nx.nx.drawing.nx_agraph.to_agraph(nx_graph)


import os
import unittest
import networkx as nx
import numpy as np
import lib.config as config
import lib.nickTracker as nickTracker
import lib.util as util
import lib.vis as vis
from igraph.clustering import compare_communities
from lib.analysis import network, channel, community
from lib.in_out import reader, saver




class NetworkProfileTest(unittest.TestCase):
    def setUp(self):
        self.current_directory = os.path.dirname(os.path.realpath(__file__))
        self.log_data_dir = self.current_directory + "/data/input/"
        self.start_date = '2013-01-01'
        self.end_date = '2013-01-08'

    def tearDown(self):
        self.current_directory = None
        self.log_data_dir = None
        self.start_date = None
        self.end_date = None

    def test_presence_networks(self):
        log_data = reader.linux_input(self.log_data_dir, ["ALL"], self.start_date, self.end_date)
        expected_result = util.load_from_disk(self.current_directory + '/data/output/presence_graph_dict')
        nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash = nickTracker.nick_tracker(log_data, True)

# Path: lib/analysis/network.py
# def message_number_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def msg_no_analysis_helper(rec_list, corrected_nick, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def channel_user_presence_graph_and_csv(nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash):
#     def create_adj_matrix(hashed_list1, hashed_list2):
#     def add_channel_weighted_edge(graph, adjlist, nicks_hash, channels_hash, channel):
#     def add_common_users_weighted_edge(graph, index1, index2, common_users):
#     def print_node_degree(nodes, max_degree_possible):
#     def inc_degree(degree_list, nodes, max_degree_possible):        
#     def get_top_indices(sum_list, how_many_vals):        
#     def get_indices_to_delete(hash_list, top_indices):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None, directed = True):
#     def nodes_with_degree_populator(degree_values, label): 
#     def give_userlist_where_degree_helper(degree_dict, degree):
#     def raw_node_append(nodes, raw, degree_type):        
# def message_time_graph(log_dict, nicks, nick_same_list, DAY_BY_DAY_ANALYSIS=False):
#     def compare_spliced_nick(nick_to_compare, spliced_nick, nick_name, line):
# def message_number_bins_csv(log_dict, nicks, nick_same_list):
#     def bin_increment(nick_name, messager, nick_spliced, bins, bin_index):
# def degree_node_number_csv(log_dict, nicks, nick_same_list):
#     def format_degree_list(degree_list, max_range, degree_type):
# def nick_receiver_from_conn_comp(nick, conn_comp_list):
# def identify_hubs_and_experts(log_dict, nicks, nick_same_list):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)
# 
# Path: lib/analysis/channel.py
# def conv_len_conv_refr_time(log_dict, nicks, nick_same_list, rt_cutoff_time, cutoff_percentile):
#     def build_conversation(rec_list, nick, send_time, nick_to_search,
#                            nick_receiver, nick_sender, dateadd,
#                            conversations, conn_comp_list, line):
#     def conv_helper(rec, nick, send_time, nick_to_search, nick_receiver,
#                     nick_sender, dateadd, conversations, conn_comp_list, line):
#     def conv_mat_diff(i,j,conversations):
#     def conv_append(conversations, index, dateadd, line):
#     def parse_log_lines_for_conv(log_dict, nicks, conn_comp_list, conversations):
# def response_time(log_dict, nicks, nick_same_list, cutoff_percentile):
#     def build_mean_list(conversations, index, mean_list):
#     def resp_helper(rec, nick, send_time, nick_to_search, nick_receiver, nick_sender, conversations, conn_comp_list):
# def build_stat_dist(number_list):
# def truncate_table(table, cutoff_percentile):
#     G = util.to_graph(nick_same_list)
#     G = util.to_graph(nick_same_list)
# 
# Path: lib/analysis/community.py
# def infomap_igraph(ig_graph, net_file_location=None):
# 
# Path: lib/in_out/reader.py
# def linux_input(log_directory, channels_requested, starting_date, ending_date):
#     def check_if_path_and_file_is_valid(work_path, channels_requested):
# 
# Path: lib/in_out/saver.py
# def check_if_dir_exists(output_directory):
# def draw_nx_graph(nx_graph, output_directory, output_file_name):
# def save_net_nx_graph(nx_graph, output_directory, output_file_name):
# def save_csv(matrix, output_directory, output_file_name):
# def save_js_arc(reduced_CC_graph, channels_hash, output_directory, output_file_name):
#     A = nx.nx.drawing.nx_agraph.to_agraph(nx_graph)


# Path: test/functional-test/test_networkprofile.py
import os
import unittest
import networkx as nx
import numpy as np
import lib.config as config
import lib.nickTracker as nickTracker
import lib.util as util
import lib.vis as vis
from igraph.clustering import compare_communities
from lib.analysis import network, channel, community
from lib.in_out import reader, saver





class NetworkProfileTest(unittest.TestCase):
    def setUp(self):
        self.current_directory = os.path.dirname(os.path.realpath(__file__))
        self.log_data_dir = self.current_directory + "/data/input/"
        self.start_date = '2013-01-01'
        self.end_date = '2013-01-08'

    def tearDown(self):
        self.current_directory = None
        self.log_data_dir = None
        self.start_date = None
        self.end_date = None

    def test_presence_networks(self):
        log_data = reader.linux_input(self.log_data_dir, ["ALL"], self.start_date, self.end_date)
        expected_result = util.load_from_disk(self.current_directory + '/data/output/presence_graph_dict')
        nicks, nick_same_list, channels_for_user, nick_channel_dict, nicks_hash, channels_hash = nickTracker.nick_tracker(log_data, True)

        expected_output, graph = network.channel_user_presence_graph_and_csv(nicks, nick_same_list, channels_for_user,