-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodel.xml
More file actions
130 lines (127 loc) · 5.41 KB
/
model.xml
File metadata and controls
130 lines (127 loc) · 5.41 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<project heartbeat-interval="1" name="aggregate" pubsub="auto" threads="1">
<metadata>
<meta id="layout">{"cq1":{"Aggregate_Normal":{"x":295,"y":335},"Aggregate_Timed":{"x":765,"y":335},"Copy_EventTime_Sliding":{"x":765,"y":200},"Copy_SystemTime_Sliding":{"x":295,"y":195},"Source":{"x":530,"y":50}}}</meta>
<meta id="studioUploadedBy">anonymous</meta>
<meta id="studioUploaded">1759830397071</meta>
<meta id="studioModifiedBy">anonymous</meta>
<meta id="studioModified">1759831960865</meta>
<meta id="studioTags">Example</meta>
</metadata>
<contqueries>
<contquery name="cq1">
<windows>
<window-source index="pi_EMPTY" insert-only="true" name="Source">
<schema>
<fields>
<field name="motor" type="string" key="true"/>
<field name="time" type="stamp" key="true"/>
<field name="vibration" type="double"/>
</fields>
</schema>
<connectors>
<connector class="python" name="input_publisher">
<properties>
<property name="type"><![CDATA[pub]]></property>
<property name="maxevents"><![CDATA[10]]></property>
<property name="interval"><![CDATA[1 second]]></property>
<property name="init"><![CDATA[init]]></property>
<property name="publish"><![CDATA[publish]]></property>
<property name="code"><![CDATA[import esp
import os
lines = []
def init():
global lines
project_home = os.environ['ESP_PROJECT_HOME']
inputFile = f"{project_home}/test_files/input.csv"
print(inputFile)
with open(inputFile, 'r') as file:
lines = file.readlines()
count = 1
def publish():
global count
event_data = {}
fields = lines[count].split(',')
event_data['motor'] = fields[2]
event_data['time'] = fields[3]
event_data['vibration'] = fields[4]
count += 1
done = False
if(count >= len(lines)):
done = True
return {
"events": event_data,
"done": done
}
]]></property>
</properties>
</connector>
</connectors>
</window-source>
<window-copy name="Copy_SystemTime_Sliding">
<retention type="bytime_sliding"><![CDATA[5 seconds]]></retention>
</window-copy>
<window-copy name="Copy_EventTime_Sliding">
<retention field="time" type="bytime_sliding"><![CDATA[10 seconds]]></retention>
</window-copy>
<window-aggregate name="Aggregate_Timed">
<schema>
<fields>
<field key="true" name="motor" type="string"/>
<field name="time" type="stamp"/>
<field name="vibration" type="double"/>
<field name="timed_avg_vibration" type="double"/>
<field name="timed_count" type="int64"/>
<field name="timed_max" type="double"/>
<field name="timed_min" type="double"/>
<field name="timed_sum" type="double"/>
</fields>
</schema>
<output>
<field-expr><![CDATA[ESP_aLast(time)]]></field-expr>
<field-expr><![CDATA[ESP_aLast(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aAveTimed(vibration, 5)]]></field-expr>
<field-expr><![CDATA[ESP_aCountTimed(5)]]></field-expr>
<field-expr><![CDATA[ESP_aMaxTimed(vibration, 5)]]></field-expr>
<field-expr><![CDATA[ESP_aMinTimed(vibration, 5)]]></field-expr>
<field-expr><![CDATA[ESP_aSumTimed(vibration, 5)]]></field-expr>
</output>
</window-aggregate>
<window-aggregate name="Aggregate_Normal">
<schema>
<fields>
<field name="motor" type="string" key="true"/>
<field name="time" type="stamp"/>
<field name="vibration" type="double"/>
<field name="avg_vibration" type="double"/>
<field name="count" type="int32"/>
<field name="first_vibration" type="double"/>
<field name="lag_vibration" type="double"/>
<field name="max_vibration" type="double"/>
<field name="min_vibration" type="double"/>
<field name="std_vibration" type="double"/>
<field name="sum_vibration" type="double"/>
</fields>
</schema>
<output>
<field-expr><![CDATA[ESP_aLast(time)]]></field-expr>
<field-expr><![CDATA[ESP_aLast(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aAve(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aCount()]]></field-expr>
<field-expr><![CDATA[ESP_aFirst(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aLag(vibration, 1)]]></field-expr>
<field-expr><![CDATA[ESP_aMax(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aMin(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aStd(vibration)]]></field-expr>
<field-expr><![CDATA[ESP_aSum(vibration)]]></field-expr>
</output>
</window-aggregate>
</windows>
<edges>
<edge source="Source" target="Copy_SystemTime_Sliding"/>
<edge source="Source" target="Copy_EventTime_Sliding"/>
<edge source="Copy_EventTime_Sliding" target="Aggregate_Timed"/>
<edge source="Copy_SystemTime_Sliding" target="Aggregate_Normal"/>
</edges>
</contquery>
</contqueries>
</project>