<commit_before>from shadho.backend.base.model import BaseModel
from shadho.backend.json.domain import Domain
from shadho.backend.json.result import Result

import uuid


class Model(BaseModel):
    def __init__(self, id=None, priority=None, complexity=None, rank=None,
                 domains=None, results=None):
        self.id = id if id is not None else str(uuid.uuid4())
        self.priority = [priority] if isinstance(priority, (int, float)) \
                        else priority
        self.complexity = complexity
        self.rank = rank
        self.domains = []
        self.results = []
        map(self.add_domain, domains if domains is not None else [])
        map(self.add_result, results if results is not None else [])

    def add_domain(self, domain):
        if isinstance(domain, Domain):
            self.domains.append(domain.id)
        elif isinstance(domain, (int, str)):
            self.domains.append(domain)

    def add_result(self, result):
        if isinstance(result, Result):
            self.results.append(result.id)
        elif isinstance(result, (int, str)):
            self.results.append(result)

    def to_json(self):
        return {
            'priority': self.priority,
            'complexity': self.complexity,
            'rank': self.rank,
            'domains': self.spaces,
            'results': self.results,
        }
<commit_msg>fix broken add_domain() and add_result() during initialization<commit_after>from shadho.backend.base.model import BaseModel
from shadho.backend.json.domain import Domain
from shadho.backend.json.result import Result
from shadho.backend.utils import InvalidObjectError

import uuid


class Model(BaseModel):
    def __init__(self, id=None, priority=None, complexity=None, rank=None,
                 domains=None, results=None):
        self.id = id if id is not None else str(uuid.uuid4())
        self.priority = [priority] if isinstance(priority, (int, float)) \
                        else priority
        self.complexity = complexity
        self.rank = rank
        self.domains = []
        self.results = []

        domains = [domains] if not isinstance(domains, list) else domains
        results = [results] if not isinstance(results, list) else results
        for domain in domains:
            self.add_domain(domain)
        for result in results:
            self.add_result(result)

    def add_domain(self, domain):
        if domain is not None:
            if isinstance(domain, Domain):
                self.domains.append(domain.id)
            elif isinstance(domain, (int, str)):
                self.domains.append(domain)
            else:
                raise InvalidObjectError(domain)

    def add_result(self, result):
        if result is not None:
            if isinstance(result, Result):
                self.results.append(result.id)
            elif isinstance(result, (int, str)):
                self.results.append(result)
            else:
                raise InvalidObjectError(result)

    def to_json(self):
        return {
            'priority': self.priority,
            'complexity': self.complexity,
            'rank': self.rank,
            'domains': self.domains,
            'results': self.results,
        }

{'fraction_non_alphanumeric': 0.09862174578866768, 'fraction_numerical': 0.0006125574272588055, 'mean_word_length': 2.128352490421456, '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': '215780', 'n_tokens_mistral': 883, 'n_tokens_neox': 855, 'n_words': 236}