def test_status_count_up(self):

        f = open('/Users/len/log-analyer-assignment/tests/fixtures/text.txt',
                 'r',
                 encoding="utf-8")
        f2 = open(
            '/Users/len/log-analyer-assignment/tests/fixtures/output.txt',
            'w',
            encoding="utf-8")

        lines = f.readlines()
        file_lists = []
        for row in lines:
            row_list = custom_log_parser(row)
            # data
            input_date = datetime.datetime.strptime(
                row_list[constants.INDEX_OF_DATETIME_IN_LOG()],
                '%d/%b/%Y:%H:%M:%S %z')
            row_list[4] = input_date
            file_lists.append(row_list)

        result = {}

        for single_data in file_lists:
            http_status = single_data[constants.INDEX_OF_STATUS_NUMBER()]
            if http_status in result:
                result[http_status] = result[http_status] + 1
            else:
                result[http_status] = 1

        for single_data in result:
            print("STATUS CODE {}: COUNT {}".format(single_data,
                                                    result[single_data]))

        self.assertEqual([], [])
Пример #2
0
    def print_datetime(self, original_dates: list, start_time: str,
                       end_time: str) -> List:
        sorted_list = self.datetime_sort(original_dates)

        result_datetime = []
        for single_list in sorted_list:
            data_date_time = single_list[constants.INDEX_OF_DATETIME_IN_LOG()]
            if start_time <= data_date_time <= end_time:
                result_datetime.append(single_list)
        return result_datetime
Пример #3
0
    def datetime_sort(self, original_dates: list) -> List:
        file_lists = []
        for row in original_dates:
            row_list = LogParserHelper.raw_log_parser(row)
            row_list = self.cv_line_str_to_datetime(row_list)
            file_lists.append(row_list)

        file_lists.sort(key=lambda single_list: single_list[
            constants.INDEX_OF_DATETIME_IN_LOG()])
        return file_lists
Пример #4
0
    def run(self):
        lines = csv.reader(open(file=self.file_path,
                                newline='',
                                encoding='utf-8'),
                           delimiter='|')
        function_02 = Function02Impl()
        result = {}
        for line in tqdm(lines):
            rest_api = line[constants.INDEX_OF_REST_API()]
            input_date = datetime.datetime.strptime(
                line[constants.INDEX_OF_DATETIME_IN_LOG()],
                '%d/%b/%Y:%H:%M:%S %z')
            if self.start_time <= input_date <= self.end_time:
                if function_02.is_satisfied_http_method(line, self.method) is True and \
                        function_02.is_satisfied_http_status(line, self.code) is True and \
                        function_02.remove_if_not_static_resource(line):
                    result = function_02.collect_all_satisfied_request_api(
                        line)

                self._result = result
Пример #5
0
    def run(self):

        entries_datetime_zone = []
        for i in range(1, len(self.times)):
            start_datetime = TimeControlHelper.cv_str_to_datetime(
                self.times[i - 1])
            end_datetime = TimeControlHelper.cv_str_to_datetime(self.times[i])

            datetime_zone = [start_datetime, end_datetime]
            entries_datetime_zone.append(datetime_zone)

        with open(file=self.file_path, newline='', encoding='utf8') as lines:
            lines = csv.reader(lines, delimiter='|')
            # 시간대별로 Request 정보에서 Client-Agent 정보를 추출하여 어떤 브라우저(디바이스)에서 접속 했는지 추출함

            total_result = {}
            for line in tqdm(lines):
                if len(line) == 14:
                    user_time = line[constants.INDEX_OF_DATETIME_IN_LOG()]
                    input_date = datetime.datetime.strptime(
                        user_time, '%d/%b/%Y:%H:%M:%S %z')

                    for start_time_zone, end_time_zone in entries_datetime_zone:
                        if start_time_zone <= input_date <= end_time_zone:
                            user_agent = UserAgentHelper.detect_user_agent(
                                line[constants.INDEX_OF_USER_AGENT()])
                            if start_time_zone in total_result.keys():
                                dict_user_agents = total_result[
                                    start_time_zone]
                                if user_agent in dict_user_agents.keys():
                                    dict_user_agents[
                                        user_agent] = dict_user_agents[
                                            user_agent] + 1
                                else:
                                    dict_user_agents[user_agent] = 1
                                total_result[start_time_zone].update(
                                    dict_user_agents)
                            else:
                                total_result[start_time_zone] = {}

            self._result = total_result
Пример #6
0
    def count_http_status_code(self, files_path: List,
                               range_times_list: List) -> Dict:

        entries_datetime_zone = []
        for i in range(1, len(range_times_list)):
            start_datetime = TimeControlHelper.cv_str_to_datetime(
                range_times_list[i - 1])
            end_datetime = TimeControlHelper.cv_str_to_datetime(
                range_times_list[i])

            datetime_zone = [start_datetime, end_datetime]
            entries_datetime_zone.append(datetime_zone)

        total_result = {}
        for file_path in files_path:
            with open(file_path, 'r', encoding='utf8') as lines:
                for line in lines:
                    cv_line = LogParserHelper.csv_log_parser(line)
                    if len(cv_line) == 14:
                        http_status = cv_line[
                            constants.INDEX_OF_STATUS_NUMBER()]
                        dt_date = cv_line[constants.INDEX_OF_DATETIME_IN_LOG()]
                        dt_date = TimeControlHelper.cv_str_to_datetime(dt_date)
                        for start_datetime, end_datetime in entries_datetime_zone:
                            if start_datetime <= dt_date < end_datetime:
                                if start_datetime in total_result.keys():
                                    status_dates = total_result[start_datetime]
                                    # {status : key, count : value}
                                    if http_status in status_dates.keys():
                                        status_dates[
                                            http_status] = status_dates[
                                                http_status] + 1
                                    else:
                                        status_dates[http_status] = 1
                                    total_result[start_datetime].update(
                                        status_dates)
                                else:
                                    total_result[start_datetime] = {}
        return total_result
Пример #7
0
    def run(self):
        lines = csv.reader(open(file=self.file_path,
                                newline='',
                                encoding='utf-8'),
                           delimiter='|')

        MIN = 0.0
        for line in tqdm(lines):
            input_date = datetime.datetime.strptime(
                line[constants.INDEX_OF_DATETIME_IN_LOG()],
                '%d/%b/%Y:%H:%M:%S %z')
            if self.start_time <= input_date <= self.end_time:
                response_time = line[constants.INDEX_OF_RESPONSE_TIME()]
                if response_time is not '-':
                    response_time = float(response_time)

                    if self.late_time_by_user is not None:
                        if response_time > MIN:
                            self._result.append([response_time, line])

                    elif response_time > MIN:
                        MIN = response_time
                        result_log_line = line
                        self._result = [MIN, result_log_line]
Пример #8
0
    def run(self):
        lines = csv.reader(open(file=self.file_path,
                                newline='',
                                encoding='utf-8'),
                           delimiter='|')
        function_04 = Function04Impl()
        result = {}
        for line in tqdm(lines):
            input_date = datetime.datetime.strptime(
                line[constants.INDEX_OF_DATETIME_IN_LOG()],
                '%d/%b/%Y:%H:%M:%S %z')
            if self.start_time <= input_date <= self.end_time:
                if function_04.remove_if_not_static_resource(
                        line[constants.INDEX_OF_REST_API()]):
                    continue
                else:
                    rest_api = line[constants.INDEX_OF_REST_API()]

                    if rest_api in result:
                        result[rest_api] = result[rest_api] + 1
                    else:
                        result[rest_api] = 1

                self._result = result
Пример #9
0
 def cv_line_str_to_datetime(row_list) -> datetime:
     input_date = datetime.datetime.strptime(
         row_list[constants.INDEX_OF_DATETIME_IN_LOG()],
         '%d/%b/%Y:%H:%M:%S %z')
     row_list[constants.INDEX_OF_DATETIME_IN_LOG()] = input_date
     return row_list