<commit_before># -*- coding:utf-8 -*-
import random

from jpmynumber.exceptions import (JPMyNumberCheckDigitError,
                                   JPMyNumberLengthError)


class _ValidatorMixin(object):

    def validate_length(self):
        if not len(self._to_s) == self.LEN:
            raise JPMyNumberLengthError

    def validate_check_digit(self):
        if not self.true_check_digit == self.check_digit:
            raise JPMyNumberCheckDigitError

    def validate(self):
        self.validate_length()
        self.validate_check_digit()


class _CreateMixin(object):

    @classmethod
    def random_create(cls):
        temp = cls(
            random.randint(int('1' + '0' * (cls.LEN - 1)), int('9' * cls.LEN)),
            False)
        number_list = temp._user_number_to_a + [temp.true_check_digit]
        return cls(int(''.join([str(i) for i in number_list])))


class JPMyNumber(_CreateMixin, _ValidatorMixin):

    LEN = 12

    def __init__(self, number, validation=True):
        self.number = int(number)
        if validation:
            self.validate()

    def __repr__(self):
        return '<{module}.{_class}({number})>'.format(
            module=self.__module__,
            _class=self.__class__.__name__,
            number=self.number)

    @property
    def check_digit(self):
        return self._to_a[-1]

    @property
    def true_check_digit(self):
        user_number_len = len(self._user_number_to_a)
        temp = sum([self._f(n) for n in range(1, self.LEN)]) % user_number_len
        if temp <= 1:
            return 0
        return user_number_len - temp

    @property
    def _to_a(self):
        return [int(s) for s in self._to_s]

    @property
    def _to_s(self):
        return str(self.number)

    @property
    def _user_number_to_a(self):
        return self._to_a[0: -1]

    def _p(self, n):
        return self._user_number_to_a[-n]

    def _q(self, n):
        if 1 <= n <= (self.LEN / 2):
            return n + 1
        if (self.LEN / 2) < n <= len(self._user_number_to_a):
            return n - 5
        raise

    def _f(self, n):
        return self._p(n) * self._q(n)<commit_msg>Update writing style<commit_after># -*- coding:utf-8 -*-
import random

from jpmynumber.exceptions import (JPMyNumberCheckDigitError,
                                   JPMyNumberLengthError)


def _assert_n(func):
    def validate(self, n):
        assert 1 <= n < self.LEN
        return func(self, n)
    return validate


class _ValidatorMixin(object):

    def validate_length(self):
        if not len(self._to_s) == self.LEN:
            raise JPMyNumberLengthError

    def validate_check_digit(self):
        if not self.true_check_digit == self.check_digit:
            raise JPMyNumberCheckDigitError

    def validate(self):
        self.validate_length()
        self.validate_check_digit()


class _CreateMixin(object):

    @classmethod
    def random_create(cls):
        temp = cls(
            random.randint(int('1' + '0' * (cls.LEN - 1)), int('9' * cls.LEN)),
            False)
        number_list = temp._user_number_to_a + [temp.true_check_digit]
        return cls(int(''.join([str(i) for i in number_list])))


class JPMyNumber(_CreateMixin, _ValidatorMixin):

    LEN = 12

    def __init__(self, number, validation=True):
        self.number = int(number)
        if validation:
            self.validate()

    def __repr__(self):
        return '<{module}.{_class}({number})>'.format(
            module=self.__module__,
            _class=self.__class__.__name__,
            number=self.number)

    @property
    def check_digit(self):
        return self._to_a[-1]

    @property
    def true_check_digit(self):
        user_number_len = len(self._user_number_to_a)
        remainder = sum([self._f(n)
                         for n in range(1, self.LEN)]) % user_number_len
        if remainder <= 1:
            return 0
        return user_number_len - remainder

    @property
    def _to_a(self):
        return [int(s) for s in self._to_s]

    @property
    def _to_s(self):
        return str(self.number)

    @property
    def _user_number_to_a(self):
        return self._to_a[0: -1]

    @_assert_n
    def _p(self, n):
        return self._user_number_to_a[-n]

    @_assert_n
    def _q(self, n):
        return n + 1 if n <= (self.LEN / 2) else n - 5

    @_assert_n
    def _f(self, n):
        return self._p(n) * self._q(n)
{'fraction_non_alphanumeric': 0.11259025270758123, 'fraction_numerical': 0.0078971119133574, 'mean_word_length': 2.1755014326647566, 'pattern_counts': {'":': 0, '<': 14, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1024205', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1420, 'n_words': 315}