<commit_before>'''
Definition of the models used in the timetracker app
'''

import datetime as dt
import calendar as cdr

from django.db import models
from django.forms import ModelForm

from timetracker.utils.datemaps import MONTH_MAP, DAYTYPE_CHOICES

class Tbluser(models.Model):

    """
    Models the user table and provides the admin interface with the
    niceties it needs.
    """

    USER_TYPE = (
        ('ADMIN', 'Administrator'),
        ('RUSER', 'Regular User')
    )

    MARKET_CHOICES = (
        ('BG', 'Germany'),
        ('BK', 'Kirchberg'),
        ('CZ', 'Czech')
    )

    PROCESS_CHOICES = (
        ('AP', 'Accounts Payable'),
        ('AR', 'Accounts Receivable'),
        ('AO', 'Accounting Operations')
    )

    JOB_CODES = (
        ('00F20A', '00F20A'),
        ('00F20B', '00F20B'),
        ('00F20C', '00F20C'),
        ('00F20D', '00F20D'),
        ('00F20E', '00F20E'),
        ('00F20F', '00F20F'),
        ('00F20G', '00F20G')
    )

    user_id = models.EmailField(max_length=105,
                                verbose_name=("UserID / HP Email"))

    firstname = models.CharField(max_length=60,
                                 db_column='uFirstName',
                                 verbose_name=("First Name"))

    lastname = models.CharField(max_length=60,
                                db_column='uLastName',
                                verbose_name=("Last Name"))

    password = models.CharField(max_length=60,
                                db_column='uPassword')

    user_type = models.CharField(max_length=5,
                                 choices=USER_TYPE)

    market = models.CharField(max_length=2,
                               db_column='uMarket',
                               choices=MARKET_CHOICES)

    process = models.CharField(max_length=2,
                                db_column='uProcess',
                                choices=PROCESS_CHOICES)

    start_date = models.DateField(db_column='Start_Date',
                                  verbose_name=("Start Date"))

    breaklength = models.TimeField(db_column='breakLength',
                                   verbose_name=("Break Length"))

    shiftlength = models.TimeField(db_column='shiftLength',
                                   verbose_name=("Shift Length"))

    job_code = models.CharField(max_length=6,
                                choices=JOB_CODES,
                                db_column='Job_Code',
                                verbose_name=('Job Code'))

    holiday_balance = models.IntegerField(db_column='Holiday_Balance',
                                          verbose_name=('Holiday Balance'))

    class Meta:

        """
        Metaclass allows for additional options to be set on the model
        """

        db_table = u'tbluser'
        verbose_name = "User"
        verbose_name_plural = "Users"
        unique_together = ("user_id", "firstname", "lastname")

    def __unicode__(self):

        """
        How the row is represented in admin
        """

        return '%s - %s %s ' % (self.user_id,
                                self.firstname,
                                self.lastname)

    def display_user_type(self):

        """
        Function for displaying the user in admin
        """

        return self.user_type

    def name(self):

        """
        Utility method for returning users full name
        """

        return self.firstname + ' ' + self.lastname

    def tracking_entries(self):
        """
        Returns all the tracking entries associated with
        this user
        """

        return TrackingEntry.objects.filter(user_id=self.id)
    
    def get_holiday_balance(self, year):
        """
        Calculates the holiday balance for the employee
        """

        tracking_days = TrackingEntry.objects.filter(user_id=self.id,
                                                     entry_date__year=year)

        holiday_value_map = {
            'HOLIS': -1,
            'PUWRK': 2,
            'RETRN': -1
            }

        holiday_balance = self.holiday_balance
        for entry in tracking_days:
            holiday_balance += holiday_value_map.get(entry.daytype, 0)

        return holiday_balance

    def get_total_balance(self):

        """
        Calculates the total balance for the user.
        """

        total, total_mins = 0, 0
        tracking_days = TrackingEntry.objects.filter(user_id=self.id)

        for item in tracking_days:

            total += (      item.end_time.hour
                        - item.start_time.hour )

            total_mins += (     item.end_time.minute
                            - item.start_time.minute )<commit_msg>Only calculate WKDAY for time balance<commit_after>'''
Definition of the models used in the timetracker app
'''

import datetime as dt
import calendar as cdr

from django.db import models
from django.forms import ModelForm

from timetracker.utils.datemaps import MONTH_MAP, DAYTYPE_CHOICES

class Tbluser(models.Model):

    """
    Models the user table and provides the admin interface with the
    niceties it needs.
    """

    USER_TYPE = (
        ('ADMIN', 'Administrator'),
        ('RUSER', 'Regular User')
    )

    MARKET_CHOICES = (
        ('BG', 'Germany'),
        ('BK', 'Kirchberg'),
        ('CZ', 'Czech')
    )

    PROCESS_CHOICES = (
        ('AP', 'Accounts Payable'),
        ('AR', 'Accounts Receivable'),
        ('AO', 'Accounting Operations')
    )

    JOB_CODES = (
        ('00F20A', '00F20A'),
        ('00F20B', '00F20B'),
        ('00F20C', '00F20C'),
        ('00F20D', '00F20D'),
        ('00F20E', '00F20E'),
        ('00F20F', '00F20F'),
        ('00F20G', '00F20G')
    )

    user_id = models.EmailField(max_length=105,
                                verbose_name=("UserID / HP Email"))

    firstname = models.CharField(max_length=60,
                                 db_column='uFirstName',
                                 verbose_name=("First Name"))

    lastname = models.CharField(max_length=60,
                                db_column='uLastName',
                                verbose_name=("<NAME>"))

    password = models.CharField(max_length=60,
                                db_column='uPassword')

    user_type = models.CharField(max_length=5,
                                 choices=USER_TYPE)

    market = models.CharField(max_length=2,
                               db_column='uMarket',
                               choices=MARKET_CHOICES)

    process = models.CharField(max_length=2,
                                db_column='uProcess',
                                choices=PROCESS_CHOICES)

    start_date = models.DateField(db_column='Start_Date',
                                  verbose_name=("Start Date"))

    breaklength = models.TimeField(db_column='breakLength',
                                   verbose_name=("Break Length"))

    shiftlength = models.TimeField(db_column='shiftLength',
                                   verbose_name=("Shift Length"))

    job_code = models.CharField(max_length=6,
                                choices=JOB_CODES,
                                db_column='Job_Code',
                                verbose_name=('Job Code'))

    holiday_balance = models.IntegerField(db_column='Holiday_Balance',
                                          verbose_name=('Holiday Balance'))

    class Meta:

        """
        Metaclass allows for additional options to be set on the model
        """

        db_table = u'tbluser'
        verbose_name = "User"
        verbose_name_plural = "Users"
        unique_together = ("user_id", "firstname", "lastname")

    def __unicode__(self):

        """
        How the row is represented in admin
        """

        return '%s - %s %s ' % (self.user_id,
                                self.firstname,
                                self.lastname)

    def display_user_type(self):

        """
        Function for displaying the user in admin
        """

        return self.user_type

    def name(self):

        """
        Utility method for returning users full name
        """

        return self.firstname + ' ' + self.lastname

    def tracking_entries(self):
        """
        Returns all the tracking entries associated with
        this user
        """

        return TrackingEntry.objects.filter(user_id=self.id)
    
    def get_holiday_balance(self, year):
        """
        Calculates the holiday balance for the employee
        """

        tracking_days = TrackingEntry.objects.filter(user_id=self.id,
                                                     entry_date__year=year)

        holiday_value_map = {
            'HOLIS': -1,
            'PUWRK': 2,
            'RETRN': -1
            }

        holiday_balance = self.holiday_balance
        for entry in tracking_days:
            holiday_balance += holiday_value_map.get(entry.daytype, 0)

        return holiday_balance

    def get_total_balance(self):

        """
        Calculates the total balance for the user.
        """

        total, total_mins = 0, 0
        tracking_days = TrackingEntry.objects.filter(user_id=self.id,
                                                     daytype="WKDAY")

        for item in tracking_days:

            total += (      item.end_time.hour
                        - item.start_time.hour )

            total_mins += (     item.end_time.minute
                            - item.start_time.minute )
{'fraction_non_alphanumeric': 0.1005774278215223, 'fraction_numerical': 0.015748031496062992, 'mean_word_length': 1.5463779738037957, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '641471', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2562, 'n_words': 539}