Browse Source

Add categories for work time analysis

Eren Yilmaz 1 year ago
parent
commit
ab017d1ea0

+ 95 - 5
time_recoder/statistics.py

@@ -1,12 +1,97 @@
+import math
 import os
-from typing import List
+from typing import List, Union
 
 import numpy
 import pandas
 from pandas import DataFrame
 
 from tool_lib.tuned_pandasql import TunedPandaSQL
-from tool_lib.util import my_tabulate
+from tool_lib.util import my_tabulate, EBC, EBE
+
+
+class Category(EBE):
+    UNKNOWN = 'UNKNOWN'
+    OPERATIVE = 'OPERATIVE'
+    MEETING = 'MEETING'
+    PLANNING = 'PLANNING'
+    STRATEGY = 'STRATEGY'
+    CONTROLLING = 'CONTROLLING'
+    AUTOMATION = 'AUTOMATION'
+    WASTED_TIME = 'WASTED_TIME'
+    NOT_AVAILABLE = 'NOT_AVAILABLE'
+
+    @classmethod
+    def determine_category(cls, task: Union[str, float]) -> 'Category':
+        task = str(task)
+        if task == 'nan':
+            return cls.NOT_AVAILABLE
+        elif task == 'root':
+            return cls.NOT_AVAILABLE
+        elif 'meeting' in task.lower():
+            return cls.MEETING
+        elif 'eckard' in task.lower() or 'eckhard' in task.lower():
+            return cls.MEETING
+        elif 'unternehmensberatung' in task.lower():
+            return cls.MEETING
+        elif 'wirschaftsbüro' in task.lower() or 'wirtschaftsbüro' in task.lower():
+            return cls.MEETING
+        elif 'controlling' in task.lower():
+            return cls.CONTROLLING
+        elif 'strateg' in task.lower():
+            return cls.STRATEGY
+        elif 'arbeitserfassungstool' in task.lower():
+            return cls.AUTOMATION
+        elif 'worktime table' in task.lower():
+            return cls.AUTOMATION
+        elif 'automat' in task.lower():
+            return cls.AUTOMATION
+        elif 'template' in task.lower():
+            return cls.AUTOMATION
+        elif 'rechnung' in task.lower():
+            return cls.AUTOMATION
+        elif 'operativ' in task.lower():
+            return cls.OPERATIVE
+        elif 'website' in task.lower():
+            return cls.OPERATIVE
+        elif 'bunq' in task.lower():
+            return cls.WASTED_TIME
+        elif task == 'root/Master-Arbeitsstunden ':
+            return cls.OPERATIVE
+        elif 'planungsassistent' in task.lower():
+            return cls.OPERATIVE
+        elif 'telefonat' in task.lower():
+            return cls.OPERATIVE
+        elif 'umfrage' in task.lower():
+            return cls.OPERATIVE
+        elif 'code cleaning' in task.lower():
+            return cls.OPERATIVE
+        elif 'economy_calendar' in task.lower() or 'economy calendar' in task.lower():
+            return cls.OPERATIVE
+        elif 'tradingbot' in task.lower() or 'trading bot' in task.lower():
+            return cls.OPERATIVE
+        elif 'optiwae' in task.lower():
+            return cls.OPERATIVE
+        elif 'twilio' in task.lower():
+            return cls.OPERATIVE
+        elif 'linkguide' in task.lower():
+            return cls.OPERATIVE
+        elif 'plan' in task.lower():
+            return cls.PLANNING
+        elif 'tools' in task.lower():
+            return cls.AUTOMATION
+        else:
+            return cls.UNKNOWN
+
+
+unknown_categories = set()
+
+
+def category_from_row(row):
+    result = Category.determine_category(row['Task']).value
+    if result == Category.UNKNOWN.value:
+        unknown_categories.add(row['Task'])
+    return result
 
 
 def load_from_disk():
@@ -87,6 +172,7 @@ def raw_df():
         'Arbeitszeit in Minuten': get_work_time_minutes,
         'Einkommen': get_income,
         'Überstunden': get_overtime,
+        'Kategorie': category_from_row,
         **{
             f'Task Präfix {i}': lambda row, i=i: get_task_prefix(row, i)
             for i in range(1, MAX_TASK_PARTS)
@@ -94,10 +180,10 @@ def raw_df():
     }
     combinations: List[tuple] = [
         ('Name', 'Jahr'),
-        ('Name', 'Task'),
-        ('Name', 'Task Präfix 1'),
+        # ('Name', 'Task'),
+        # ('Name', 'Task Präfix 1'),
         ('Name', 'Task Präfix 2'),
-        ('Name', 'Task Präfix 3'),
+        # ('Name', 'Task Präfix 3'),
     ]
 
     for combination in combinations:
@@ -183,3 +269,7 @@ def compute_rows(max_distinct_values=120, ):
 rows, columns = compute_rows()
 rows = sorted(rows, key=lambda row: (row[0], row[1]))
 print(my_tabulate(data=rows, headers=columns))
+print()
+print('Unspecified categories:')
+for c in unknown_categories:
+    print(' -', c)

BIN
time_recoder/time_recorded_tables/work_time_danny - Kopie.xlsx