Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Restructuring create_meters (#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
aivanova5 authored May 16, 2023
1 parent b99676c commit c2dfe85
Show file tree
Hide file tree
Showing 21 changed files with 11,957 additions and 110 deletions.
11 changes: 6 additions & 5 deletions converters/json2glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,15 @@ def convert(ifile,ofile,json_type="gridlabd",noclock=False,ignore_globals=None)
# print("CLASSNAME",classname,classdata)
fw.write(f"\nobject {classname}")
fw.write("\n{")
fw.write(f"\n\tname \"{obj_id_sorted.replace(':','_')}\";")
# fw.write(f"\n\tname \"{obj_id_sorted.replace(':','_')}\";")
fw.write(f"\n\tname \"{obj_id_sorted}\";")
for v_id, v_info in data['objects'][obj_id_sorted].items() :
if v_id not in objects_ignore and v_info:
# print(v_id)
if v_id in classdata and type(classdata[v_id]) is dict and classdata[v_id]['type'] == 'object':
v_str = v_info.replace(':','_')
else:
v_str = v_info.replace('"', '\\\"')
# if v_id in classdata and type(classdata[v_id]) is dict and classdata[v_id]['type'] == 'object':
# v_str = v_info.replace(':','_')
# else:
v_str = v_info.replace('"', '\\\"')
if '\n' in v_info :
var_str = f"\n\t{v_id} \"\"\"{v_str}\"\"\";"
else :
Expand Down
45 changes: 45 additions & 0 deletions tools/autotest/check-meters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import difflib
MODEL_NAME = sys.argv[1]
# MODEL_NAME="meters-withloads nodes-withloads notnodes-withloads links-to-meter links-to-triplexmeter link-to-notnode links-to-meter-to-child links-to-triplexmeter-to-child"

FAILED=0
input_file_1=''
input_file_2=''

# for model in MODEL_NAME.split() :
# with open('../'+model+'-meters.glm', 'r') as f1, open(model+'-meters.glm', 'r') as f2:
# for line1, line2 in zip(f1, f2):
# line1 = line1.strip()
# line2 = line2.strip()

# if line1.startswith('guid') or line1.startswith('//'):
# continue

# if line2.startswith('guid') or line2.startswith('//'):
# continue

# if line1 != line2:
# FAILED=FAILED+1
# print('FILE '+ '../'+model+'-meters.glm : ' + line1)
# print('FILE '+ model+'-meters.glm : ' + line2)

def filter_lines(lines):
skip_prefixes = ['guid', '//', 'solver_py_config', '#define pythonpath', '#set pythonpath',
'#define tmp', '#set tmp', '#define kmlhost', '#set kmlhost', '#define datadir',
'#set datadir', 'name', 'global enumeration validto_context', '#set validto_context',
'#define browser', '#set browser']
return [line for line in lines if not any(line.strip().startswith(prefix) for prefix in skip_prefixes)]

for model in MODEL_NAME.split() :
with open('../'+model+'-meters.glm', 'r') as file1, open(model+'-meters.glm', 'r') as file2:
filtered_lines1 = filter_lines(file1.readlines())
filtered_lines2 = filter_lines(file2.readlines())

diff = difflib.unified_diff(filtered_lines1, filtered_lines2, lineterm='')
diff_lines = list(diff)

if diff_lines :
for line in diff_lines:
print(line)
sys.exit(1)
Loading

0 comments on commit c2dfe85

Please sign in to comment.