Răsfoiți Sursa

TOOL PROJECT
- time_recorder
- time_recorder gui

Danny 2 ani în urmă
părinte
comite
5391b73278

+ 1 - 1
personal_income_calculator/income_calculator_main.py

@@ -1,4 +1,4 @@
-def calc_income_by_time(worked_time, hourly_wage_in_euro):
+def calc_income_by_time_in_euro(worked_time, hourly_wage_in_euro):
     sales_tax_percent = 0.19
     brutto_income_in_euro = worked_time*(hourly_wage_in_euro/60)
     sales_tax = sales_tax_percent*brutto_income_in_euro

+ 1 - 1
time_recoder/Readme

@@ -1 +1 @@
-pip install styleframe xlsxwriter
+pip install styleframe xlsxwriter pysimplegui

+ 16 - 10
time_recoder/save_recorded_time_in_table.py

@@ -1,26 +1,32 @@
-from time_recoder.time_recoder_config import HOURLY_WAGE_IN_EURO, PATH
-from personal_income_calculator.income_calculator_main import calc_income_by_time
+from time_recoder.time_recoder_config import HOURLY_WAGE_IN_EURO, PATH, NAME
+from personal_income_calculator.income_calculator_main import calc_income_by_time_in_euro
 from tool_lib import create_excel_tables
 from os import path
-
+from time import time
+from datetime import date
 def create_recorded_time_dict(worked_time, income, sales_taxes):
-    return {'Arbeitszeit' : worked_time,
+    return {'Name': NAME,
+            'Datum': str(date.today()),
+            'Arbeitszeit' : worked_time,
             'Einkommen': income,
             'Umsatzsteuern': sales_taxes}
 
-def table_exists(path):
-    return path.isfile(path)
+def table_exists(path_):
+    return path.isfile(path_)
+
+def get_current_time_as_timestamp():
+    return int(time())
 
 def add_to_xlsx_table(table_object):
-    pass
+    table_object.append_df_to_xlsx(table_object.dataframes)
 
 def create_xlsx_table(table_object):
-    pass
+    table_object.export_to_excel(table_object.create_writer())
 
 def save_recorded_time_in_table(worked_time_in_minutes):
-    income, sales_taxes = calc_income_by_time(worked_time_in_minutes, HOURLY_WAGE_IN_EURO)
+    income, sales_taxes = calc_income_by_time_in_euro(worked_time_in_minutes, HOURLY_WAGE_IN_EURO)
     table_dict = create_recorded_time_dict(worked_time_in_minutes, income, sales_taxes)
-    xlsx_table= create_excel_tables.CreateTable(table_dict, path=PATH)
+    xlsx_table = create_excel_tables.CreateTable(table_dict, path=PATH)
     if table_exists(PATH):
         add_to_xlsx_table(xlsx_table)
     else:

+ 3 - 2
time_recoder/time_recoder_config.py

@@ -1,3 +1,4 @@
 HOURLY_WAGE_IN_EURO = 28
-PATH = r'C:\Users\Danny\Desktop\ssd wichtige dinge D\Tools\time_recoder\time_recorded_tables'
-TEST_CASE = True
+PATH = r'C:\Users\Danny\Desktop\ssd wichtige dinge D\Tools\time_recoder\time_recorded_tables\worked_time_table.xlsx'
+TEST_CASE = True
+NAME = 'Daniel Krauel'

+ 7 - 0
time_recoder/time_recoder_gui/time_recorder_gui_config.py

@@ -0,0 +1,7 @@
+
+PAUSE_BUTTON_TEXT = 'Pause Timer'
+START_BUTTON_TEXT = 'Start Timer'
+STOP_BUTTON_TEXT = 'Stop Timer'
+STOP_BUTTON_INTRODUCTION_TEXT = 'Pause Timer: Pausiert die aktuelle Zeit'
+PAUSE_BUTTON_INTRODUCTION_TEXT = 'Stop Timer: Fügt die gearbeitete Zeit in eine Excel'
+WINDOW_SIZE = (400, 130)

+ 80 - 0
time_recoder/time_recoder_gui/time_recorder_gui_main.py

@@ -0,0 +1,80 @@
+import PySimpleGUI
+from time_recoder.time_recoder_gui.time_recorder_gui_config import PAUSE_BUTTON_TEXT, START_BUTTON_TEXT, STOP_BUTTON_TEXT, \
+    STOP_BUTTON_INTRODUCTION_TEXT, PAUSE_BUTTON_INTRODUCTION_TEXT, WINDOW_SIZE
+from time_recoder import save_recorded_time_in_table
+
+
+def create_layout():
+    return [
+        [PySimpleGUI.Text(PAUSE_BUTTON_INTRODUCTION_TEXT)],
+        [PySimpleGUI.Text(STOP_BUTTON_INTRODUCTION_TEXT)],
+        [PySimpleGUI.Button(START_BUTTON_TEXT),
+         PySimpleGUI.Button(PAUSE_BUTTON_TEXT),
+         PySimpleGUI.Button(STOP_BUTTON_TEXT)]
+    ]
+
+
+def create_window(layout):
+    return PySimpleGUI.Window('END_TR300 Arbeitserfassungstool ', layout=layout, size=WINDOW_SIZE)
+
+
+def window_is_closed(event):
+    return event == PySimpleGUI.WIN_CLOSED
+
+
+def stop_button_is_pushed(event):
+    return event == STOP_BUTTON_TEXT
+
+
+def start_button_is_pushed(event):
+    return event == START_BUTTON_TEXT
+
+
+def pause_button_is_pushed(event):
+    return event == PAUSE_BUTTON_TEXT
+
+
+def event_loop(window):
+    while True:
+        event, values = window.read()
+        if window_is_closed(event):
+            break
+        if start_button_is_pushed(event):
+            print('Start Time')
+            if 'start_time' in locals():
+                if 'pause_time' in locals():
+                    print('Time updated, Pause Timer Reseted')
+                    start_time = start_time + (pause_time - save_recorded_time_in_table.get_current_time_as_timestamp())
+                    pause_time = 'reseted'
+                else:
+                    pass
+            else:
+                start_time = save_recorded_time_in_table.get_current_time_as_timestamp()
+        if pause_button_is_pushed(event):
+            print('Pause Timer Activated')
+            if 'pause_time' in locals():
+                if pause_time == 'reseted':
+                    print('New Pause Timer Activated')
+                    pause_time = save_recorded_time_in_table.get_current_time_as_timestamp()
+                else:
+                    pass
+            else:
+                pause_time = save_recorded_time_in_table.get_current_time_as_timestamp()
+        if stop_button_is_pushed(event):
+            print('Timer Stoped Recording, Close the Window')
+            if 'start_time' in locals():
+                worked_time_in_minutes = (save_recorded_time_in_table.get_current_time_as_timestamp() - start_time) / 60
+                save_recorded_time_in_table.save_recorded_time_in_table(worked_time_in_minutes)
+            else:
+                pass
+
+
+def gui_main():
+    layout = create_layout()
+    window = create_window(layout)
+    event_loop(window)
+    window.close()
+
+
+if __name__ == '__main__':
+    gui_main()

+ 0 - 27
time_recoder/time_recoder_main.py

@@ -1,27 +0,0 @@
-from time import sleep, time
-from time_recoder.save_recorded_time_in_table import save_recorded_time_in_table
-from time_recoder.time_recoder_config import TEST_CASE
-
-
-def get_current_time_as_timestamp():
-    return int(time())
-
-def stop_record_time():
-    if TEST_CASE:
-        sleep(5)
-        return True
-    else:
-        NotImplementedError
-
-
-def time_recording_main():
-    start_time = get_current_time_as_timestamp()
-    while not stop_record_time():
-        sleep(1)
-    else:
-        worked_time_in_minutes = (get_current_time_as_timestamp() - start_time)/60
-        save_recorded_time_in_table(worked_time_in_minutes)
-
-
-if __name__ == '__main__':
-    time_recording_main()

+ 37 - 0
time_recoder/time_recoder_test.py

@@ -0,0 +1,37 @@
+import unittest
+from os import path
+import time_recoder.time_recoder_config as config_
+import re
+from time import sleep
+from time_recoder.save_recorded_time_in_table import save_recorded_time_in_table, get_current_time_as_timestamp
+from time_recoder.time_recoder_config import TEST_CASE
+
+
+
+class ConfigTest(unittest.TestCase):
+
+    def test_path_folder_exists(self):
+        folder_string_index = config_.PATH.rfind('\\')
+        tested_path = config_.PATH[0:folder_string_index]
+        self.assertTrue(path.isdir(tested_path), msg='The Folder where the Table should be does not exist, check path')
+
+class TimeRecorderIntegrationtest(unittest.TestCase):
+
+    def test_time_recorder_without_gui(self):
+        ConfigTest().test_path_folder_exists()
+
+        # Integration Test
+        start_time = get_current_time_as_timestamp()
+        sleep(5)
+        worked_time_in_minutes = (get_current_time_as_timestamp() - start_time) / 60
+        save_recorded_time_in_table(worked_time_in_minutes)
+
+
+class GUITest(unittest.TestCase):
+    def test_gui_layout_format(self):
+        raise NotImplementedError
+
+
+
+if __name__ == '__main__':
+    TimeRecorderIntegrationtest().test_time_recorder_without_gui()

+ 4 - 31
tool_lib/create_excel_tables.py

@@ -81,34 +81,7 @@ class CreateTable:
                 writer.sheets['Karte ' + str(count + 2)].set_column(col_idx, col_idx, column_width, cell_format=currency_format)
         writer.save()
 
-
-
-    def add_to_existing_xlsx_file(self, writer, additional_dataframes=[]):
-        if self.ordered_by == []:
-            pass
-        else:
-            self.dataframes = self.dataframes.sort_values(by=self.ordered_by, axis=self.axis)
-
-            # Format
-        currency_format = self.create_workbook().add_format()
-        currency_format.set_align('center')
-        currency_format.set_align('center')
-
-        # First Tab
-        self.dataframes.to_excel(excel_writer=writer, sheet_name='Karte ' + str(1), index=False)
-        for column in self.dataframes:
-            column_width = max(self.dataframes[column].astype(str).map(len).max(), len(column) + 5)
-            col_idx = self.dataframes.columns.get_loc(column)
-
-            writer.sheets['Karte ' + str(1)].set_column(col_idx, col_idx, column_width, cell_format=currency_format)
-
-        # All other Tabs
-
-        for count, each_dataframe in enumerate(additional_dataframes):
-            each_dataframe.to_excel(writer, sheet_name='Karte ' + str(count + 2), index=False)
-            for column in each_dataframe:
-                column_width = max(each_dataframe[column].astype(str).map(len).max(), len(column) + 5)
-                col_idx = each_dataframe.columns.get_loc(column)
-                writer.sheets['Karte ' + str(count + 2)].set_column(col_idx, col_idx, column_width, cell_format=currency_format)
-        writer.save()
-
+    def append_df_to_xlsx(self, df): #TODO extract even more
+        df_excel = pd.read_excel(self.path)
+        self.dataframes = pd.concat([df_excel, df], ignore_index=True)
+        self.export_to_excel(self.create_writer())