From 1238f2227d9e02626d59ff6d2111978cfeafcc4b Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Wed, 23 Apr 2025 10:44:55 +0200 Subject: [PATCH] =?UTF-8?q?Ist-Zeit=20Berechnung=20f=C3=BCr=20Tage=20erg?= =?UTF-8?q?=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_ui.py | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/web_ui.py b/web_ui.py index 750f7bb..cf7efa7 100644 --- a/web_ui.py +++ b/web_ui.py @@ -33,6 +33,23 @@ def load_adminsettings(): except: return(-1) +def convert_seconds_to_hours(seconds): + hours = seconds // 3600 + remaining_seconds = seconds - hours * 3600 + minutes = remaining_seconds // 60 + remaining_seconds = remaining_seconds - minutes * 60 + if remaining_seconds > 0: + minutes += 1 + if hours < 10: + hours = "0" + str(hours) + else: + hours = str(hours) + if minutes < 10: + minutes = "0" + str(minutes) + else: + minutes = str(minutes) + return(f"{hours}:{minutes}") + @ui.page('/login') def page_login(): @@ -173,6 +190,7 @@ def page_admin(): with ui.row(): counter = 0 + for i in timestamps: actual_timestamp = datetime.datetime.fromtimestamp(int(i)) timestamp_day = actual_timestamp.strftime('%-d') @@ -220,7 +238,7 @@ def page_admin(): edit_dialog.open() counter += 1 - current_button = ui.button(actual_timestamp.strftime('%H:%M'), on_click=lambda t_stamp=i, day=day: edit_entry(t_stamp, day)) + ui.button(actual_timestamp.strftime('%H:%M'), on_click=lambda t_stamp=i, day=day: edit_entry(t_stamp, day)) #if counter % 2 == 0: # current_button.props('color=red') #else: @@ -242,10 +260,34 @@ def page_admin(): ui.markdown(f"{current_user.workhours[entry][str(weekday_index)]} h") found_match = True + # Arbeitszeit Ist bestimmen + timestamps_of_this_day = [ ] - # ui.markdown("Soll") + # Suche mir alle timestamps für diesen Tag + for i in timestamps: + actual_timestamp = datetime.datetime.fromtimestamp(int(i)) + timestamp_day = actual_timestamp.strftime('%-d') - ui.markdown("Ist") + if int(timestamp_day) == int(day): + timestamps_of_this_day.append(i) + + timestamps_of_this_day.sort() + if len(timestamps_of_this_day) > 1: + time_sum = 0 + if len(timestamps_of_this_day) % 2 == 0: + for i in range(0, len(timestamps_of_this_day), 2): + time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i]) + time_sum += time_delta + else: + for i in range(0, len(timestamps_of_this_day) - 1, 2): + time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i]) + time_sum += time_delta + + ui.markdown(convert_seconds_to_hours(time_sum)) + else: + ui.markdown("Kein") + + # ui.markdown("Ist") ui.markdown("+/-") def add_entry(day):