system.kanoa.utilities.convertDatasetToDict(data, keyCol, keyValue)
Given the name of a key column or list of key columns, and value column, this function will convert a dataset into a dictionary of key value pairs if valueCol is None, all data columns will be returned as values for each key
Parameters
data Dataset: Dataset to be converted
keyCol List of Strings: Can be a string i.e. 'configName' or list of strings to concatenate i.e. ['plantId', 'configName'])
keyValue String: i.e. 'configValue' or null to return all column values in the dictionary
Returns
convertedDict dictionary
Example
data = system.kanoa.asset.getAssets({'assetTypeName': 'site'})
print system.kanoa.utilities.convertDatasetToDict(data, 'assetName', 'assetId')
> {'Adelaide Hills': 16, 'Napa Valley': 10, 'Vernon': 2480, 'Box Plant': 900, 'Tacoma': 1974, 'Buffalo Bakery': 506, 'Jacksonville Juices': 1951}
data = system.kanoa.asset.getAssets({'assetTypeName': 'enterprise'})
print system.kanoa.utilities.convertDatasetToDict(data, ['assetName', 'assetTypeName'], 'assetId')
> {('Kanoa Box Co', 'enterprise'): 899, ('Kanoa Industries', 'enterprise'): 9}
data = system.kanoa.asset.getAssets({'assetId': 899})
print system.kanoa.utilities.convertDatasetToDict(data, 'assetName', None)
> {'Kanoa Box Co':
{
'assetTypeId': 4,
'assetTypeName': u'enterprise',
'targetThreshold': None,
'oeeType': None,
'oee': None,
'enabled': True,
'path': u'Kanoa Box Co',
'assetId': 899,
'assetPath': u'Kanoa Box Co',
'a': None,
'assetGroupName': None,
'tzOffset': None,
'timeZone': None,
'displayPath': u'Kanoa Box Co',
'assetGroupId': None,
'parentId': None,
'p': None,
'q': None,
'tagPath': u'[Kanoa]/Kanoa Box Co',
'sortOrder': 3,
'assetName': u'Kanoa Box Co',
'assetGroupColor': None,
'assetTypePath': u'enterprise',
'iconPath': u'kanoa/enterprise'
}
}