瀏覽代碼

Getrennt gespeicherte Dateien zusammensetzen

robert 1 年之前
父節點
當前提交
d4fbe4b7f1
共有 1 個文件被更改,包括 39 次插入0 次删除
  1. 39 0
      webservice/planner_combine_files.py

+ 39 - 0
webservice/planner_combine_files.py

@@ -0,0 +1,39 @@
+from collections import defaultdict
+from plan_values2 import VALUES2_HEADER
+
+import json
+import csv
+import re
+from pathlib import Path
+
+
+def combine_file(year, version, timestamp, username):
+    base_dir = "save/"
+
+    data_file = f"data_{year}_{version}_{timestamp}.csv"
+    data_search = rf"data_{year}_{version}_\d+\.csv"
+    user_search = rf"user_{username}_\d+\.json"
+    options_search = rf"options_{year}_{version}_\d+\.json"
+    struct_search = rf"struct_{year}_{version}_\d+\.json"
+
+    file_list = [f.name for f in Path(base_dir).glob("*.*") if f.is_file()]
+    file_list.sort()
+
+    if not Path(base_dir + data_file).exists():
+        data_files = [f for f in file_list if re.search(data_search, f)]
+        if len(data_files) > 0:
+            data_file = data_files[-1]
+
+    with open(base_dir + data_file, "r") as frh:
+        csv_reader = csv.reader(frh, delimiter="\t")
+        header = next(csv_reader)
+        values2 = defaultdict(dict)
+        for row in csv_reader:
+            id = row.pop(0)
+            department = row.pop(0)
+            values2[id][department] = row
+    print(len(values2.keys()))
+
+
+if __name__ == "__main__":
+    combine_file("2023", "V1", "current", "global")