forked from fledge-iot/fledge-filter-python35
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadings35.py
More file actions
68 lines (54 loc) · 1.52 KB
/
readings35.py
File metadata and controls
68 lines (54 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Fledge filtering for readings data
using Python 3.5
"""
__author__ = "Massimiliano Pinto"
__copyright__ = "Copyright (c) 2018 Dianomic Systems"
__license__ = "Apache 2.0"
__version__ = "${VERSION}"
import sys
import json
"""
Filter configuration set by set_filter_config(config)
"""
"""
filter_config, global variable
"""
filter_config = dict()
"""
Set the Filter configuration into filter_config (global variable)
Input data is a dict with 'config' key and JSON string version wit data
JSON string is loaded into a dict, set to global variable filter_config
Return True
"""
def set_filter_config(configuration):
print(configuration)
global filter_config
filter_config = json.loads(configuration['config'])
return True
"""
Method for filtering readings data
Input is array of dicts
[
{'reading': {'power_set1': '5980'}, 'asset_code': 'lab1'},
{'reading': {'power_set1': '211'}, 'asset_code': 'lab1'}
]
Input data:
readings: can be modified, dropped etc
Output is array of dict
"""
def readings35(readings):
# Get list of asset code to filter
if ('asset_code' in filter_config):
asset_codes = filter_config['asset_code']
else:
asset_codes = []
for elem in readings:
print("IN=" + str(elem))
reading = elem['reading']
# Apply some changes: add 100 to all datapoints value
for key in reading:
newVal = reading[key] + 100
reading[key] = newVal
print("OUT=" + str(elem))
return readings