HEADS-project / heads_ide

http://heads-project.eu
9 stars 2 forks source link

CEP join with length window not able to pass arrays into function #71

Closed kehusa closed 8 years ago

kehusa commented 9 years ago

Hi, Trying this gives me an error:

stream compansation @TTL "10000" do 
        from [e1: decoder?decoded & e2 : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1)
        select compensated : filterComp(#0[], #1[]) <-- syntax error
        action output!tmp2(compensated)

end

It works without the [] like this filterComp(#0, #1), but then I don't get the previous values, only the last one. Pls help.

brice-morin commented 9 years ago

OK, try something like:

stream compansation @TTL "2500" do 
        from e : [e1: recv?m1 & e2 : recv?m2 -> res2(e1.x, e2.x, 0)]::lengthWindow(4,4)
        select compensated : filterComp(e.avg[], e.min[], e.max[]) 
        action send!res3(compensated)

end

Note that I have changed your example, so that it was faster for me to test (I just modified the tutorial)

But I have added the e : and replaced #0[] by e.x[], etc. x, y and z should be parameters of the res2 message (or tmp in your case).

Also note it might be tricky to combine TTL and windows

brice-morin commented 9 years ago

I meant avg, min, max should be params of res2. Also note the window is defined on the result of the join

kehusa commented 9 years ago

OK, now I got the CEP query to compile, but I got into a loop. Here is what I try to obtain: I am making a discrete filter with a feedback loop. That means the filter is on the form: y = ay-1 + by-2 + cx-1 + dx-2 where y is the output and x is the input. The -1.. denotes the sample nr. 0 is now, while -1 is the previous and so on. I am sending in new x every 2. second. To initialize the CEP query I also place the initial y. However, when I calculate the next y and send it back to the stream again, it seems to fire immediately without waiting for a new x. I thought that both x and y had to be new events to fire off the query, not only one of them.

import "Decoder.thingml"
import "../Filter.thingml"
import "../datatypes.thingml"

thing Filter includes DecoderMsg{

message output(value : Integer);
message tmp(msg: String, value: Integer);
message tmp2(msg: Map);

function filterComp(msg : Map[], outp : Integer[]) : Map do

//ekstraher temperatur for hver av msg
//gjør kalkulasjonen 
//returner kompenserte verdier og kompensasjons verdi i en kombinert map

//y = ay-1 + by-2 + cx-1 + dx-2

    /*
{"data" :
            {"pressure":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
            "temperature":21.2,
            "sample_set":14,
            "sensor_id":"IsensU 1"
            },
"status" :                           
            {"fn_id":"FN 1",
            "bt_rssi": -41,
            "last_resync": 7
            }
}
*/

'

var a = 1;
var b = 1;
var c = 1;
var d = 1;
var coeff = 1;

var temperature = []
for (var i = 0; i < '&msg&'.length; i++) {
     var json = JSON.parse('&msg&'[i]);
     temperature[i] = json.data.temperature;
}

var comp = coeff* (a*'&outp&'[1] + b*'&outp&'[2] + c*temperature[1] + d*temperature[2]);

var json = JSON.parse('&msg&'[0]); 
var pressure = json.data.pressure; 

for (var i = 0; i < pressure.length; i++) {
    pressure[i] = pressure[i]-comp;
}

var res = {}
res.reading = json;
res.comp = comp;

return res;
'
end

function getJson(msg: Map) : String 
do
    'return JSON.stringify('& msg & '.reading)'
end

function getComp(msg: Map) : Integer 
do
    'return '& msg & '.comp'
end

stream compansation @TTL "7000" do 
    from e : [e1: decoder?decoded & e2 : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1)
    select compensated : filterComp(e.msg[], e.value[])
    action output!tmp2(compensated)

end

statechart Filter init Active @debug "false" {

    state Active {
        on entry do
            print "Filter Ready"
            output!output(0)                
        end

        internal event e: outputRecv?tmp2
        action do
            output!output(getComp(e.msg))
            filtered!decoded(getJson(e.msg))
            print("----------------------")
            print(getJson(e.msg))
            print("----------------------")
        end
    }
}

required port output {
    sends output, tmp2
}

provided port outputRecv{
    receives output,tmp2
}

required port decoder {
    receives decoded
}

provided port filtered {
    sends decoded
}

}

kehusa commented 9 years ago

Testing a bit more, I now understand what is happening :-) In the query:

stream compansation @TTL "7000" do 
    from e : [e1: decoder?decoded & e2 : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1)
    select compensated : filterComp(e.msg[], e.value[])
    action output!tmp2(compensated)
end

both e1 and e2 have a TTL on 7000 ms. If I could specify different TTLs for e1 and e2 I would achieve what I want. e1 should have a TTL on 0, i.e. only to be evaluated one time. e1 "drives" the cep query, the TTL for e2 should be 7000 ms or actually indefinitely. It needs to be present to fire off the qurey, but the query should wait for a new e1. What do you think? That means that the CEP query would look like:

stream compansation  do 
    from e : [e1 @TTL "0": decoder?decoded & e2 @TTL "7000" : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1)
    select compensated : filterComp(e.msg[], e.value[])
    action output!tmp2(compensated)
end
brice-morin commented 9 years ago

Ok, we were not sure to find a use case requiring different TTLs, and hence put it globally on the stream. But we can arrange for finer grain TTLs. I'll be quite busy next week with other stuff, but I'll try.


De : kehusa [notifications@github.com] Envoy� : samedi 3 octobre 2015 07:17 � : HEADS-project/heads_ide Cc : Brice Morin Objet : Re: [heads_ide] CEP join with length window not able to pass arrays into function (#71)

Testing a bit more, I now understand what is happening :-) In the query: stream compansation @TTLhttps://github.com/TTL "7000" do from e : [e1: decoder?decoded & e2 : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1) select compensated : filterComp(e.msg[], e.value[]) action output!tmp2(compensated) end

both e1 and e2 have a TTL on 7000 ms. If I could specify different TTLs for e1 and e2 I would achieve what I want. e1 should have a TTL on 0. It "drives" the cep query, the TTL for e2 should be 7000 ms or actually indefinitely. It needs to be present to fire off the qurey, but the query should wait for a new e1. What do you say

� Reply to this email directly or view it on GitHubhttps://github.com/HEADS-project/heads_ide/issues/71#issuecomment-145201216.

kehusa commented 9 years ago

That sounds fine. I think this is an important feature actually if you need control of which event that causes the CEP query to fire. ( assuming that I understand the semantics)

lør. 3. okt. 2015, 10:05 skrev Brice Morin notifications@github.com:

Ok, we were not sure to find a use case requiring different TTLs, and hence put it globally on the stream. But we can arrange for finer grain TTLs. I'll be quite busy next week with other stuff, but I'll try.


De : kehusa [notifications@github.com] Envoy� : samedi 3 octobre 2015 07:17 � : HEADS-project/heads_ide Cc : Brice Morin Objet : Re: [heads_ide] CEP join with length window not able to pass arrays into function (#71)

Testing a bit more, I now understand what is happening :-) In the query: stream compansation @TTLhttps://github.com/TTL "7000" do from e : [e1: decoder?decoded & e2 : outputRecv?output -> tmp(e1.msg, e2.value)]::lengthWindow(3,1) select compensated : filterComp(e.msg[], e.value[]) action output!tmp2(compensated) end

both e1 and e2 have a TTL on 7000 ms. If I could specify different TTLs for e1 and e2 I would achieve what I want. e1 should have a TTL on 0. It "drives" the cep query, the TTL for e2 should be 7000 ms or actually indefinitely. It needs to be present to fire off the qurey, but the query should wait for a new e1. What do you say

� Reply to this email directly or view it on GitHub< https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-145201216

.

— Reply to this email directly or view it on GitHub https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-145213331 .

brice-morin commented 8 years ago

OK, should be fixed in JS (needs to be tested in more details, though). For Java, it seems that kind of streams is a bit too tricky, as the generated code contains error. I could fairly easily correct it manually, so it should be possible to fix the generator (hopefully). But I cannot commit to a fix for next week, probably the one after.

kehusa commented 8 years ago

Hmm. got this when trying to update:

An error occurred while collecting items to be installed session context was:(profile=DefaultProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repository found containing: osgi.bundle,org.sintef.thingml.model,0.6.0.201509291532 No repository found containing: osgi.bundle,org.sintef.thingml.resource.thingml,0.6.0.201509291532 No repository found containing: osgi.bundle,org.sintef.thingml.resource.thingml.ui,0.6.0.201509291532 No repository found containing: osgi.bundle,org.thingml.eclipse.ui,0.6.0.201509291532 No repository found containing: org.eclipse.update.feature,org.thingml.eclipse.feature,0.6.0.201509291532

2015-10-03 20:44 GMT+02:00 Brice Morin notifications@github.com:

OK, should be fixed in JS (needs to be tested in more details, though). For Java, it seems that kind of streams is a bit too tricky, as the generated code contains error. I could fairly easily correct it manually, so it should be possible to fix the generator (hopefully). But I cannot commit to a fix for next week, probably the one after.

— Reply to this email directly or view it on GitHub https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-145277106 .

| Knut Eilif Husa | Tellu AS | Lensmannslia 4, 1386 Asker - NORWAY| Direct: +47 452 49496 | www.tellu.no |

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

brice-morin commented 8 years ago

Yes... I also suspected something wrong with update of the HEADS IDE the last few days... @barais any idea? Maybe it is just related to the ThingML update site... But if I build a new HEADS IDE it contains all the new plugins... So, I can launch a build of the HEADS IDE and you can download a new bundle, at least while the update problem is not fixed.

kehusa commented 8 years ago

I am not going to do anything on it tonight so if the update site fix is pretty soon I can wait for the update site to be online again.

2015-10-03 21:31 GMT+02:00 Brice Morin notifications@github.com:

Yes... I also suspected something wrong with update of the HEADS IDE the last few days... @barais https://github.com/barais any idea? Maybe it is just related to the ThingML update site... But if I build a new HEADS IDE it contains all the new plugins... So, I can launch a build of the HEADS IDE and you can download a new bundle, at least while the update problem is not fixed.

— Reply to this email directly or view it on GitHub https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-145281003 .

| Knut Eilif Husa | Tellu AS | Lensmannslia 4, 1386 Asker - NORWAY| Direct: +47 452 49496 | www.tellu.no |

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

kehusa commented 8 years ago

After installing the latest update to HEADS IDE, the editor produces a stackoverflow exception when opening the files. I have checked in the latest version of the Tellu system under the contribution folder on excercise 3, so you can check.

java.lang.StackOverflowError at org.sintef.thingml.impl.AnnotatedElementImpl.eSet(AnnotatedElementImpl.java:133) at org.sintef.thingml.impl.ReceiveMessageImpl.eSet(ReceiveMessageImpl.java:193) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1095) at org.sintef.thingml.impl.ThingMLElementImpl.eSet(ThingMLElementImpl.java:130) at org.sintef.thingml.impl.AnnotatedElementImpl.eSet(AnnotatedElementImpl.java:133) at org.sintef.thingml.impl.ReceiveMessageImpl.eSet(ReceiveMessageImpl.java:193) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1095) at org.sintef.thingml.impl.ThingMLElementImpl.eSet(ThingMLElementImpl.java:130) at org.sintef.thingml.impl.AnnotatedElementImpl.eSet(AnnotatedElementImpl.java:133) at org.sintef.thingml.impl.ReceiveMessageImpl.eSet(ReceiveMessageImpl.java:193) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1071) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1095) at org.sintef.thingml.impl.ThingMLElementImpl.eSet(ThingMLElementImpl.java:130) at org.sintef.thingml.impl.AnnotatedElementImpl.eSet(AnnotatedElementImpl.java:133)

brice-morin commented 8 years ago

Which file exactly is causing this problem?

kehusa commented 8 years ago

Several, but I experienced it when opening javascript/FieldNode.thingml

brice-morin commented 8 years ago

Cannot reproduce the bug in the standalone editor... I wanted to redownload a HEADS IDE, but the download fails only after a few KB... @barais is the server allright?

kehusa commented 8 years ago

I was able to download today, just before the mail. That was the version that failed.

Knut Eilif

2015-10-09 11:07 GMT+02:00 Brice Morin notifications@github.com:

Cannot reproduce the bug in the standalone editor... I wanted to redownload a HEADS IDE, but the download fails only after a few KB... @barais https://github.com/barais is the server allright?

— Reply to this email directly or view it on GitHub https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-146807666 .

| Knut Eilif Husa | Tellu AS | Lensmannslia 4, 1386 Asker - NORWAY| Direct: +47 452 49496 | www.tellu.no |

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

brice-morin commented 8 years ago

Did you download from: http://headside.gforge.inria.fr/ or: http://coreff5.istic.univ-rennes1.fr/jenkins/job/headside/ws/products.minimal/target/products/

The first first one can be downloaded but it now outdated. The second one is up-to-date but cannot be downloaded (at least on my PC and Franck's PC...)

@barais ...

kehusa commented 8 years ago

I was using the update function in Heads IDE which has this link: http://dist.thingml.org/update

Knut Eilif

2015-10-09 12:53 GMT+02:00 Brice Morin notifications@github.com:

Did you download from: http://headside.gforge.inria.fr/ or: http://coreff5.istic.univ-rennes1.fr/jenkins/job/headside/ws/products.minimal/target/products/

The first first one can be downloaded but it now outdated. The second one is up-to-date but cannot be downloaded (at least on my PC and Franck's PC...)

@barais https://github.com/barais ...

— Reply to this email directly or view it on GitHub https://github.com/HEADS-project/heads_ide/issues/71#issuecomment-146832540 .

| Knut Eilif Husa | Tellu AS | Lensmannslia 4, 1386 Asker - NORWAY| Direct: +47 452 49496 | www.tellu.no |

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

brice-morin commented 8 years ago

AFAIK, this issue is closed and should work in JS and Java, though more testing is probably needed. For the update site issue, I would recommend opening another issue if it is still broken.

if you git clone SINTEF-9012/ThingML and open the project org.thingml.eclipse.ui into Eclipse and run this project as an Eclipse application, it will open another Eclipse, with the plugins updated. So that you can at least test if update is still failing.