<commit_before>'''
A trivial stats system for CoCrawler
'''

import logging
import pickle
import time
from contextlib import contextmanager

from hdrh.histogram import HdrHistogram
from sortedcollections import ValueSortedDict

from .urls import URL
from . import config

LOGGER = logging.getLogger(__name__)

start_time = time.time()
start_cpu = time.clock()
maxes = {}
sums = {}
sets = {}
burners = {}
latencies = {}
coroutine_states = {}
exitstatus = 0


def stats_max(name, value):
    maxes[name] = max(maxes.get(name, value), value)


def stats_sum(name, value):
    sums[name] = sums.get(name, 0) + value
    return sums[name]


def stats_set(name, value):
    sets[name] = value


def record_a_burn(name, start, url=None):
    if isinstance(url, URL):
        url = url.url
    elapsed = time.clock() - start
    burn = burners.get(name, {})
    burn['count'] = burn.get('count', 0) + 1
    burn['time'] = burn.get('time', 0.0) + elapsed<commit_msg>implement me<commit_after>'''
A trivial stats system for CoCrawler
'''

import logging
import pickle
import time
from contextlib import contextmanager

from hdrh.histogram import HdrHistogram
from sortedcollections import ValueSortedDict

from .urls import URL
from . import config

LOGGER = logging.getLogger(__name__)

start_time = time.time()
start_cpu = time.clock()
maxes = {}
sums = {}
sets = {}
burners = {}
latencies = {}
coroutine_states = {}
exitstatus = 0


def stats_max(name, value):
    maxes[name] = max(maxes.get(name, value), value)


def stats_sum(name, value, url=None):
    sums[name] = sums.get(name, 0) + value

    if url is not None:
        # remember these urls per-host
        # sum these sums per-host
        pass

    return sums[name]


def stats_set(name, value):
    sets[name] = value


def record_a_burn(name, start, url=None):
    if isinstance(url, URL):
        url = url.url
    elapsed = time.clock() - start
    burn = burners.get(name, {})
    burn['count'] = burn.get('count', 0) + 1
    burn['time'] = burn.get('time', 0.0) + elapsed
{'fraction_non_alphanumeric': 0.12825552825552824, 'fraction_numerical': 0.005896805896805897, 'mean_word_length': 3.7020785219399537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1411410', 'n_tokens_mistral': 705, 'n_tokens_neox': 686, 'n_words': 193}