<commit_before>import json

from django.core.management.base import BaseCommand, CommandError
from promgen import models


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('target_file')

    def handle(self, target_file, **kwargs):
        config = json.load(open(target_file))
        for entry in config:
            service, _ = models.Service.objects.get_or_create(
                name=entry['labels']['service'],
            )

            project, _ = models.Project.objects.get_or_create(
                name=entry['labels']['project'],
                defaults={'service': service}
            )

            farm, _ = models.Farm.objects.get_or_create(
                name=entry['labels']['farm'],
                defaults={'source': 'DB'}
            )

            project.farm = farm
            project.save()

            for target in entry['targets']:
                host, _ = models.Host.objects.get_or_create(
                    name=target,
                    defaults={'farm': farm}
                )
<commit_msg>Fix hosts and import exporters<commit_after>import json

from django.core.management.base import BaseCommand, CommandError
from promgen import models


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('target_file')

    def handle(self, target_file, **kwargs):
        config = json.load(open(target_file))
        for entry in config:
            service, _ = models.Service.objects.get_or_create(
                name=entry['labels']['service'],
            )

            farm, _ = models.Farm.objects.get_or_create(
                name=entry['labels']['farm'],
                defaults={'source': 'DB'}
            )

            project, _ = models.Project.objects.get_or_create(
                name=entry['labels']['project'],
                service=service,
                farm=farm,
            )

            for target in entry['targets']:
                target, port = target.split(':')
                host, _ = models.Host.objects.get_or_create(
                    name=target,
                    defaults={'farm': farm}
                )

            exporter = models.Exporter.objects.get_or_create(
                job=entry['labels']['job'],
                port=port,
                project=project,
            )

{'fraction_non_alphanumeric': 0.11270578303081469, 'fraction_numerical': 0.0, 'mean_word_length': 1.7430555555555556, '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': '7643722', 'n_tokens_mistral': 632, 'n_tokens_neox': 601, 'n_words': 113}