# Path: lib/slack/in_out/reader.py
# def linux_input_slack(log_directory, starting_date, ending_date):
#     def check_if_path_is_valid(work_path):
# 
# 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: lib/analysis/user.py
# def nick_change_graph(log_dict, DAY_BY_DAY_ANALYSIS=False):
# def top_keywords_for_nick(user_keyword_freq_dict, nick, threshold, min_words_spoken):
# def keywords(log_dict, nicks, nick_same_list):
#     def get_nick_receiver(nick_receiver, rec, nick_to_compare, nick_name, nicks, nick_same_list):
# def keywords_clusters(log_dict, nicks, nick_same_list, output_directory, out_file_name):
#     def build_centroid(km):
# def extended_stop_words(nicks_for_stop_words, stop_word_without_apostrophe):
# 
# Path: lib/analysis/community.py
# def infomap_igraph(ig_graph, net_file_location=None):
# 
# Path: lib/slack/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, nick_sender, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None):
#     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/slack/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)


from lib.slack.in_out import reader
from lib.in_out import saver
from lib.analysis import user, community
from lib.slack.analysis import network, channel
import lib.slack.nickTracker as nickTracker, lib.slack.config as config, lib.vis as vis, lib.validate as validate, lib.slack.util as util
import numpy as np
import networkx as nx
import gc
import datetime
from __future__ import print_function

log_directory = config.LOG_DIRECTORY
channel_name = config.CHANNEL_NAME
starting_date = config.STARTING_DATE
ending_date = config.ENDING_DATE
output_directory = config.OUTPUT_DIRECTORY

exec_times_file = open(output_directory + "execution_times.txt", 'w')

degree_type = ["out_degree", "in_degree", "total_degree"]

print("begin at: ", datetime.datetime.now(), file=exec_times_file)
exec_times_file.flush()


# ============== INPUT==================
log_data = reader.linux_input_slack(log_directory, starting_date, ending_date)
nicks, nick_same_list = nickTracker.nick_tracker(log_data)
print("reading log files completed at: ", datetime.datetime.now(), file=exec_times_file)
exec_times_file.flush()


# ============== MESSAGE BINS HEATMAP =============
bin_matrix, total_messages = network.message_number_bins_csv(log_data, nicks, nick_same_list)
data = [[i for i in range(len(bin_matrix[0]))]]
data.append([sum(i) for i in zip(*bin_matrix)])

# Path: lib/slack/in_out/reader.py
# def linux_input_slack(log_directory, starting_date, ending_date):
#     def check_if_path_is_valid(work_path):
# 
# 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: lib/analysis/user.py
# def nick_change_graph(log_dict, DAY_BY_DAY_ANALYSIS=False):
# def top_keywords_for_nick(user_keyword_freq_dict, nick, threshold, min_words_spoken):
# def keywords(log_dict, nicks, nick_same_list):
#     def get_nick_receiver(nick_receiver, rec, nick_to_compare, nick_name, nicks, nick_same_list):
# def keywords_clusters(log_dict, nicks, nick_same_list, output_directory, out_file_name):
#     def build_centroid(km):
# def extended_stop_words(nicks_for_stop_words, stop_word_without_apostrophe):
# 
# Path: lib/analysis/community.py
# def infomap_igraph(ig_graph, net_file_location=None):
# 
# Path: lib/slack/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, nick_sender, nick, conn_comp_list,conversations,today_conversation):
#     def message_no_add_egde(message_graph, conversation):
# def filter_edge_list(edgelist_file_loc, max_hash, how_many_top):
# def degree_analysis_on_graph(nx_graph, date=None):
#     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/slack/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: slack.py
from lib.slack.in_out import reader
from lib.in_out import saver
from lib.analysis import user, community
from lib.slack.analysis import network, channel
import lib.slack.nickTracker as nickTracker, lib.slack.config as config, lib.vis as vis, lib.validate as validate, lib.slack.util as util
import numpy as np
import networkx as nx
import gc
import datetime

from __future__ import print_function

log_directory = config.LOG_DIRECTORY
channel_name = config.CHANNEL_NAME
starting_date = config.STARTING_DATE
ending_date = config.ENDING_DATE
output_directory = config.OUTPUT_DIRECTORY

exec_times_file = open(output_directory + "execution_times.txt", 'w')

degree_type = ["out_degree", "in_degree", "total_degree"]

print("begin at: ", datetime.datetime.now(), file=exec_times_file)
exec_times_file.flush()


# ============== INPUT==================
log_data = reader.linux_input_slack(log_directory, starting_date, ending_date)
nicks, nick_same_list = nickTracker.nick_tracker(log_data)
print("reading log files completed at: ", datetime.datetime.now(), file=exec_times_file)
exec_times_file.flush()


# ============== MESSAGE BINS HEATMAP =============
bin_matrix, total_messages = network.message_number_bins_csv(log_data, nicks, nick_same_list)
data = [[i for i in range(len(bin_matrix[0]))]]
data.append([sum(i) for i in zip(*bin_matrix)])

saver.save_csv(bin_matrix, output_directory, "MessageNumber_binsize_"+str(config.BIN_LENGTH_MINS)) 