|
@@ -0,0 +1,136 @@
|
|
|
+from tool_lib.read_table import Read_Table
|
|
|
+from fast_excel_to_bill.transform_excel_data_to_bill_data.table_config import TABLE_PATH
|
|
|
+
|
|
|
+
|
|
|
+def add_sum_to_dict(work_time_dict, income_per_hour):
|
|
|
+ for key in work_time_dict.keys():
|
|
|
+ work_time_dict[key]['Betrag'] = int(work_time_dict[key]['Arbeitszeit']*income_per_hour)
|
|
|
+ return work_time_dict
|
|
|
+
|
|
|
+def round_worktime_for_week(work_time_dict, round_time = 300):
|
|
|
+ for key in work_time_dict.keys():
|
|
|
+ over_time = work_time_dict[key]['Arbeitszeit'] % round_time
|
|
|
+ work_time_dict[key]['Arbeitszeit'] = (work_time_dict[key]['Arbeitszeit']-over_time)/ 60
|
|
|
+ return work_time_dict, over_time
|
|
|
+
|
|
|
+def get_task_out_of_tree(work_time_dict):
|
|
|
+ for key in work_time_dict.keys():
|
|
|
+ work_time_dict[key]['Task'] = ['- ' + last_branch[last_branch.rfind('/')+1:] for last_branch in work_time_dict[key]['Task']]
|
|
|
+ return work_time_dict
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def compress_data_by_key_list(*compressable_lists, key_list):
|
|
|
+ '''
|
|
|
+ function: a list containing different Values, if a Value is more than one time
|
|
|
+ in the list. Then this list an all list of the same size are compressed, for the values of the
|
|
|
+ list_of_same_size they are put in tuple.
|
|
|
+ '''
|
|
|
+ if len(compressable_lists) > 1:
|
|
|
+ for list_ in compressable_lists:
|
|
|
+ past_values = []
|
|
|
+ pos_bias = 0
|
|
|
+ for pos, value in enumerate(key_list):
|
|
|
+ if value in past_values:
|
|
|
+ pos = pos - pos_bias
|
|
|
+ if isinstance(list_[pos - pos_bias], int):
|
|
|
+ list_[pos - 1] += list_[pos]
|
|
|
+ elif isinstance(list_[pos - pos_bias], str):
|
|
|
+ list_[pos - 1] = [list_[pos - 1], list_[pos]]
|
|
|
+ elif isinstance(list_[pos - pos_bias], list):
|
|
|
+ list_[pos - 1] = list_[pos - 1].append(list_[pos])
|
|
|
+ list_.remove(list_[pos])
|
|
|
+ pos_bias += 1
|
|
|
+ else:
|
|
|
+ past_values += [value]
|
|
|
+ else:
|
|
|
+ compressable_lists = compressable_lists[0]
|
|
|
+ if len(compressable_lists) > len(key_list):
|
|
|
+ compressable_lists = compressable_lists[:len(key_list)]
|
|
|
+ elif len(compressable_lists) < len(key_list):
|
|
|
+ assert (False, 'Compressable list length should be greater equal then the length of the key_list')
|
|
|
+ past_values = []
|
|
|
+ pos_bias = 0
|
|
|
+ for pos, value in enumerate(key_list):
|
|
|
+ if value in past_values:
|
|
|
+ pos = pos - pos_bias
|
|
|
+ if isinstance(compressable_lists[pos - 1], int):
|
|
|
+ compressable_lists[pos - 1] += compressable_lists[pos]
|
|
|
+ elif isinstance(compressable_lists[pos - 1], str):
|
|
|
+ compressable_lists[pos - 1] = [compressable_lists[pos - 1], compressable_lists[pos]]
|
|
|
+ elif isinstance(compressable_lists[pos - 1], list):
|
|
|
+ compressable_lists[pos - 1] += [compressable_lists[pos]]
|
|
|
+ compressable_lists.remove(compressable_lists[pos])
|
|
|
+ pos_bias += 1
|
|
|
+ else:
|
|
|
+ past_values += [value]
|
|
|
+ return compressable_lists
|
|
|
+
|
|
|
+
|
|
|
+def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
|
|
|
+ week_keys_to_list_of_keys_dict = {}
|
|
|
+ if isinstance(pathes, list):
|
|
|
+ for c, path in enumerate(pathes):
|
|
|
+
|
|
|
+ read_table_object = Read_Table(path)
|
|
|
+ table_object = read_table_object.table_to_dict()
|
|
|
+
|
|
|
+
|
|
|
+ calendar_weeks_list = table_object['Kalenderwoche']
|
|
|
+
|
|
|
+
|
|
|
+ for week in list(set(calendar_weeks_list)):
|
|
|
+ if week in week_keys_to_list_of_keys_dict:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ week_keys_to_list_of_keys_dict[week] = {}
|
|
|
+
|
|
|
+
|
|
|
+ key_dict = {}
|
|
|
+ for key in list_of_keys:
|
|
|
+ key_dict[key] = table_object[key]
|
|
|
+
|
|
|
+
|
|
|
+ for key in key_dict.keys():
|
|
|
+ all_weeks = compress_data_by_key_list(key_dict[key], key_list=calendar_weeks_list)
|
|
|
+ for week_indx, week in enumerate(list(set(calendar_weeks_list))):
|
|
|
+ if c == 0:
|
|
|
+ week_keys_to_list_of_keys_dict[week][key] = all_weeks[week_indx]
|
|
|
+ else:
|
|
|
+ if isinstance(all_weeks[week_indx], int):
|
|
|
+ week_keys_to_list_of_keys_dict[week][key] += all_weeks[week_indx]
|
|
|
+ elif isinstance(all_weeks[week_indx], list):
|
|
|
+ week_keys_to_list_of_keys_dict[week][key] += all_weeks[week_indx]
|
|
|
+ else:
|
|
|
+
|
|
|
+ read_table_object = Read_Table(pathes)
|
|
|
+ table_object = read_table_object.table_to_dict()
|
|
|
+
|
|
|
+
|
|
|
+ calendar_weeks_list = table_object['Kalenderwoche']
|
|
|
+
|
|
|
+
|
|
|
+ for week in list(set(calendar_weeks_list)):
|
|
|
+ if week in week_keys_to_list_of_keys_dict:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ week_keys_to_list_of_keys_dict[week] = {}
|
|
|
+
|
|
|
+
|
|
|
+ key_dict = {}
|
|
|
+ for key in list_of_keys:
|
|
|
+ key_dict[key] = table_object[key]
|
|
|
+
|
|
|
+
|
|
|
+ compressed_lists = []
|
|
|
+ for key in key_dict.keys():
|
|
|
+ all_weeks = compress_data_by_key_list(key_dict[key], key_list=calendar_weeks_list)
|
|
|
+ for week_indx, week in enumerate(list(set(calendar_weeks_list))):
|
|
|
+ week_keys_to_list_of_keys_dict[week][key] = all_weeks[week_indx]
|
|
|
+
|
|
|
+ return week_keys_to_list_of_keys_dict
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ table_object = main_data_collection([TABLE_PATH, TABLE_PATH])
|