<commit_before>from datetime import date, timedelta

CONTRACT_STATES = [
    'draft',
    'validate',
    'pending',
    'active',
    'contract',
    'new_contract',
    'modcontract',
    'unpayed',
    'off',
    'down'
]


class Contract(object):
    """Contract object.
    """
    def __init__(self):
        self.code = None
        self.state = 'draft'
        self.modifications = []
        self.contracted_power = 0

    def modify(self, modcontract, overwrite=False):
        assert isinstance(modcontract, Modification)
        if overwrite:
            self.modifications[-1] = modcontract
        else:
            if self.modifications:
                old_mod = self.modifications[-1]
                assert modcontract.start_date > old_mod.start_date
                old_mod.end_date = modcontract.start_date - timedelta(days=1)
                old_mod.next = modcontract
                modcontract.previous = old_mod
                old_mod.state = 'down'
            self.modifications.append(modcontract)
        self.contracted_power = modcontract.contracted_power

    def get_intervals(self, start_date, end_date, changes=None):
        mods = []
        for m in self.modifications:
            if m.start_date <= start_date and (
                m.end_date is None or m.end_date >= end_date):
                mods.append(m)
            elif m.start_date >= start_date and m.start_date <= end_date:
                mods.append(m)
        return mods

    def get_changes(self, modification):
        changes = {}
        local_vals = vars(self)
        mod_vals = vars(modification)
        for attr, value in mod_vals.iteritems():
            if attr in local_vals:
                if value != local_vals[attr]:
                    changes[attr] = {'old': local_vals[attr], 'new': value}
        return changes


class Modification(Contract):
    def __init__(self, start_date=None):
        if start_date is None:
            start_date = date.today()
        self.start_date = start_date
        self.end_date = None
        self.previous = None
        self.next = None
        self.contracted_power = 0
        self.state = 'draft'<commit_msg>Change inheritance of Modification to object<commit_after>from datetime import date, timedelta

CONTRACT_STATES = [
    'draft',
    'validate',
    'pending',
    'active',
    'contract',
    'new_contract',
    'modcontract',
    'unpayed',
    'off',
    'down'
]


class Contract(object):
    """Contract object.
    """
    def __init__(self):
        self.code = None
        self.state = 'draft'
        self.modifications = []
        self.contracted_power = 0

    def modify(self, modcontract, overwrite=False):
        assert isinstance(modcontract, Modification)
        if overwrite:
            self.modifications[-1] = modcontract
        else:
            if self.modifications:
                old_mod = self.modifications[-1]
                assert modcontract.start_date > old_mod.start_date
                old_mod.end_date = modcontract.start_date - timedelta(days=1)
                old_mod.next = modcontract
                modcontract.previous = old_mod
                old_mod.state = 'down'
            self.modifications.append(modcontract)
        self.contracted_power = modcontract.contracted_power

    def get_intervals(self, start_date, end_date, changes=None):
        mods = []
        for m in self.modifications:
            if m.start_date <= start_date and (
                m.end_date is None or m.end_date >= end_date):
                mods.append(m)
            elif m.start_date >= start_date and m.start_date <= end_date:
                mods.append(m)
        return mods

    def get_changes(self, modification):
        changes = {}
        local_vals = vars(self)
        mod_vals = vars(modification)
        for attr, value in mod_vals.iteritems():
            if attr in local_vals:
                if value != local_vals[attr]:
                    changes[attr] = {'old': local_vals[attr], 'new': value}
        return changes



class Modification(object):
    def __init__(self, start_date=None):
        if start_date is None:
            start_date = date.today()
        self.start_date = start_date
        self.end_date = None
        self.previous = None
        self.next = None
        self.contracted_power = 0
        self.state = 'draft'
{'fraction_non_alphanumeric': 0.09547738693467336, 'fraction_numerical': 0.0022841480127912287, 'mean_word_length': 1.9488215488215488, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6934893', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1234, 'n_words': 284}