From 258472d30fe7ea57944a1a8af631d803995b30a5 Mon Sep 17 00:00:00 2001 From: "christoph.von.oy" <christoph.von.oy@rwth-aachen.de> Date: Fri, 5 May 2023 12:21:48 +0200 Subject: [PATCH] Models are jsons now --- Model_Library | 2 +- .../convert_input_files_new_input_format.py | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Model_Library b/Model_Library index e666cdf791..933cbeb8de 160000 --- a/Model_Library +++ b/Model_Library @@ -1 +1 @@ -Subproject commit e666cdf7915a24c5fa750649a13dedb3f61f4fdb +Subproject commit 933cbeb8de5715ad18184c67a609ce852d152ade diff --git a/input_files/convert_input_files_new_input_format.py b/input_files/convert_input_files_new_input_format.py index a4d8d37199..1b48ff4114 100644 --- a/input_files/convert_input_files_new_input_format.py +++ b/input_files/convert_input_files_new_input_format.py @@ -23,7 +23,7 @@ THE SOFTWARE. """ """ -This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !TODO New input format. +This script inspects the input files and modifies them such that they adhere to the new input file specification used by the framework after merge of merge request !24 New input format. """ import os.path @@ -120,3 +120,26 @@ for directory in changed_topologies: print(f"Modified topology {directory}!") for file in invalid_topologies: print(f"Topology {file} breaks some part of the input file specification!") + +changed_models = [] +invalid_models = [] +for dirpath, dirnames, filenames in os.walk(".\\Model_Library\\Component\\data"): + for filename in filenames: + if filename.endswith(".csv"): + try: + print(f"Inspecting model {os.path.join(dirpath, filename)}") + model = pd.read_csv(os.path.join(dirpath, filename)) + model_json = dict() + for i in model.columns: + no_space_name = "_".join(i.split(" ")) + model_json[no_space_name] = model[i][0] + changed_models.append(os.path.join(dirpath, filename)) + os.remove(os.path.join(dirpath, filename)) + with open(os.path.join(dirpath, "".join(filename.split(".")[:-1]) + ".json"), "w", encoding ="utf-8") as f: + json.dump(model_json, f, indent = 4, default = np_encoder) + except: + invalid_models.append(os.path.join(dirpath, filename)) +for directory in changed_models: + print(f"Modified model {directory}!") +for file in invalid_models: + print(f"Model {file} breaks some part of the input file specification!") -- GitLab