Repository navigation
Expand file tree
/
Copy pathmodel.xml
More file actions
74 lines (72 loc) · 2.96 KB
/
Copy pathmodel.xml
File metadata and controls
74 lines (72 loc) · 2.96 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
<project name="lua_state" index="pi_EMPTY" pubsub="none" threads="4" heartbeat-interval="1" luaroot="@ESP_PROJECT_OUTPUT@/luaroot">
<description><![CDATA[This project demonstrates how to maintain event state in Lua and use it to generate events. It streams stock trade data into the model and uses a Lua window to generate events when a new symbol price exceeds the current maximum price for that symbol.]]></description>
<metadata>
<meta id="studioUploadedBy">anonymous</meta>
<meta id="studioUploaded">1759178990791</meta>
<meta id="studioModifiedBy">anonymous</meta>
<meta id="studioModified">1759179548321</meta>
<meta id="layout">{"cq":{"generateEvents":{"x":50,"y":175},"trades":{"x":50,"y":50}}}</meta>
<meta id="studioTags">Example</meta>
</metadata>
<contqueries>
<contquery name="cq" trace="generateEvents">
<windows>
<window-source name="trades">
<schema>
<fields>
<field name="id" type="int64" key="true"/>
<field name="symbol" type="string"/>
<field name="currency" type="int32"/>
<field name="time" type="int64"/>
<field name="msecs" type="int32"/>
<field name="price" type="double"/>
<field name="quant" type="int32"/>
<field name="venue" type="int32"/>
<field name="broker" type="int32"/>
<field name="buyer" type="int32"/>
<field name="seller" type="int32"/>
<field name="buysellflg" type="int32"/>
</fields>
</schema>
<connectors>
<connector class="fs" name="input_lua_state">
<properties>
<property name="type"><![CDATA[pub]]></property>
<property name="rate"><![CDATA[1000]]></property>
<property name="fsname"><![CDATA[@ESP_PROJECT_HOME@/test_files/luaStateInput.csv]]></property>
<property name="fstype"><![CDATA[csv]]></property>
</properties>
</connector>
</connectors>
</window-source>
<window-lua events="create" name="generateEvents">
<schema>
<fields>
<field name="symbol" type="string" key="true"/>
<field name="max_price" type="double"/>
</fields>
</schema>
<copy/>
<use><![CDATA[symbol,price]]></use>
<code><![CDATA[local symbolData = {}
function create(data)
local event = nil
local maxPrice = symbolData[data.symbol]
if (maxPrice == nil or data.price > maxPrice) then
symbolData[data.symbol] = data.price
event = {}
event.symbol = data.symbol
event.max_price = data.price
event._opcode = "upsert"
end
return(event)
end
]]></code>
</window-lua>
</windows>
<edges>
<edge source="trades" target="generateEvents"/>
</edges>
</contquery>
</contqueries>
</project>