<commit_before>"""MetricSource that serves dummy data."""

import random
from vumidash.base import MetricSource, UnknownMetricError


class DummyClient(MetricSource):
    """Serve dummy data."""

    def __init__(self):
        self.latest = None
        self.metric_prefix = "test"
        self.prev_values = {}  # map of metrics to previous values

    def new_value(self, metric):
        values = self.prev_values.setdefault(metric, [])
        values.insert(0, random.uniform(0, 100))
        return values

    def get_latest(self, metric, start, end, summary_size, skip_nulls=True):
        values = self.get_history(metric, start, end, summary_size, skip_nulls)
        return values[0], values[-1]

    def get_history(self, metric, start, end, summary_size, skip_nulls=True):
        if not metric.startswith(self.metric_prefix):
            raise UnknownMetricError("Uknown metric %r" % (metric,))
        steps = (self.total_seconds((-start) - (-end))
                 / float(self.total_seconds(summary_size)))
        values = self.new_value(metric)
        while len(values) < steps:
            values = self.new_value(metric)
        return values[:steps]<commit_msg>Fix steps calculation in dummy client -- how did this work before?<commit_after>"""MetricSource that serves dummy data."""

import random
from vumidash.base import MetricSource, UnknownMetricError


class DummyClient(MetricSource):
    """Serve dummy data."""

    def __init__(self):
        self.latest = None
        self.metric_prefix = "test"
        self.prev_values = {}  # map of metrics to previous values

    def new_value(self, metric):
        values = self.prev_values.setdefault(metric, [])
        values.insert(0, random.uniform(0, 100))
        return values

    def get_latest(self, metric, start, end, summary_size, skip_nulls=True):
        values = self.get_history(metric, start, end, summary_size, skip_nulls)
        return values[0], values[-1]

    def get_history(self, metric, start, end, summary_size, skip_nulls=True):
        if not metric.startswith(self.metric_prefix):
            raise UnknownMetricError("Uknown metric %r" % (metric,))
        steps = int(self.total_seconds((-start) - (-end))
                    / float(self.total_seconds(summary_size)))
        values = self.new_value(metric)
        while len(values) < steps:
            values = self.new_value(metric)
        return values[:steps]
{'fraction_non_alphanumeric': 0.11330861145447053, 'fraction_numerical': 0.0057684384013185, 'mean_word_length': 3.0265339966832503, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3274946', 'n_tokens_mistral': 716, 'n_tokens_neox': 694, 'n_words': 177}