Using Persistent TCP points in script calculations
-
@phildunlap said in Using Persistent TCP points in script calculations:
@psysak said in Using Persistent TCP points in script calculations:
You know what, nevermind :) I'm going to do my calculations in the edge from now on.
Ha!
Well, for posterity, the easiest setup for a meta point across a persistent TCP connection is to disable real time publishing (or just not save it), have frequent data syncs, and set the meta point to run on LOGGED events. The meta point can only be expected to update in that setup at each sync. But, computing things at the lowest level that has all the information is often a good distributed computing model.
You're awesome man, thanks for all the help :) I'll play around with that as well now that I have it
Certainly :D
Only issue I see with that Phil is communication loss and if you get an extended outage. If I were to go down for an hour then all the sync'd data would cause the same issue again. My thought was in that case run a script which doesn't rely on the LOGGED trigger but rather just manually steps through the source points values, keeping track of what the last one it processed was, which can just be accomplished by comparing what the last timestamps for each (meta and source) are.
-
The same issue being that point values were queued, then referred to before they were actually stored?
That should only have been an issue with backdated points, so when you're also saving the realtime data that backdate area exists because the realtime data got processed first and produced a current value. In a sync, it should go from the older to the newer, and it should log all those sync'ed values quite quickly. You didn't experience the timing issue when you had a separate point doing your realtime, I thought - only when I guided you to saving the real time data into the same meta point and publishing/saving on the LOGGED event did it become an issue. Right?
-
Hey, I'll have a think about what you asked in a bit I just have another question right now. In that META script, is there a way to prevent a value being pushed into the history for that point each time the script runs? Ie, the last statement, return p.value, will push a value in the database for that point. Can NOT have a value returned?
-
Yes. As of Mango 3.2 set point event handler scripts, point link scripts, and meta point scripts can all
return UNCHANGED;
to indicate no value should be set forth.
-
@phildunlap said in Using Persistent TCP points in script calculations:
return UNCHANGED;
At some point I will find a question you cannot answer!
-
Bring it on :P
-
Interesting, I'm still getting the same errors as before even though I tried changing the script so it doesn't rely on LOGGED or anything like that. I'm literally pulling the data right out of the database
if(pulse.lastValue().time > my.lastValue().time + 15000) { var list = pulse.pointValuesSince(my.lastValue().time + 5000); for (var i=0; i < list.length; i++) { my.set(list*.doubleValue * pfactor * tfactor, list*.time); } } return UNCHANGED;
Now I get this error, which is the same as before
'MORGUARD': Script error in point "MORGUARD - EO00026SW_BIERMARKTM3": TypeError: Cannot get property "time" of null in at line number 31 in at line number 31Add commentOh well... That was my last attempt, I'll move it all to the edge devices now.
-
The issue is that the meta point doesn't have any values, so
my.lastValue()
is null, and it cannot have a.time
.One can initialize a meta point like this by either setting a value to it, or putting a little handling in the point, like,
if(my.lastValue() === null) { //TIMESTAMP = new Date(2018, 1, 1).getTime(); //When does your point begin? //return 0; //What does it begin at? //Edit: I just remembered, you could also do, my.set(0, new Date(2018, 1, 1).getTime()); //and then carry on with the script. //be sure your meta point is settable! }
-
Noo way! If that's the issue I'm gonna have some kind of egg on my face haha. Classic rookie mistake not validating this.
K I'm going to poke this into all my points and see how it feels about it.
-
I did that on purpose just to see how well you knew your product.......
-
And I wrote
getPointValuesSince
instead ofpointValuesSince
the first time to ensure you had something to correct... yes... :D -
Huh, I'm getting odd results Phil.
And there's time ranges with no issues at all. No errors now though. The only thing I can think of is a timestamp that I'm not aware of which affects the number of data points I get back.
I was hopeful!
My code looks like this now, triggered every 15mins.
if(pulse.lastValue() === null) { return UNCHANGED; } if(my.lastValue() === null) { my.set(0, new Date(2017, 1, 1).getTime()); } if(pulse.lastValue().time > my.lastValue().time + 15000) { var list = pulse.pointValuesSince(my.lastValue().time + 5000); for (var i=0; i < list.length; i++) { my.set(list*.doubleValue * pfactor * tfactor, list*.time); } } return UNCHANGED;
I've turned on TRACE logging for this script, hopefully I can see what's going on.
Saga continues, Empire Strikes Back episode.
-
My first thought, pardon the asking, is if your source point has values for that time period.
Also, my offhand
new Date()
was somewhat off, the month field is zero indexed, so,
new Date(2017, 0, 1).getTime(); //Jan 1 2017 server timezone
-
Hey, absolutely valid question and yes they do have data for those missing chunks. I also did notice that it was a month off but I'm okay with that I don't have any data prior to middle of last year anyway. Script runs every 15 minutes and I enabled the trace logging a while ago so hopefully when I go back and look at it this afternoon I'll see something useful. I forgot to mention as well that I trigger every 15 minutes starting at 2 minutes past the hour that way hopefully everything is synced properly but it shouldn't matter anyway cuz that scription catch any change. I believe you mentioned that the historical synchronisation through this mechanism starts with the oldest date of first is that correct?
-
Yes, values in the history sync are processed oldest to newest.
I wouldn't expect that cron to change anything.
-
Let me ask you this, are execution conditions additive or exclusive? So if I have context update logged, a point is set to update context AND a CRON is setup what happens? I just realized I left a point updating context in that script so am experimenting with that now.
-
Additive-ish; a meta point executing every 15 seconds with four point updates in a minute (to a point that is set to update context, with an update event that has occurred) will execute eight times, unless a point update is at the same millisecond as the cron commanded. Then whichever execution arrived second will not be performed.
-
LOL this is all I get from the TRACE logs for the meta point
INFO 2018-01-16 11:15:46,365 - Data point started
You think more logs might still be buffered and haven't purged to file yet? Or is this all I should get
-
Do you call to
LOG.debug("I'm here in my script, doing this.");
at all? Or, any other log level? -
Ooooohhhh I see, that logging is manually controlled. I thought it was system level logging where it would print stuff out itself. Got ya, I can add some stuff to see what results I get.