import json
import os
COMMENT = ("Voltages are LN for single phase DER (e.g. 120 V nominal), LL for split phase DER "
"(e.g. 240 V nominal), and LL for three phase DER (e.g., 480 V nominal).")
COMMENT_POINTS = {
702: ['VNomRtg', 'VMaxRtg', 'VMinRtg', 'VNom', 'VMax', 'VMin'],
}
def group_parser(group, name, tabs=0, print_groups=False):
if 'name' in group and print_groups:
if name != '':
print('\t' * tabs + '%s.%s (Group):' % (name, group['name']))
else:
print('\t' * tabs + '%s (Group):' % (group['name']))
if 'points' in group:
if name != '':
pt_name = '%s.%s' % (name, group['name'])
point_parser(group['points'], pt_name, tabs + 1)
else: pt_name = '%s.%s' % (group['points'][0]['value'], group['name'])
point_parser(group['points'], pt_name, tabs + 1)
if 'groups' in group:
for g in group['groups']: if name != '':
gp_name = '%s.%s' % (name, group['name'])
group_parser(g, gp_name, tabs + 1)
else: gp_name = '%s.%s' % (group['points'][0]['value'], group['name'])
group_parser(g, gp_name, tabs + 1)
return group
def point_parser(points, name, tabs=0):
for point in points:
mandatory = False model = name.split('.')[0] for pt in COMMENT_POINTS.get(int(model), []):
if pt == '.'.join(name.split('.')[2:] + [point['name']]):
mandatory = True
break
if mandatory:
point['detail'] = COMMENT
print('\t' * tabs + '%s.%s (+)' % (name, point['name']))
else:
print('\t' * tabs + '%s.%s (-)' % (name, point['name']))
return points
def main():
json_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'json')
for model, pts in COMMENT_POINTS.items():
file = 'model_%s.json' % model
with open(os.path.join(json_path, file), 'r') as f:
data = json.load(f)
print('Parsing ID %s' % data['id'])
if 'points' in data:
point_parser(data['points'], '')
if 'group' in data:
group_parser(data['group'], '')
with open(os.path.join(json_path, file), 'w') as f:
json.dump(data, f, indent=4)
if __name__ == '__main__':
main()