<commit_before>from .models import R


_r = R()


def metric(slug, num=1, **kwargs):
    """Create/Increment a metric."""
    _r.metric(slug, num)


def gague(slug, current_value):
    """Set a value for a Guage"""
    _r.gague(slug, current_value)


def generate_test_metrics(slug='test-metric', num=100):
    """Generate some dummy (but increasing) metrics for the given ``slug`` and
    the past ``num`` days."""
    import datetime
    today = datetime.date.today()
    dates = (today - datetime.timedelta(days=d) for d in range(num))

    i = 1
    for date in dates:
        for key in _r._build_keys(slug, date=date):
            # The following is normally done in _r.metric, but we're adding
            # "old" metrics here, so this is duplicate code.
            _r.r.sadd(_r._metric_slugs_key, key)  # keep track of the keys
            for x in range(i):
                _r.r.incr(key)  # incr the key an increasing number of times
        i += 1<commit_msg>added a delete_test_metrics util function<commit_after>import datetime
from .models import R


_r = R()


def metric(slug, num=1, **kwargs):
    """Create/Increment a metric."""
    _r.metric(slug, num)


def gague(slug, current_value):
    """Set a value for a Guage"""
    _r.gague(slug, current_value)


def _dates(num):
    today = datetime.date.today()
    return (today - datetime.timedelta(days=d) for d in range(num))


def generate_test_metrics(slug='test-metric', num=100):
    """Generate some dummy (but increasing) metrics for the given ``slug`` and
    the past ``num`` days."""
    i = 1
    for date in _dates(num):
        for key in _r._build_keys(slug, date=date):
            # The following is normally done in _r.metric, but we're adding
            # "old" metrics here, so this is duplicate code.
            _r.r.sadd(_r._metric_slugs_key, key)  # keep track of the keys
            for x in range(i):
                _r.r.incr(key)  # incr the key an increasing number of times
        i += 1


def delete_test_metrics(slug='test-metric', num=100):
    """Deletes the metrics created by ``generate_test_metrics``."""
    for date in _dates(num):
        keys = _r._build_keys(slug, date=date)
        _r.r.srem(_r._metric_slugs_key, *keys)  # remove metric slugs
        _r.r.delete(*keys)  # delete the metrics
{'fraction_non_alphanumeric': 0.12088388214904679, 'fraction_numerical': 0.006499133448873483, 'mean_word_length': 2.766721044045677, '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': '5966131', 'n_tokens_mistral': 763, 'n_tokens_neox': 748, 'n_words': 242}