Skip to content
Snippets Groups Projects
Commit a378d80f authored by Taeyoung Kim's avatar Taeyoung Kim
Browse files

create function that read keys in json(for now very limited and selected) and...

create function that read keys in json(for now very limited and selected) and make empty dictionary that has same key as template json file

Signed-off-by: default avatarTaeyoung Kim <taeyoung.kim@eonerc.rwth-aachen.de>
parent 55cb32e7
No related branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,6 @@ INFO:cimpy.cimimport:CIM object Line created : 11 times ...@@ -76,6 +76,6 @@ INFO:cimpy.cimimport:CIM object Line created : 11 times
INFO:cimpy.cimimport:CIM object SubGeographicalRegion created : 2 times INFO:cimpy.cimimport:CIM object SubGeographicalRegion created : 2 times
INFO:cimpy.cimimport:CIM object BusbarSection created : 13 times INFO:cimpy.cimimport:CIM object BusbarSection created : 13 times
INFO:cimpy.cimimport:CIM object TopologicalIsland created : 2 times INFO:cimpy.cimimport:CIM object TopologicalIsland created : 2 times
INFO:cimpy.cimimport:Created totally 275 CIM objects in 0.022518157958984375s INFO:cimpy.cimimport:Created totally 275 CIM objects in 0.023797273635864258s
...@@ -43,6 +43,7 @@ q = a.makeOneDict() ...@@ -43,6 +43,7 @@ q = a.makeOneDict()
aa = export.DataFrameToJson(q) aa = export.DataFrameToJson(q)
bb= aa.readSampleJson('/home/ubuntu/code/CIM_Read/pyvolt-docker/Data/template') ##due to the path, we need to provide absolute path here bb= aa.readSampleJson('/home/ubuntu/code/CIM_Read/pyvolt-docker/Data/template') ##due to the path, we need to provide absolute path here
cc= aa.extractKeyFromSampleJson(bb)
# Print node voltages # Print node voltages
print("Powerflow converged in " + str(num_iter) + " iterations.\n") print("Powerflow converged in " + str(num_iter) + " iterations.\n")
... ...
......
...@@ -242,7 +242,7 @@ class DataFrameToJson(Exporter): ...@@ -242,7 +242,7 @@ class DataFrameToJson(Exporter):
folder_dir folder_dir
files_dir = glob.glob(os.path.join(folder_dir, '*.json')) files_dir = glob.glob(os.path.join(folder_dir, '*.json'))
print(files_dir)
json_template = dict() json_template = dict()
for file_path in files_dir: for file_path in files_dir:
try: try:
...@@ -254,4 +254,30 @@ class DataFrameToJson(Exporter): ...@@ -254,4 +254,30 @@ class DataFrameToJson(Exporter):
raise Exception(f"Error loading JSON file '{file_path}': {e}") raise Exception(f"Error loading JSON file '{file_path}': {e}")
print("All JSON templates are read") print("All JSON templates are read")
print(json_template)
return json_template return json_template
def extractKeyFromSampleJson(self, json_template):
og_template = json_template
keys = [key for key in json_template.keys() if 'Input' in key and 'mt' in key] #this filters key name that contain 'input' and 'mt'
# template = og_template[keys[1]] #for mtPowerFlowInput
input_pf = keys[1]
# key_for_dict = og_template[input_pf]['mtPowerFlowInput']['busses'][1].keys()
template=dict()
# template = dict.fromkeys(key_for_dict,None)
for k in og_template[input_pf]['mtPowerFlowInput'].keys():
if k == 'baseMVA':
continue
else:
key_for_dict = og_template[input_pf]['mtPowerFlowInput'][k][0].keys()
template[k] = dict.fromkeys(key_for_dict,None)
return template
# for q in iter(og_template[k]['mtPowerFlowInput']['busses'])
# og_template[k]['mtPowerFlowInput']['busses'][1].keys()
return template
...@@ -76,6 +76,6 @@ INFO:cimpy.cimimport:CIM object Line created : 11 times ...@@ -76,6 +76,6 @@ INFO:cimpy.cimimport:CIM object Line created : 11 times
INFO:cimpy.cimimport:CIM object SubGeographicalRegion created : 2 times INFO:cimpy.cimimport:CIM object SubGeographicalRegion created : 2 times
INFO:cimpy.cimimport:CIM object BusbarSection created : 13 times INFO:cimpy.cimimport:CIM object BusbarSection created : 13 times
INFO:cimpy.cimimport:CIM object TopologicalIsland created : 2 times INFO:cimpy.cimimport:CIM object TopologicalIsland created : 2 times
INFO:cimpy.cimimport:Created totally 275 CIM objects in 0.04523348808288574s INFO:cimpy.cimimport:Created totally 275 CIM objects in 0.03974318504333496s
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment