<commit_before>import os
import json

from oct.results.models import Result, Turret, set_database, db


def init_stats(output_dir, config):
    """Init all required ressources for stats handling

    :param str output_dir: the output directory for the results
    :param dict config: the project configuration
    """

    try:
        os.makedirs(output_dir, 0o755)
    except OSError:
        print("ERROR: Can not create output directory\n")
        raise

    set_database(output_dir + "results.sqlite", db, config)
    db.connect()
    db.create_tables([Result, Turret])


class StatsHandler(object):
    """This class will handle results and stats comming from the turrets

    :param str output_dir: the output directory for the results
    """
    def __init__(self, output_dir, config):
        self.output_dir = output_dir
        self.trans_count = 0
        self.timer_count = 0
        self.error_count = 0
        self.turret_name = 'Turret'
        self.results = []

    def write_result(self, data):
        """Write the results received to the database

        :param dict data: the data to save in database
        :return: None
        """
        print(data)
        self.trans_count += 1
        self.timer_count += len(data['custom_timers'])
        if data['error']:
            self.error_count += 1

        data['custom_timers'] = json.dumps(data['custom_timers'])
        self.results.append(data)

        if len(self.results) >= 450:  # SQLite limit for inser_many is 500
            with db.execution_context():
                with db.atomic():
                    Result.insert_many(self.results).execute()
                del self.results[:]

    def write_remaining(self):
        """Write the remaning stack content
        """
        with db.atomic():
            Result.insert_many(self.results).execute()
        del self.results[:]<commit_msg>remove print statement<commit_after>import os
import json

from oct.results.models import Result, Turret, set_database, db


def init_stats(output_dir, config):
    """Init all required ressources for stats handling

    :param str output_dir: the output directory for the results
    :param dict config: the project configuration
    """

    try:
        os.makedirs(output_dir, 0o755)
    except OSError:
        print("ERROR: Can not create output directory\n")
        raise

    set_database(output_dir + "results.sqlite", db, config)
    db.connect()
    db.create_tables([Result, Turret])


class StatsHandler(object):
    """This class will handle results and stats comming from the turrets

    :param str output_dir: the output directory for the results
    """
    def __init__(self, output_dir, config):
        self.output_dir = output_dir
        self.trans_count = 0
        self.timer_count = 0
        self.error_count = 0
        self.turret_name = 'Turret'
        self.results = []

    def write_result(self, data):
        """Write the results received to the database

        :param dict data: the data to save in database
        :return: None
        """
        self.trans_count += 1
        self.timer_count += len(data['custom_timers'])
        if data['error']:
            self.error_count += 1

        data['custom_timers'] = json.dumps(data['custom_timers'])
        self.results.append(data)

        if len(self.results) >= 450:  # SQLite limit for inser_many is 500
            with db.execution_context():
                with db.atomic():
                    Result.insert_many(self.results).execute()
                del self.results[:]

    def write_remaining(self):
        """Write the remaning stack content
        """
        with db.atomic():
            Result.insert_many(self.results).execute()
        del self.results[:]
{'fraction_non_alphanumeric': 0.09789837722798617, 'fraction_numerical': 0.007980845969672785, 'mean_word_length': 2.399638336347197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4711601', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1031, 'n_words': 306}