<commit_before>#!/usr/bin/env python2
import os
import sys
import logging
import datetime
import json
import argparse
import socket
import tempfile
from collections import defaultdict
from results_analyze import BaseResultsAnalyzer
# disable InsecureRequestWarning
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

logger = logging.getLogger("microbenchmarking")
logger.setLevel(logging.DEBUG)

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)


class MicroBenchmarkingResultsAnalyzer(BaseResultsAnalyzer):
    def __init__(self, email_recipients, db_version=None):
        super(MicroBenchmarkingResultsAnalyzer, self).__init__(
            es_index="microbenchmarking",
            es_doc_type="microbenchmark",
            send_email=True,
            email_recipients=email_recipients,
            email_template_fp="results_microbenchmark.html",
            query_limit=10000,
            logger=logger
        )
        self.hostname = socket.gethostname()
        self._run_date_pattern = "%Y-%m-%d_%H:%M:%S"
        self.test_run_date = datetime.datetime.now().strftime(self._run_date_pattern)
        self.db_version = db_version

    def check_regression(self, current_results, html_report_path):
        filter_path = (
            "hits.hits._id",  # '2018-04-02_18:36:47_large-partition-skips_[64-32.1)'
            "hits.hits._source.test_args",  # [64-32.1)
            "hits.hits.test_group_properties.name",  # large-partition-skips
            "hits.hits._source.hostname",  # 'godzilla.cloudius-systems.com'
            "hits.hits._source.test_run_date",
            "hits.hits._source.test_group_properties.name",  # large-partition-skips
            "hits.hits._source.results.stats.aio",
            "hits.hits._source.results.stats.cpu",
            "hits.hits._source.results.stats.time (s)",
            "hits.hits._source.results.stats.frag/s",
            "hits.hits._source.versions",
            "hits.hits._source.excluded"
        )

        cur_version_info = current_results[current_results.keys()[0]]['versions']['scylla-server']
        self.db_version = cur_version_info["version"]
        tests_filtered = self._es.search(index=self._es_index, filter_path=filter_path, size=self._limit,
                                         q="hostname:'%s' \
                                            AND versions.scylla-server.version:%s* \
                                            AND ((-_exists_:excluded) OR (excluded:false))" % (self.hostname,
                                                                                               self.db_version[:3]))
        assert tests_filtered, "No results from DB"
        results = tests_filtered["hits"]["hits"]
        sorted_by_type = defaultdict(list)
        for res in results:
            test_type = "%s_%s" % (res["_source"]["test_group_properties"]["name"],
                                   res["_source"]["test_args"])
            sorted_by_type[test_type].append(res)

        report_results = defaultdict(dict)
        # report_results = {
        #     "large-partition-skips_1-0.1": {
        #           "aio":{
        #               "Current":
        #               "Last":
        #               "Diff last [%]":
        #               "Best":
        #               "Diff best [%]":
        #           },
        #           "frag/s":{
        #               "Current":
        #               "Stats": { submetrica: }<commit_msg>And start date for mbm results analyzing<commit_after>#!/usr/bin/env python2
import os
import sys
import logging
import datetime
import json
import argparse
import socket
import tempfile
from collections import defaultdict
from results_analyze import BaseResultsAnalyzer
# disable InsecureRequestWarning
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

logger = logging.getLogger("microbenchmarking")
logger.setLevel(logging.DEBUG)

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)


class MicroBenchmarkingResultsAnalyzer(BaseResultsAnalyzer):
    def __init__(self, email_recipients, db_version=None):
        super(MicroBenchmarkingResultsAnalyzer, self).__init__(
            es_index="microbenchmarking",
            es_doc_type="microbenchmark",
            send_email=True,
            email_recipients=email_recipients,
            email_template_fp="results_microbenchmark.html",
            query_limit=10000,
            logger=logger
        )
        self.hostname = socket.gethostname()
        self._run_date_pattern = "%Y-%m-%d_%H:%M:%S"
        self.test_run_date = datetime.datetime.now().strftime(self._run_date_pattern)
        self.db_version = db_version

    def check_regression(self, current_results, html_report_path):
        START_DATE = datetime.datetime.strptime("2019-01-01", "%Y-%m-%d")
        filter_path = (
            "hits.hits._id",  # '2018-04-02_18:36:47_large-partition-skips_[64-32.1)'
            "hits.hits._source.test_args",  # [64-32.1)
            "hits.hits.test_group_properties.name",  # large-partition-skips
            "hits.hits._source.hostname",  # 'godzilla.cloudius-systems.com'
            "hits.hits._source.test_run_date",
            "hits.hits._source.test_group_properties.name",  # large-partition-skips
            "hits.hits._source.results.stats.aio",
            "hits.hits._source.results.stats.cpu",
            "hits.hits._source.results.stats.time (s)",
            "hits.hits._source.results.stats.frag/s",
            "hits.hits._source.versions",
            "hits.hits._source.excluded"
        )

        cur_version_info = current_results[current_results.keys()[0]]['versions']['scylla-server']
        self.db_version = cur_version_info["version"]
        tests_filtered = self._es.search(index=self._es_index, filter_path=filter_path, size=self._limit,
                                         q="hostname:'%s' \
                                            AND versions.scylla-server.version:%s* \
                                            AND ((-_exists_:excluded) OR (excluded:false))" % (self.hostname,
                                                                                               self.db_version[:3]))
        assert tests_filtered, "No results from DB"

        results = []
        for doc in tests_filtered['hits']['hits']:
            doc_date = datetime.datetime.strptime(doc['_source']['versions']['scylla-server']['run_date_time'], "%Y-%m-%d %H:%M:%S")
            if doc_date > START_DATE:
                results.append(doc)

        sorted_by_type = defaultdict(list)
        for res in results:
            test_type = "%s_%s" % (res["_source"]["test_group_properties"]["name"],
                                   res["_source"]["test_args"])
            sorted_by_type[test_type].append(res)

        report_results = defaultdict(dict)
        # report_results = {
        #     "large-partition-skips_1-0.1": {
        #           "aio":{
        #               "Current":
        #               "Last":
        #               "Diff last [%]":
        #               "Best":
        #               "Diff best [%]":
        #           },
        #           "frag/s":{
        #               "Current":
        #               "Stats": { submetrica: }
{'fraction_non_alphanumeric': 0.12142763071249836, 'fraction_numerical': 0.011062821019359936, 'mean_word_length': 2.063331988705123, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7288172', 'n_tokens_mistral': 2292, 'n_tokens_neox': 2222, 'n_words': 304}