<br> Definitively. That for sure will cause a problem, because each entry point is like a partition in the data set space.<br> <br> To make this work, just use the "from entry-point":<br><br><p style=""><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> Number( doubleValue > 1.0 ) </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">from</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">accumulate</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">(</span></font><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"></span></font></p>
<p style=""><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> StockTick( $pr : price, symbol == </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"IBM"</span></font><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> ) over window:time( 5m ) from entry-point "StockTick stream",</span></font><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"></span></font></p>
<font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> average( $pr ) )</span></font><br><br><br> []s<br> Edson<br><br><div class="gmail_quote">
2009/5/27 Chris Richmond <span dir="ltr"><<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="blue" lang="EN-US">
<div>
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;">I think the problem is that the stockticks
aren’t being processed unless I use the:</span></font></p>
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">From entry-point
“StockTick stream” </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font></p>
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;">But I can’t combine “from accumulate”
with that from statement successfully in that sample I sent. I think that is
the problem . The sample I sent, none of those ever get processed since it is
not looking at the proper entry point…</span></font></p><div class="im">
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;"> </span></font></p>
<p><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;"> </span></font></p>
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p><font color="navy" size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<div>
<div style="text-align: center;" align="center"><font size="3" face="Times New Roman"><span style="font-size: 12pt;">
<hr align="center" size="3" width="100%">
</span></font></div>
<p><b><font size="2" face="Tahoma"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font size="2" face="Tahoma"><span style="font-size: 10pt; font-family: Tahoma;">
<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b><span style="font-weight: bold;">On
Behalf Of </span></b>Michal Bali<br>
<b><span style="font-weight: bold;">Sent:</span></b> Wednesday, May 27, 2009
11:09 AM<br>
<b><span style="font-weight: bold;">To:</span></b> Rules Users List<br>
<b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] keeping
running stats</span></font></p>
</div>
<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;"> </span></font></p>
</div><p style="margin-bottom: 12pt;"><font size="3" face="Times New Roman"><span style="font-size: 12pt;">Hi Chris,<div><div></div><div class="h5"><br>
<br>
You can use 'accumulate' with sliding time window. Have a look here <a href="http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/ch02.html#d0e1169" target="_blank">http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/ch02.html#d0e1169</a></div>
</div></span></font></p><div><div></div><div class="h5">
<pre><font size="2" face="Courier New"><span style="font-size: 10pt;">rule "Sound the alarm in case temperature rises above threshold"<br>
when<br>
TemperatureThreshold( $max : max )<br>
Number( doubleValue > $max ) from accumulate(<br>
<br>
</span></font></pre><pre><font size="2" face="Courier New"><span style="font-size: 10pt;"> SensorReading( $temp : temperature ) over window:time( 10m ),<br>
average( $temp ) )<br>
then<br>
// sound the alarm<br>
end</span></font></pre>
<p style="margin-bottom: 12pt;"><font size="3" face="Times New Roman"><span style="font-size: 12pt;">The engine will
automatically discard any SensorReading older than 10 minutes and keep the
calculated average consistent.<br>
<br>
Is that what you're looking for?<br>
<br>
Michal<br>
<br>
</span></font></p>
<div>
<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;">2009/5/27 Chris Richmond <<a href="mailto:crichmond@referentia.com" target="_blank">crichmond@referentia.com</a>></span></font></p>
<div link="blue" vlink="purple">
<div>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Hello,</span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">I
have modified the stockTicker fusion example to keep some running stats, you
can see from the rule snippet below that it injects a stats object based on the
symbol then matches them as updates come in later. You can see for now I
am just updating the running counts and outputting the readings count on each
stock tick and this works fine.</span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">What
I would like to do however is only have the running averages,stats object
reflect stock ticks that are still in memory….essentiall only stock tick items
that have not expired. As it is now the count just keeps growing and
growing, I want the count to only reflect the stock ticks within the expiration
time in the past for stock ticks, but I cannot figure out how to make this
happen? Could anyone give me a pointer on how to do this?
How to make the stats object only reflect those stock ticks that have not
expired? I do not know the strategy for this.</span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Thanks,</span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Chris</span></font></p>
<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># tells the engine that a StockTick
instance will assume the</span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># role (semantics) of events and that
the default retention </span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># policy will be 2 minutes </span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">declare</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> StockTick</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> @role( event )</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> @expires( 1m )</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">end</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># One can even declare helper facts to
make rules easier and</span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># simpler to write and maintain</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">declare</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> Statistics</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> symbol : String
@key()</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> average : </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">double</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> readings : </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">int</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> total : </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">double</span></font></b></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">end</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">rule</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"Setup statistics"</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">when</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $c : Company( $s : symbol )</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">not</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">( Statistics( symbol == $s ) )</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">then</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> Statistics s = </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">new</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> Statistics();</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> s.symbol = $s;</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> s.readings = s.readings +
1;</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">insert</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">( s );</span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">end</span></font></b></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># a simple rule to show that it is
possible to join</span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># events from an entry-point (stream)
with facts </span></font></p>
<p><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;"># present in the working memory</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">rule</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"Update stock stats"</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">agenda-group</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"evaluation"</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">lock-on-active</span></font></b></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">when</span></font></b></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $cp : Company( $sb :
symbol )</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $st : StockTick(
symbol == $sb, $pr : price ) </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">from</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> entry-point </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"StockTick stream"</span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $stats :
Statistics( symbol == $sb )</span></font></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">then</span></font></b></p>
<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New";"> </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">modify</span></font></b><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">( $stats ) { readings = readings + 1};</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;">
System.err.println($stats.symbol + </span></font><font color="green" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"readings: "</span></font><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> + $stats.readings);</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">// This shows an update on working memory facts with
data from joined events</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//modify( $cp ) { currentPrice = $pr }</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">// Although events are considered immutable, a
common pattern is to use a class</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">// to represent an event and enrich that event
instance with data derived from other facts/events.</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">// Bellow we "enrich" the event instance
with the percentual change in the price, </span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">// based on the previous price</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//modify( $st ) { delta = $cp.delta }</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//modify( $st ) { readings = 5 }</span></font></p>
<p><font color="black" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></font><font color="olive" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//System.out.println($st.delta)</span></font></p>
<p><b><font color="#960000" size="2" face="Courier New"><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0); font-weight: bold;">end</span></font></b></p>
</div>
</div>
<p style="margin-bottom: 12pt;"><font size="3" face="Times New Roman"><span style="font-size: 12pt;"><br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a></span></font></p>
</div>
<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;"> </span></font></p>
</div></div></div>
</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>