<commit_before># !/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# Copyright: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

"""
Calculation module
"""

from models.query import Query


class Calculator:
    """
    Calculator
    """

    def __init__(self):
        """
        Initialize Calculator
        """
        self.model = {
            "name": "calc",
            "id": "calc_id",
            "fields": ("calc_id", "calc_date", "report_id", "employee_id", "reports_calculated",
                       "new_visit", "new_demo", "new_sale", "new_turnover",
                       "recall_visit", "recall_demo", "recall_sale", "recall_turnover",
                       "sas", "sas_turnover", "current", "demo", "sale", "turnover",
                       "kmwork", "kmprivate", "workdays", "offdays"),
            "types": ("INTEGER PRIMARY KEY NOT NULL", "TEXT NOT NULL", "INTEGER NOT NULL", "INTEGER NOT NULL",
                      "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "REAL DEFAULT 0",
                      "INTEGER DEFAULT 0", "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "INTEGER DEFAULT 0", "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "INTEGER DEFAULT 0", "INTEGER DEFAULT 0")
        }
        self._totals = {}
        self.q = Query()
        if not self.q.exist_table(self.model["name"]):
            sql = self.q.build("create", self.model)
            self.q.execute(sql)

    @property
    def active(self):
        """
        Totals
        Returns:
            The current current
        """
        return self._totals

    @active.setter
    def active(self, wd_eid):
        """
        Sets the current totals
        :param wd_eid: string with two 'words' the first is workdate and the second is employee_id
        :return:
        """
        td = wd_eid.split()
        try:
            wd = td[0]
            eid = td[1]
            try:
                twd = self._totals["workdate"]
                if not twd == wd:
                    self.select_by_date_employee(wd, eid)
            except KeyError:
                self.select_by_date_employee(wd, eid)
        except IndexError:
            self.clear()

    def clear(self):
        """
        Clear internal variables
        """
        self._totals = {}

    def insert(self, values):
        """
        Save values to database and sets current with the supplied values
        Args:
            values:<commit_msg>code cleanup<commit_after># !/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# Copyright: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

"""
Calculation module
"""

from models.query import Query


class Calculator:
    """
    Calculator
    """

    def __init__(self):
        """
        Initialize Calculator
        """
        self.model = {
            "name": "report_calculations",
            "id": "calc_id",
            "fields": ("calc_id", "calc_date", "report_id", "employee_id", "reports_calculated",
                       "new_visit", "new_demo", "new_sale", "new_turnover",
                       "recall_visit", "recall_demo", "recall_sale", "recall_turnover",
                       "sas", "sas_turnover", "current", "demo", "sale", "turnover",
                       "kmwork", "kmprivate", "workdays", "offdays"),
            "types": ("INTEGER PRIMARY KEY NOT NULL", "TEXT NOT NULL", "INTEGER NOT NULL", "INTEGER NOT NULL",
                      "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0", "REAL DEFAULT 0",
                      "INTEGER DEFAULT 0", "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "INTEGER DEFAULT 0", "REAL DEFAULT 0", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0",
                      "INTEGER DEFAULT 0", "INTEGER DEFAULT 0")
        }
        self._totals = {}
        self.q = Query()
        if not self.q.exist_table(self.model["name"]):
            sql = self.q.build("create", self.model)
            self.q.execute(sql)

    @property
    def active(self):
        """
        Totals
        Returns:
            The current current
        """
        return self._totals

    @active.setter
    def active(self, date_employee):
        """
        Sets the current totals
        :param date_employee: tuple with date and employee
        :return:
        """
        try:
            try:
                _ = self._totals["workdate"]
                if not _ == date_employee[0]:
                    self.select_by_date_employee(date_employee[0], date_employee[1])
            except KeyError:
                self.select_by_date_employee(date_employee[0], date_employee[1])
        except IndexError:
            self.clear()

    def clear(self):
        """
        Clear internal variables
        """
        self._totals = {}

    def insert(self, values):
        """
        Save values to database and sets current with the supplied values
        Args:
            values:
{'fraction_non_alphanumeric': 0.1288098693759071, 'fraction_numerical': 0.011429608127721336, 'mean_word_length': 1.8300821355236139, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '2444628', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1592, 'n_words': 440}