|
@@ -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")
|