in sitewise_export_tools/asset_model_exporter.py [0:0]
def case_handler_1st_pass(k,v):
if k == 'type' and isinstance(v, dict):
if 'measurement' in v:
return {'TypeName': 'Measurement'}
if 'transform' in v:
return {'TypeName': 'Transform', 'Transform':v['transform']}
if 'attribute' in v:
return {'TypeName': 'Attribute', 'Attribute':v['attribute']}
if 'metric' in v:
return {'TypeName': 'Metric', 'Metric':v['metric']}
if k == 'value' and isinstance(v, dict):
if 'hierarchyId' in v and 'propertyId' in v:
#Return the new dictionary structure with original IDs...we will replace these in the second pass
return {'PropertyLogicalId':v['propertyId'], 'HierarchyLogicalId':v['hierarchyId']}
if 'propertyId' in v:
#Same as above but only when we find propertyId
return {'PropertyLogicalId':v['propertyId']}
if k == 'assetModelProperties' and isinstance(v, list):
tmp = []
for d in v:
logical_id = re.sub(r'[^A-Za-z0-9]+', '', d['name']).lower()
logical_id_with_hash = logical_id+uuid.uuid4().hex[:8]
tmp.append({**d,**{'LogicalId':logical_id_with_hash}})
#update the property lookup table with the id so we can use it during our second pass
property_logical_id_lookup.update({d['id']:logical_id_with_hash})
return tmp
if k == 'assetModelHierarchies' and isinstance(v, list):
tmp = []
for d in v:
#Create our LogicalIds for Hierarchies and then populate a lookup table that we will use in the second pass.
d['childAssetModelId'] = {'Ref': hierarchy_id_lookup[d['childAssetModelId']]}
logical_id = re.sub(r'[^A-Za-z0-9]+', '', d['name']).lower()
tmp.append({**d,**{'LogicalId':logical_id}})
#update the hierarchy logical id lookup table with the logical_id
hierarchy_logical_id_lookup.update({d['id']:logical_id})
return tmp
else:
return v