From b0067ae057c0305270c5275579c0bdec63b4e33d Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 3 Mar 2024 22:01:21 +0100 Subject: [PATCH] step3.py updated --- main.py | 21 ++++++++++++--------- src/step2.py | 11 +++++++---- src/step3.py | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index d7254e2..7c31bed 100644 --- a/main.py +++ b/main.py @@ -41,10 +41,10 @@ if __name__ == "__main__": log_file_path = 'log.txt' if os.path.exists(log_file_path): open(log_file_path, 'w').close() - # sys.stdout = Logger.Logger(log_file_path) + sys.stdout = Logger.Logger(log_file_path) print("Schul-IT UCS-Import Tool:\n") - dev = True + dev = True # CHANGE FOR PRODUCTION RUN <------ # ----------------------------------------------------------------- # # Step 1 - Dateien wählen, formatieren, einlesen | Variablen setzen # @@ -70,11 +70,11 @@ if __name__ == "__main__": print("Schul ID:", school_id, "\nOX-Context:", ox_context, "\nNullen:", del_zeros) lul_new = step1.check_export_file(lehrer_liste_neu) - # print("Spalten der Import Liste - Lehrer:", lul_new.columns) + # print("Spalten der Import Liste - Lehrer: ", lul_new.columns) lul_sys = step1.create_dataframe_system(lehrer_liste_system) sus_new = step1.check_export_file(schueler_liste_neu) - # print("Spalten der Import Liste - Schüler:", sus_new.columns) + # print("Spalten der Import Liste - Schüler: ", sus_new.columns) sus_sys = step1.create_dataframe_system(schueler_liste_system) # Test- und Funktionsuser auslagern @@ -92,16 +92,19 @@ if __name__ == "__main__": # 2.1 Data Frames für Abgleich erstellen print(" Lehrer:innen:") - lul_matched, new_lul = step2.compare_data(lul_new, lul_sys, False) + lul_matched, new_lul = step2.compare_data(lul_new, lul_sys) print("\n Schüler:innen:") - sus_matched, new_sus = step2.compare_data(sus_new, sus_sys, True) + sus_matched, new_sus = step2.compare_data(sus_new, sus_sys,) + print("Step2 completed! \n") + + sys.stdout = sys.__stdout__ # ----------------------------------------------------------------------------------------# # Step 3 - Import Data generieren - klasse, uuids, weiteres in einer Liste zusammenführen # # Lul: Namen + UUIDs + Testuser - lul_import = step3.add_school_data(lul_sys, school_id, ox_context, mail_quota_lul, ox_quota_lul) + lul_import = step3.merch_uuids(new_lul, lul_matched, dev) + # lul_import = step3.add_school_data(lul_import, school_id, ox_context, mail_quota_lul, ox_quota_lul) + print(lul_import[['name', 'klasse', 'schuelerid']]) # SuS: Namen + UUIDs + Klassen + Testuser # sus_import = step3.add_school_data(sus_sys, school_id, ox_context, mail_quota_sus, ox_quota_sus) - - sys.stdout = sys.__stdout__ diff --git a/src/step2.py b/src/step2.py index 4611d6b..b68c356 100644 --- a/src/step2.py +++ b/src/step2.py @@ -2,10 +2,12 @@ import pandas as pd from Levenshtein import distance -def compare_data(new, sys, bool_class): +def compare_data(new, sys): print(f"\nEinträge in Import Liste: {len(new)}") print(f"Einträge in System Liste: {len(sys)}") + bool_class = 'klasse' in new.columns + if bool_class: if 'index' in new.columns: new = new.drop('index', axis=1) @@ -35,9 +37,10 @@ def search_typos(new, sys): for idx1, row1 in new.iterrows(): for idx2, row2 in sys.iterrows(): if distance(row1[col1], row2[col1]) <= 2 and distance(row1[col2], row2[col2]) <= 2: - typos.append((row1[col1], row1[col2], row2[col1], row2[col2])) - if len(typos) > 0: - print('Mögliche Tippfehler:', len(typos), '\n', typos) + typos.append(([row1[col1], row1[col2]], [row2[col1], row2[col2]])) + typo_df = pd.DataFrame(typos, columns=['Import', 'System']) + if len(typo_df) > 0: + print('Mögliche Tippfehler:', len(typo_df), '\n', typo_df) else: print('Mögliche Tippfehler: keine Fehler gefunden!') diff --git a/src/step3.py b/src/step3.py index d078c88..30045fe 100644 --- a/src/step3.py +++ b/src/step3.py @@ -1,15 +1,25 @@ import uuid +import pandas as pd def create_uuid(): return str(uuid.uuid4()) -def merch_uuids(new, sys): - return 0 +def merch_uuids(new, sys, dev): + print(sys[['name', 'klasse', 'schuelerid']]) + print(new[['name', 'klasse', 'schuelerid']]) + if dev: + new_uuids = ["test" for _ in range(len(new))] + else: + new_uuids = [create_uuid() for _ in range(len(new))] + new['schuelerid'] = new_uuids + + return pd.concat([sys, new], ignore_index=True) def add_school_data(df, school_id, ox_context, mail_quota, ox_quota): + # print(df.head()) df['mailUserQuota'] = mail_quota df['oxUserQuota'] = ox_quota df['oxContext'] = ox_context