From 236ae156938434147998f8463cbe3cb063cae2c9 Mon Sep 17 00:00:00 2001 From: Benedikt Tissot <benedikt@tissot.de> Date: Mon, 28 Jan 2019 13:47:39 +0100 Subject: [PATCH] fix a logical error and make pylint happier --- python/arbeitsstundenzettel.py | 65 ++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/python/arbeitsstundenzettel.py b/python/arbeitsstundenzettel.py index 0ce2598..db03508 100644 --- a/python/arbeitsstundenzettel.py +++ b/python/arbeitsstundenzettel.py @@ -9,7 +9,7 @@ import datetime as dt import holidays import csv import random -import itertools +# import itertools import os import os.path import subprocess @@ -26,61 +26,74 @@ locale = locale.setlocale(locale.LC_ALL, 'de_DE.UTF8') def diff_full_months(start, end): start = start - end = end + dt.timedelta( days = 1 ) - + end = end + dt.timedelta(days=1) + full_months = (end.year - start.year) * 12 + end.month - start.month - + if start.day > end.day: full_months = full_months - 1 - + return full_months + def diff_months(start, end): - - months = ((end + dt.timedelta( days = 1 )) - start).days / 30 - + + # TODO y??? + end = end + dt.timedelta(days=1) + # TODO check wether this always works or wether it yields problems for start.day > end.day + # +1 as we want to include the starting month + months = (end.year - start.year) * 12 + end.month - start.month + 1 + print("months =", months) + return months + def diff_weeks(start, end): - - weeks = ((end + dt.timedelta( days = 1 )) - start).days / 7 - + + weeks = ((end + dt.timedelta(days=1)) - start).days / 7 + return weeks + def get_calendar_week(date): - + calendar_week = date.isocalendar()[1] - + return int(calendar_week) + def float2time(float_time): - + time = '{0:02.0f}.{1:02.0f}'.format(*divmod(round(float_time * 60), 60)) - + return time + def float2duration(float_time): - + time = '{0:02.0f}:{1:02.0f}'.format(*divmod(round(float(float_time) * 60), 60)) - + return time + def check_day_hours(list_of_workinghours, workingday_list_position, timestep): - + if list_of_workinghours[workingday_list_position][7] + timestep <= 6: return True else: return False -def check_week_hours(list_of_workinghours, workingday_list_position, timestep, list_of_filled_workinghours): - + +def check_week_hours(list_of_workinghours, workingday_list_position, + timestep, list_of_filled_workinghours): + current_calendar_week = get_calendar_week(list_of_workinghours[workingday_list_position][0]) list_of_affected_days = [same_calendar_week for same_calendar_week in list_of_workinghours if get_calendar_week(same_calendar_week[0]) == current_calendar_week] list_of_other_affected_days = [same_calendar_week for same_calendar_week in list_of_filled_workinghours if get_calendar_week(same_calendar_week[0]) == current_calendar_week] - + for a in range(len(list_of_other_affected_days)): list_of_affected_days.append(list_of_other_affected_days[a]) - + week_sum = 0 for x in range(len(list_of_affected_days)): week_sum = week_sum + list_of_affected_days[x][7] @@ -91,18 +104,18 @@ def check_week_hours(list_of_workinghours, workingday_list_position, timestep, l return False def move_filled_day(list_of_workinghours, workingday_list_position, list_of_filled_workinghours): - + list_of_filled_workinghours.append(list_of_workinghours[workingday_list_position]) list_of_workinghours = [unfilled_day for unfilled_day in list_of_workinghours if unfilled_day not in list_of_filled_workinghours] return list_of_workinghours, list_of_filled_workinghours print("Day " + list_of_workinghours[workingday_list_position][0].strftime("%Y-%m-%d") + " full and moved.") - + def move_filled_week(list_of_workinghours, workingday_list_position, list_of_filled_workinghours): - + current_calendar_week = get_calendar_week(list_of_workinghours[workingday_list_position][0]) list_of_affected_days = [same_calendar_week for same_calendar_week in list_of_workinghours if get_calendar_week(same_calendar_week[0]) == current_calendar_week] - + for x in range(len(list_of_affected_days)): list_of_filled_workinghours.append(list_of_affected_days[x]) list_of_workinghours = [unfilled_day for unfilled_day in list_of_workinghours if unfilled_day not in list_of_filled_workinghours] -- GitLab