Converting a tags() output into a dict
Say you had a list of tag paths like this:
- AreaA/P001/Sts/Status
- AreaA/P002/Sts/Status
- AreaA/P003/Sts/Status
and you want to produce a dict with the equipment name and status tag value, e.g.
{
'P001': 'Running',
'P002': 'Stopped', :face_with_hand_over_mouth:
'P003': 'Running'
}
. You can use:
view.custom.tagPaths: <your tag list>
view.custom.pumpStatuses:
asMap(
forEach(
tags({view.custom.tagPaths}),
transform(split(it()[0], '/'), value()[len(value())-3, 0]),
it()[1]
)
)
PS. I'm sure someone will tell me there's a simpler way...
Phil: I would put the tags() function directly as the source for the forEach(). Just the actual list of tag paths would be in the custom prop. I would use the parsePath() function to extract the tag path inside the loop, and split just that part--otherwise you cannot use the first element when necessary. If you need more than one object level, you can use grouping on partial tag paths.
Nick: oh, using tag in the pumpStatuses expression is actually what I did do in reality, I just bungled it up here
I need to look into your parsePath as it's currently a mystery to me!