Mango Scripting Data Source and Data Points
-
Hi all,
Looking for help using scripts within a scripting data source. I basically would like to place all of my scripts within one scripting data source and push the results of the script to individual meta data points. I am having some trouble as it seems that I cannot create and save a meta data point without filling out the 'script' and 'external context' fields. I have tried creating data points within the scripting source, however these do not appear under the 'external context' selection field.
Specifically I am looking for a way to count the amount of times numerous binary data points change from '0' to '1' within a set time period (ie. 1 month).
Any help with how to go about doing this (including required java script) is appreciated. Thanks.
Nathan
-
As a quick workaround to save your empty meta point, you can just enter some comment characters in the meta point script:
//
You can also add the 'my' variable to the script context, which is self-referencing, or you could set it to a cron pattern (yearly?) which should allow you to save the meta point.
-
@laona When you add a data point to a Scripting Data Source you don't need to add them into the context like you do other data points. When you create the Scripting Data Point you give it a variable name and can reference this within the script just like other data points.
I think it would make more sense to do this rather then use meta data points but to use the meta data point I think Jeremy has the right idea. Just make sure the meta data point is settable and then save it with a comment.
-
Thanks Joel. I have done as suggested with the scripting source and scripting data point.
When I use the following script in the scripting source area however I am not able to push anything to my data point:abcd = p5111.past(MONTH).get(true).starts;
In this case I have given the variable name 'abcd' to my data numeric and settable data point. and variable 'p5111' is an external context point from my PLC data source.
When I use the scripting source and a meta data point I still am not able to push the value to the point.
When I use the following script within the meta data point however I get the desired result:
return p5111.past(MONTH).get(true).starts;
Also I am unable to use 'return' in the scripting data source without getting an error.
-
@laona,in scripting source,you no need use return, because no place you can return,you just put the value to the point which you want, for example,you want return to point1,you give it a variable name like p1, you write p1.set( the value you returned before) ,then the vaue can put to the point1.
-
Just has hussam has said if the variable name of your scripting data point is" abdc" then your script should be:
abcd.set(p5111.past(MONTH).get(true).starts);
-
Thanks Joel! This worked. However is there any way to make the time period dynamic. Ie. Instead of Month a user within DGLux would be able to select past 'Month, 2months, 3months or year.
I want to try to avoid creating seperate script and seperate variables for each time period.
I also was thinking if this is possible using a historical query table in DGLux? If I set the interval to 0 (when the parameter changes)
and set the period range (dynamic) and I sum the value column I believe I will end up with the count that I want.Am I able to determine the sum of a column using a formula column and script? I have looked into using the rollup widget but have not been able to get anywhere with it.
Thanks,