removed db
This commit is contained in:
parent
2eeda5315e
commit
3f26366eda
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@ -6,9 +6,14 @@ import pandas as pd
|
||||
|
||||
class UpdatePlan:
|
||||
def __init__(self, json):
|
||||
''':param json - json, generated by JS in frontend'''
|
||||
'''target username'''
|
||||
self.target_username = json['username']
|
||||
'''start date in iso format'''
|
||||
self.start_date = dt.datetime.strptime(json['date_start'], '%Y-%m-%d')
|
||||
'''end date in iso format'''
|
||||
self.end_date = dt.datetime.strptime(json['date_end'], '%Y-%m-%d')
|
||||
'''start time as string'''
|
||||
self.start_time = dt.datetime.strptime(json['start_time'], '%H:%M').time()
|
||||
self.daily_hours = int(json['daily_hours']) * 60
|
||||
self.activity_type = json['activity_type']
|
||||
@ -18,6 +23,7 @@ class UpdatePlan:
|
||||
self.log = None
|
||||
|
||||
def run_inserting(self):
|
||||
'''controller, running database insert for each day, checking conflicts and returning report as dictionary'''
|
||||
log = []
|
||||
for day in range(self.n_days + 1):
|
||||
date_to_add = self.start_date + dt.timedelta(days=day)
|
||||
@ -40,7 +46,9 @@ class UpdatePlan:
|
||||
|
||||
|
||||
def insert_into_plan(self, date_to_add):
|
||||
'''void function, performing separate inserts'''
|
||||
employee = Employee.objects.get(pk=self.target_username)
|
||||
'''check if the shift is overnight - then split into 2 days'''
|
||||
if not self.check_overnight_shift():
|
||||
plan = Plan(username=employee,
|
||||
date=date_to_add,
|
||||
@ -62,6 +70,8 @@ class UpdatePlan:
|
||||
activity_type=self.activity_type)
|
||||
plan.save()
|
||||
|
||||
'''if activity type is not work, then will be inserted into both plan and timelog tables
|
||||
isert into timelog table is needed for reporting'''
|
||||
if self.activity_type != 'work':
|
||||
if not self.check_overnight_shift():
|
||||
timelog = TimeLog(username=employee,
|
||||
@ -87,6 +97,8 @@ class UpdatePlan:
|
||||
|
||||
|
||||
def check_conflicting_records(self, checked_date):
|
||||
'''method to check if the inserted record overlaps with existing records
|
||||
:return True if overlapse else False'''
|
||||
plan = Plan.objects.filter(username=self.target_username, date=checked_date)
|
||||
if len(plan) > 0:
|
||||
for day in plan:
|
||||
@ -106,6 +118,8 @@ class UpdatePlan:
|
||||
|
||||
|
||||
def check_overnight_shift(self):
|
||||
'''function to check if shift is overnight
|
||||
:return True if overnight else False'''
|
||||
start = dt.datetime(2020, 1, 1, self.start_time.hour, self.start_time.minute, self.start_time.second)
|
||||
end = start + dt.timedelta(minutes=self.daily_hours)
|
||||
if (end.date() - start.date()).days > 0:
|
||||
@ -115,12 +129,14 @@ class UpdatePlan:
|
||||
|
||||
|
||||
def get_end_time(self):
|
||||
'''get shift end time, since in the begin we are providing only starting time and N hours'''
|
||||
start = dt.datetime(2020, 1, 1, self.start_time.hour, self.start_time.minute, self.start_time.second)
|
||||
end = start + dt.timedelta(minutes=self.daily_hours)
|
||||
return end.time()
|
||||
|
||||
|
||||
def get_timemodel(self, time_model):
|
||||
'''parsing time model into dicionary'''
|
||||
time_model_pattern = {0: time_model['mon'],
|
||||
1: time_model['tue'],
|
||||
2: time_model['wed'],
|
Loading…
Reference in New Issue
Block a user