# Path: lib/vis.py
# def plot_data (data, output_directory, output_file_name):
# def generate_probability_distribution(data):
# def exponential_curve_fit_and_plot(data, output_directory, output_file_name):
# def exponential_curve_fit_and_plot_x_shifted(data, output_directory, output_file_name):
# def plot_infomap_igraph(i_graph, membership, output_directory, output_file_name, show_edges=True, aux_data=None):
# def generate_log_plots(plot_data, output_directory, output_file_name):
# def calc_plot_linear_fit(x_in, y_in, output_directory, output_file_name):
#             def trace_helper_pyplot(x, y, label, color):
# def generate_group_bar_charts(y_values, x_values, trace_header, output_directory, output_file_name):
# def csv_heatmap_generator_plotly(in_directory, output_directory, output_file_name):
# def matplotlob_csv_heatmap_generator(csv_file, output_directory, output_file_name):
#     def np_arrange_helper(data, disp):
# def box_plot(data, output_directory, output_file_name):
# 
# Path: lib/util.py
# def correctLastCharCR(inText):#
# def correct_nick_for_(inText):
# def to_graph(l):
# def to_edges(l):
# def exponential_curve_func(x, a, b, c):
# def get_year_month_day(day_content):
# def rec_list_splice(rec_list):
# def check_if_msg_line (line):
# def build_graphs(nick_sender, nick_receiver, time, year, month, day, day_graph, aggr_graph):
# def HACK_convert_nx_igraph(nx_graph):
# def extend_conversation_list(nick_sender, nick_receiver, conversation):
# def create_connected_nick_list(conn_comp_list):
# def correct_last_char_list(rec_list):
# def splice_find(line, search_param1, search_param2, splice_index):
# def get_nick_sen_rec(iter_range, nick_to_search, conn_comp_list, nick_sen_rec):
# def get_nick_representative(nicks, nick_same_list, nick_to_compare):
# def find_top_n_element_after_sorting(in_list, index, reverseBool, n):
# def count_number_of_users_on_channel(nick_same_list):
# def save_to_disk(data,file_name):
# def load_from_disk(file_name):
#     G = nx.Graph()


import os
import unittest
import matplotlib.pyplot as plt
import numpy as np
import plotly.graph_objs as go
from ddt import ddt, data, unpack
from mock import patch
from lib import vis, util
    @patch("matplotlib.pyplot.plot", autospec=True)
    @patch("matplotlib.pyplot.savefig", autospec=True)
    def test_plot_data(self, mock_savefig, mock_plot):
        data = ([[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 2, 4, 6, 8, 10, 12, 14, 16]])
        x_data, y_data = (d for d in data)
        x = np.array(x_data)
        y = np.array(y_data)

        vis.plot_data(data, self.test_data_dir, 'test')
        np.testing.assert_array_equal(x, mock_plot.call_args[0][0])
        np.testing.assert_array_equal(y, mock_plot.call_args[0][1])
        plt.savefig.assert_called_once_with(self.test_data_dir + "/" + "test" + ".png")

    @data(([[0, 5], [1, 10], [2, 5], [3, 7], [4, 3]],
           [float(5) / 30, float(10) / 30, float(5) / 30, float(7) / 30, float(3) / 30], [0, 1, 2, 3, 4]))
    @unpack
    def test_generate_probability_distribution(self, data, expected_freq, expected_x):
        x, freq = vis.generate_probability_distribution(data)
        self.assertAlmostEqual(x, expected_x)
        self.assertAlmostEqual(freq, expected_freq)

    def test_generate_probability_distribution_no_data(self):
        x, freq = vis.generate_probability_distribution(None)
        self.assertEqual(x, -1)
        self.assertEqual(freq, -1)

    @patch("lib.vis.generate_probability_distribution", autospec=True)
    @patch("lib.util.exponential_curve_func", autospec=True)
    @patch("lib.vis.curve_fit", autospec=True)
    def test_exponential_curve_fit_and_plot(self, mock_curve_fit, mock_curve_func, mock_probability_distribution):

# Path: lib/vis.py
# def plot_data (data, output_directory, output_file_name):
# def generate_probability_distribution(data):
# def exponential_curve_fit_and_plot(data, output_directory, output_file_name):
# def exponential_curve_fit_and_plot_x_shifted(data, output_directory, output_file_name):
# def plot_infomap_igraph(i_graph, membership, output_directory, output_file_name, show_edges=True, aux_data=None):
# def generate_log_plots(plot_data, output_directory, output_file_name):
# def calc_plot_linear_fit(x_in, y_in, output_directory, output_file_name):
#             def trace_helper_pyplot(x, y, label, color):
# def generate_group_bar_charts(y_values, x_values, trace_header, output_directory, output_file_name):
# def csv_heatmap_generator_plotly(in_directory, output_directory, output_file_name):
# def matplotlob_csv_heatmap_generator(csv_file, output_directory, output_file_name):
#     def np_arrange_helper(data, disp):
# def box_plot(data, output_directory, output_file_name):
# 
# Path: lib/util.py
# def correctLastCharCR(inText):#
# def correct_nick_for_(inText):
# def to_graph(l):
# def to_edges(l):
# def exponential_curve_func(x, a, b, c):
# def get_year_month_day(day_content):
# def rec_list_splice(rec_list):
# def check_if_msg_line (line):
# def build_graphs(nick_sender, nick_receiver, time, year, month, day, day_graph, aggr_graph):
# def HACK_convert_nx_igraph(nx_graph):
# def extend_conversation_list(nick_sender, nick_receiver, conversation):
# def create_connected_nick_list(conn_comp_list):
# def correct_last_char_list(rec_list):
# def splice_find(line, search_param1, search_param2, splice_index):
# def get_nick_sen_rec(iter_range, nick_to_search, conn_comp_list, nick_sen_rec):
# def get_nick_representative(nicks, nick_same_list, nick_to_compare):
# def find_top_n_element_after_sorting(in_list, index, reverseBool, n):
# def count_number_of_users_on_channel(nick_same_list):
# def save_to_disk(data,file_name):
# def load_from_disk(file_name):
#     G = nx.Graph()


# Path: test/unit-test/test_lib/test_vis.py
import os
import unittest
import matplotlib.pyplot as plt
import numpy as np
import plotly.graph_objs as go
from ddt import ddt, data, unpack
from mock import patch
from lib import vis, util

    @patch("matplotlib.pyplot.plot", autospec=True)
    @patch("matplotlib.pyplot.savefig", autospec=True)
    def test_plot_data(self, mock_savefig, mock_plot):
        data = ([[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 2, 4, 6, 8, 10, 12, 14, 16]])
        x_data, y_data = (d for d in data)
        x = np.array(x_data)
        y = np.array(y_data)

        vis.plot_data(data, self.test_data_dir, 'test')
        np.testing.assert_array_equal(x, mock_plot.call_args[0][0])
        np.testing.assert_array_equal(y, mock_plot.call_args[0][1])
        plt.savefig.assert_called_once_with(self.test_data_dir + "/" + "test" + ".png")

    @data(([[0, 5], [1, 10], [2, 5], [3, 7], [4, 3]],
           [float(5) / 30, float(10) / 30, float(5) / 30, float(7) / 30, float(3) / 30], [0, 1, 2, 3, 4]))
    @unpack
    def test_generate_probability_distribution(self, data, expected_freq, expected_x):
        x, freq = vis.generate_probability_distribution(data)
        self.assertAlmostEqual(x, expected_x)
        self.assertAlmostEqual(freq, expected_freq)

    def test_generate_probability_distribution_no_data(self):
        x, freq = vis.generate_probability_distribution(None)
        self.assertEqual(x, -1)
        self.assertEqual(freq, -1)

    @patch("lib.vis.generate_probability_distribution", autospec=True)
    @patch("lib.util.exponential_curve_func", autospec=True)
    @patch("lib.vis.curve_fit", autospec=True)
    def test_exponential_curve_fit_and_plot(self, mock_curve_fit, mock_curve_func, mock_probability_distribution):

        data = util.load_from_disk(self.test_data_dir + "/vis/conv_len")