<commit_before># -*- coding: utf-8 -*-
# © 2014-2015 <NAME>/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from collections import defaultdict, OrderedDict
import datetime
import dateutil
import logging
import re
import time
import traceback

import pytz

from openerp import api, exceptions, fields, models, _
from openerp.tools.safe_eval import safe_eval

from .aep import AccountingExpressionProcessor as AEP
from .aggregate import _sum, _avg, _min, _max
from .accounting_none import AccountingNone
from openerp.exceptions import UserError
from .simple_array import SimpleArray

_logger = logging.getLogger(__name__)


class DataError(Exception):

    def __init__(self, name, msg):
        self.name = name
        self.msg = msg


class AutoStruct(object):

    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)


class KpiMatrix(object):
    """ This object holds the computation results in a way
    that can be browsed easily for rendering """

    def __init__(self, env):
        self.env = env
        # { period: {kpi: vals}
        self._kpi_vals = defaultdict(dict)
        # { period: {kpi: {account_id: vals}}}
        self._kpi_exploded_vals = defaultdict(dict)
        # { period: localdict }
        self._localdict = {}
        # { kpi: set(account_ids) }
        self._kpis = OrderedDict()
        # { account_id: account name }
        self._account_names_by_id = {}

    def _get_row_id(self, kpi, account_id=None):
        r = kpi.name
        if account_id:
            r += ':' + str(account_id)
        return r

    def declare_kpi(self, kpi):
        raise RuntimeError("not implemented")

    def declare_period(self, period_key, localdict, subkpis,
                       description, comment):
        raise RuntimeError("not implemented")

    def set_values(self, kpi, period_key, vals):
        raise RuntimeError("not implemented")

    def set_values_detail_account(self, kpi, period_key, account_id, vals):
        raise RuntimeError("not implemented")

    def add_comparison(self, period_key_1, period_key_2,
                       description, comment,
                       after_period_key):
        raise RuntimeError("not implemented")

    def iter_row_headers(self):
        """ Iterate rows headers, top down

        yields row_id, parent_row_id=None, row_description, row_comment, kpi
        """
        raise RuntimeError("not implemented")

    def iter_col_headers(self):
        """ Iterate column headers, left to right

        yields col_id, col_description, col_comment, col_span, period_key
        """
        raise RuntimeError("not implemented")

    def iter_subcol_headers(self):
        """ Iterate sub columns headers, left to right

        yields subcol_id, col_id, subcol_description, subcol_comment
        """
        raise RuntimeError("not implemented")

    def iter_row_values(self):
        """ Iterate row values, left to right

        yields row_id, col_id, val, val_rendered, val_comment, \
            subkpi, period_key
        """
        raise RuntimeError("not implemented")

    ####

    def set_kpi_vals(self, period, kpi, vals):
        """ Set the values for a kpi in a period

        vals is a list of sub-kpi values.
        """
        self._kpi_vals[period][kpi] = vals
        if kpi not in self._kpis:
            self._kpis[kpi] = set()

    def set_kpi_exploded_vals(self, period, kpi, account_id, vals):
        """ Set the detail values for a kpi in a period for a GL account

        This is used by the automatic details mechanism.

        vals is a list of sub-kpi values.
        """
        exploded_vals = self._kpi_exploded_vals[period]
        if kpi not in exploded_vals:
            exploded_vals[kpi] = {}<commit_msg>[WIP] mis_builder: refactoring<commit_after># -*- coding: utf-8 -*-
# © 2014-2015 <NAME> (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from collections import defaultdict, OrderedDict
import datetime
import dateutil
import logging
import re
import time
import traceback

import pytz

from openerp import api, exceptions, fields, models, _
from openerp.tools.safe_eval import safe_eval

from .aep import AccountingExpressionProcessor as AEP
from .aggregate import _sum, _avg, _min, _max
from .accounting_none import AccountingNone
from openerp.exceptions import UserError
from .simple_array import SimpleArray

_logger = logging.getLogger(__name__)


class DataError(Exception):

    def __init__(self, name, msg):
        self.name = name
        self.msg = msg


class AutoStruct(object):

    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)


class KpiMatrix(object):
    """ This object holds the computation results in a way
    that can be browsed easily for rendering """

    def __init__(self, env):
        self.env = env
        # { period: {kpi: vals}
        self._kpi_vals = defaultdict(dict)
        # { period: {kpi: {account_id: vals}}}
        self._kpi_exploded_vals = defaultdict(dict)
        # { period: localdict }
        self._localdict = {}
        # { kpi: set(account_ids) }
        self._kpis = OrderedDict()
        # { account_id: account name }
        self._account_names_by_id = {}

    def _get_row_id(self, kpi, account_id=None):
        r = kpi.name
        if account_id:
            r += ':' + str(account_id)
        return r

    def declare_kpi(self, kpi):
        raise RuntimeError("not implemented")

    def declare_period(self, period_key, localdict, subkpis,
                       description, comment):
        raise RuntimeError("not implemented")

    def set_values(self, kpi, period_key, vals):
        raise RuntimeError("not implemented")

    def set_values_detail_account(self, kpi, period_key, account_id, vals):
        raise RuntimeError("not implemented")

    def add_comparison(self, period_key_1, period_key_2,
                       description, comment,
                       after_period_key):
        raise RuntimeError("not implemented")

    def iter_row_headers(self):
        """ Iterate rows headers, top down

        yields row_id, parent_row_id=None, row_description, row_comment, \
            row_style, kpi
        """
        raise RuntimeError("not implemented")

    def iter_col_headers(self):
        """ Iterate column headers, left to right

        yields col_id, col_description, col_comment, col_span, period_key
        """
        raise RuntimeError("not implemented")

    def iter_subcol_headers(self):
        """ Iterate sub columns headers, left to right

        yields subcol_id, col_id, subcol_description, subcol_comment
        """
        raise RuntimeError("not implemented")

    def iter_row_values(self):
        """ Iterate row values, left to right

        yields row_id, col_id, val, val_rendered, val_comment,
            val_style, subkpi, period_key
        """
        raise RuntimeError("not implemented")

    def iter_kpi_values(self, period_key):
        """
        yields kpi, kpi_values
        """
        raise RuntimeError("not implemented")

    # TODO FIXME old methods to be removed

    def set_kpi_vals(self, period, kpi, vals):
        """ Set the values for a kpi in a period

        vals is a list of sub-kpi values.
        """
        self._kpi_vals[period][kpi] = vals
        if kpi not in self._kpis:
            self._kpis[kpi] = set()

    def set_kpi_exploded_vals(self, period, kpi, account_id, vals):
        """ Set the detail values for a kpi in a period for a GL account

        This is used by the automatic details mechanism.

        vals is a list of sub-kpi values.
        """
        exploded_vals = self._kpi_exploded_vals[period]
        if kpi not in exploded_vals:
            exploded_vals[kpi] = {}
{'fraction_non_alphanumeric': 0.09260433844982875, 'fraction_numerical': 0.003298236711911709, 'mean_word_length': 2.591799544419134, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '106574', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2306, 'n_words': 688}