<commit_before>import optparse, random, re, time

from django.core.management import base
from django.contrib.webdesign import lorem_ipsum

from django_datastream import datastream

re_float = r'[-+]?[0-9]*\.?[0-9]+'
re_int = r'[-+]?\d+'
check_types = re.compile(r'^(int(\(%s,%s\))?|float(\(%s,%s\))?|enum(\((\w|,)+\))?|,)*$' % (re_int, re_int, re_float, re_float))
split_types = re.compile(r'(int|float|enum)(?:\(([^)]+)\))?')

class Command(base.BaseCommand):
    option_list = base.BaseCommand.option_list + (
        optparse.make_option('--metrics', '-m', action='store', type="int", dest='metrics',
            help="Number of dummy metrics to be created (default: 3)."),
        optparse.make_option('--interval', '-i', action='store', type="int", dest='interval', default=10,
            help="Interval between inserts of dummy datapoints (default: every 10 seconds)."),
        optparse.make_option('--types', '-t', action='store', type="string", dest='types',
            help="Metric types, comma-separated values of int, float, or enum (default: empty string). Range can be specified in brackets."),
        )
    help = "Regularly inserts dummy datapoints into metrics."

    def handle(self, *args, **options):
        verbose = int(options.get('verbosity'))
        interval = options.get('interval')
        nmetrics = options.get('metrics')
        types = options.get('types')

        if nmetrics is None and types is None:
            nmetrics = 3

        if types and check_types.match(types):
            types = split_types.findall(types)
            if nmetrics is not None and len(types) != nmetrics:
                raise base.CommandError('Number of metric types does not mach number of metrics.')

            nmetrics = len(types)

        elif types:
            raise base.CommandError('Invalid metric types string. Must be a comma separated list of <int|float|enum>[(start,end)|(enum values)].')

        metrics = []
        for i in range(nmetrics):
            downsamplers = datastream.backend.value_downsamplers if types is not None and types[i][0] != 'enum' else []
            metric_id = datastream.ensure_metric(({'name': 'metric_%d' % i},), ('foobar', {'metric_number': i}, {'description': lorem_ipsum.paragraph()}), downsamplers, datastream.Granularity.Seconds)
            metrics.append((metric_id, types[i] if types is not None else ('int', None)))<commit_msg>Changed metrics option to nmetrics (-m to -n).<commit_after>import optparse, random, re, time

from django.core.management import base
from django.contrib.webdesign import lorem_ipsum

from django_datastream import datastream

re_float = r'[-+]?[0-9]*\.?[0-9]+'
re_int = r'[-+]?\d+'
check_types = re.compile(r'^(int(\(%s,%s\))?|float(\(%s,%s\))?|enum(\((\w|,)+\))?|,)*$' % (re_int, re_int, re_float, re_float))
split_types = re.compile(r'(int|float|enum)(?:\(([^)]+)\))?')

class Command(base.BaseCommand):
    option_list = base.BaseCommand.option_list + (
        optparse.make_option('--metrics', '-n', action='store', type="int", dest='nmetrics',
            help="Number of dummy metrics to be created (default: 3)."),
        optparse.make_option('--interval', '-i', action='store', type="int", dest='interval', default=10,
            help="Interval between inserts of dummy datapoints (default: every 10 seconds)."),
        optparse.make_option('--types', '-t', action='store', type="string", dest='types',
            help="Metric types, comma-separated values of int, float, or enum (default: empty string). Range can be specified in brackets."),
        )
    help = "Regularly inserts dummy datapoints into metrics."

    def handle(self, *args, **options):
        verbose = int(options.get('verbosity'))
        interval = options.get('interval')
        nmetrics = options.get('nmetrics')
        types = options.get('types')

        if nmetrics is None and types is None:
            nmetrics = 3

        if types and check_types.match(types):
            types = split_types.findall(types)
            if nmetrics is not None and len(types) != nmetrics:
                raise base.CommandError('Number of metric types does not mach number of metrics.')

            nmetrics = len(types)

        elif types:
            raise base.CommandError('Invalid metric types string. Must be a comma separated list of <int|float|enum>[(start,end)|(enum values)].')

        metrics = []
        for i in range(nmetrics):
            downsamplers = datastream.backend.value_downsamplers if types is not None and types[i][0] != 'enum' else []
            metric_id = datastream.ensure_metric(({'name': 'metric_%d' % i},), ('foobar', {'metric_number': i}, {'description': lorem_ipsum.paragraph()}), downsamplers, datastream.Granularity.Seconds)
            metrics.append((metric_id, types[i] if types is not None else ('int', None)))
{'fraction_non_alphanumeric': 0.16023922458238812, 'fraction_numerical': 0.004537017941843679, 'mean_word_length': 3.3342269883824844, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4040367', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1439, 'n_words': 396}