# Path: logparser/utils/logloader.py
# class LogLoader(object):
#     def __init__(self, logformat, n_workers=1):
#     def load_to_dataframe(self, log_filepath):
#     def _generate_logformat_regex(self, logformat):
# def formalize_message(enumerated_lines, regex, headers):


from ..utils import logloader
from collections import defaultdict, Counter, OrderedDict
from datetime import datetime
import re
import pandas as pd
import os
import multiprocessing as mp
import itertools
import hashlib
import numpy as np

    def match_event(self, event_list):
        match_list = []
        paras = []
        if self.n_workers == 1:
            results = match_fn(event_list, self.template_match_dict, self.optimized)
        else:
            pool = mp.Pool(processes=self.n_workers)
            chunk_size = len(event_list) / self.n_workers + 1
            result_chunks = [pool.apply_async(match_fn, args=(event_list[i:i + chunk_size], self.template_match_dict, self.optimized))\
                             for i in xrange(0, len(event_list), chunk_size)]
            pool.close()
            pool.join()
            results = list(itertools.chain(*[result.get() for result in result_chunks]))
        for event, parameter_list in results:
            self.template_freq_dict[event] += 1
            paras.append(parameter_list)
            match_list.append(event)
        return match_list, paras

    def read_template_from_csv(self, template_filepath):
        template_dataframe = pd.read_csv(template_filepath)
        for idx, row in template_dataframe.iterrows():
            event_Id = row['EventId']
            event_template = row['EventTemplate']
            self.add_event_template(event_template, event_Id)


    def match(self, log_filepath, template_filepath):
        print('Processing log file: {}'.format(log_filepath))
        start_time = datetime.now()

# Path: logparser/utils/logloader.py
# class LogLoader(object):
#     def __init__(self, logformat, n_workers=1):
#     def load_to_dataframe(self, log_filepath):
#     def _generate_logformat_regex(self, logformat):
# def formalize_message(enumerated_lines, regex, headers):


# Path: logparser/logmatch/regexmatch.py
from ..utils import logloader
from collections import defaultdict, Counter, OrderedDict
from datetime import datetime
import re
import pandas as pd
import os
import multiprocessing as mp
import itertools
import hashlib
import numpy as np

    def match_event(self, event_list):
        match_list = []
        paras = []
        if self.n_workers == 1:
            results = match_fn(event_list, self.template_match_dict, self.optimized)
        else:
            pool = mp.Pool(processes=self.n_workers)
            chunk_size = len(event_list) / self.n_workers + 1
            result_chunks = [pool.apply_async(match_fn, args=(event_list[i:i + chunk_size], self.template_match_dict, self.optimized))\
                             for i in xrange(0, len(event_list), chunk_size)]
            pool.close()
            pool.join()
            results = list(itertools.chain(*[result.get() for result in result_chunks]))
        for event, parameter_list in results:
            self.template_freq_dict[event] += 1
            paras.append(parameter_list)
            match_list.append(event)
        return match_list, paras

    def read_template_from_csv(self, template_filepath):
        template_dataframe = pd.read_csv(template_filepath)
        for idx, row in template_dataframe.iterrows():
            event_Id = row['EventId']
            event_template = row['EventTemplate']
            self.add_event_template(event_template, event_Id)


    def match(self, log_filepath, template_filepath):
        print('Processing log file: {}'.format(log_filepath))
        start_time = datetime.now()

        loader = logloader.LogLoader(self.logformat, self.n_workers)
