Skip to content

Commit 41df289

Browse files
committed
metric type
Signed-off-by: hwassman <[email protected]>
1 parent 2664935 commit 41df289

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

source/queryHandler/Topo.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Topo(object):
3636
def __init__(self, jsonStr=None):
3737
self.topo = jsonStr
3838
self.__metricsDef = defaultdict(dict) # metrics dictionary, per sensor for all elements in the metadata
39+
self.__metricsType = defaultdict(dict) # metrics types dictionary
3940
self.__levels = defaultdict(dict) # component level priority dictionary, per sensor
4041
self.__ids = {} # fieldIds dictionary
4142
self.__groupKeys = {}
@@ -62,15 +63,15 @@ def _processMetadata(self, metadata):
6263
_components = self.__compTree[label]['componentsMap']
6364
_filters = self.__compTree[label]['filtersMap']
6465

65-
self._parse_topoJSONStr(self.__metricsDef, self.__levels, self.__ids, self.__groupKeys, _components, _filters, metaStr)
66+
self._parse_topoJSONStr(self.__metricsDef, self.__metricsType, self.__levels, self.__ids, self.__groupKeys, _components, _filters, metaStr)
6667
tree_entry = {}
6768
tree_entry['componentsMap'] = _components
6869
tree_entry['filtersMap'] = _filters
6970

7071
# comp_tree[label] = tree_entry
7172
self.__compTree[label] = tree_entry
7273

73-
def _parse_topoJSONStr(self, metrics, levels, ids, groupKeys, components, filters, metaStr):
74+
def _parse_topoJSONStr(self, metrics, metricsType, levels, ids, groupKeys, components, filters, metaStr):
7475
'''
7576
This function parses the 'node' or 'attribute' object found in the given JSON string (metaStr) in
7677
the componets or metrics dictionary. Also the used metric filters (per sensor) will be stored
@@ -80,6 +81,7 @@ def _parse_topoJSONStr(self, metrics, levels, ids, groupKeys, components, filter
8081

8182
field_value = metaStr['fieldLabel']
8283
field_name = metaStr['fieldName']
84+
field_type = metaStr['fieldSemantics']
8385

8486
# check if entity is a component
8587
if metaStr['type'] == 'node':
@@ -88,7 +90,7 @@ def _parse_topoJSONStr(self, metrics, levels, ids, groupKeys, components, filter
8890
# check if metaStr includes next level metaStr
8991
if 'keys' in metaStr and len(metaStr['keys']) > 0:
9092
for metaKey in metaStr['keys']:
91-
self._parse_topoJSONStr(metrics, levels, ids, groupKeys, components, filters, metaKey)
93+
self._parse_topoJSONStr(metrics, metricsType, levels, ids, groupKeys, components, filters, metaKey)
9294

9395
# check if entity is a metric
9496
elif metaStr['type'] == 'attribute':
@@ -100,6 +102,7 @@ def _parse_topoJSONStr(self, metrics, levels, ids, groupKeys, components, filter
100102

101103
if field_name not in iterval(metrics[sensor]):
102104
metrics[sensor][field_id] = field_name
105+
metricsType[field_name] = field_type
103106

104107
if groupKey not in groupKeys:
105108
# parse sensor relevant data f.e. groupKey, filters, levels
@@ -177,6 +180,11 @@ def metricsSpec(self):
177180
''' Returns all defined metrics as dictionary of (metric_name : metric_id) items '''
178181
return self.__metricsDef
179182

183+
@property
184+
def metricsType(self):
185+
''' Returns a dictionary of (metric_name : metric_type) items '''
186+
return self.__metricsType
187+
180188
@property
181189
def getAllEnabledMetricsNames(self):
182190
''' Returns list of all found metrics names'''

0 commit comments

Comments
 (0)