How to setup and event on rate of change?
-
OK. I found how to create a meta script. It's actually a data source. I'll give your code a try out. Thanks again.
-
Data will be coming from it, won't it? :D
A solution some people use for noisy data, to avoid what I was talking about, is to just use averages from time periods to compare instead of raw data, so,
var period = 300000 //5*60*1000 Five minutes var now = new Date(); var start = now.getTime() - period; var middle = now.getTime() - period/2; if( Math.abs( p.getStats(middle, now).average - p.getStats(start, middle).average ) > 5 ) //Threshhold return true; return false;
Depending on your needs or thoughts on your data.
-
Just trying this now and when I input the script and then click save, I get this error at the bottom.
invalid return at line -1
I've selected a suitable data point and set its name to p for this test.
-
Are you using the scripts as posted or as they arrived in an email notification?
I am able to run all of these with a numeric point for p. That looks like a syntax error, which I think I would get regardless of the code path.
-
Hi Phil, I am using a numerical data point. Here is the screen capture. I modified the script as I only need to detect a falling trend.!!
-
it looks like you are using the scripting data source, instead of a meta data source and putting these scripting in a meta data point.
Scripts are intended for a multiple-output control loop. Scripting data source scripts don't contain return statements, they set a point's value with p.set(value, time) or just p.set(value) for the current time.
This kind of thing, where we're producing a single answer from perhaps multiple inputs, should be a meta point.
-
Ah yes, so I was. Just trying it now but there is an error about a null value on line 4 which seems strange because it would not get to this line unless there was data.
var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds if( data.length <= 1 ) //we have the same edge conditions for our range return false; var firstValue = data[0]; var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than for( var k = 1; k < data.length; k+=1 ) { if( firstValue.value - data[k].value < changeThreshhold) return true; } return false;
-
That is odd....
I would put print(data) at line 2 to investigate. -
I've added that but where do I see the output from this?
-
It would be below the script window, if it ran, where you saw the error. If it didn't, I wonder if you have a global script declared? The global scripts page is this icon:
-
I don't have that icon. Is this a module I need to install or a setting somewhere?
-
I found the module and installed it and the icon is now present. My scripts still don't seem the be running as there is no output from the print(data) statement.
-
No, I was curious if that's where the error was occurring, not telling you that you needed to install it.
Do you get the same error from a very simple script, perhaps just...
return false;
Are you sure your point is in the context as bbl1 (b - b - lower case L - numeral 1)?
-
I am assuming that the variable is based on the area I circled?
-
Yeah, just checking. That script I posted surely runs for me, here's a version of yours with lots of print statements, maybe it will help find the issue?
print("bbl1:"); print(bbl1); var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds print("data:"); print(data); if( data.length <= 1 ) //we have the same edge conditions for our range return false; print("Passed the length condition..."); var firstValue = data[0]; var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than for( var k = 1; k < data.length; k+=1 ) { if( firstValue.value - data[k].value < changeThreshhold) return true; } return false;
If you see no output, I encourage you to 1) check for updates, 2) clear your browsers cache, 3) delete Mango/work/jsp and then try again.
-
Hi Phil, it doesn't seem to run. Nothing appears from the debug. I also deleted the jsp directory and still the same.
-
Are you getting errors in the log, or just on the script's page? Is it still reporting null at line 4? Did you try a very simple script, just
return false;
And see if it reports success result=false?
Well, would it be possible for you to email me the JSON for your Mango and I'll try to find the problem locally? I'd like your whole configuration.
-
Looking at the log file, it is still failing at this line.
var firstValue = data[0];
ERROR 2016-07-29 07:39:00,004 (com.serotonin.m2m2.meta.JavaScriptPointLocatorRT.executeImpl:54) - sun.org.mozilla.javascript.EvaluatorException: Java class "java.util.ArrayList" has no public instance field or method named "0". (<Unknown Source>#9) in <Unknown Source> at line number 9 in <Unknown Source> at line number 9
I export and send you the file.
-
It works fine for me, so, I wonder if it's a Java version issue.
Judging from that error message, I would try using data.get(0) instead of data[0]
Can you run "java -version" on the command line and report the result?
-
It's running on a Centos system and the "java -version" command gives me this error.
Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
I have Mango running as a service on this machine. Java is install and running otherwise Mango won't run.