Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
Meta Point Help
-
Hi,
Trying to monitor cyclic fatigue on a small project, and can manually do it in excel but it's messy and ideally would like it data logged.
I though the easiest way would be a meta point such as:
if (p445.lastValue(101) > (p445.lastValue(102), (p445.lastValue(100)))); // means the value has hit peak ?? { return 1; } if (p445.lastValue(101) > (p445.lastValue(102), and < (p445.lastValue(100)))); // means the value is still climbing ?? { return 2; } if (p445.lastValue(101) < (p445.lastValue(102), (p445.lastValue(100)))); // means the value has hit trough ?? { return 3; } if (p445.lastValue(101) < (p445.lastValue(102), and > (p445.lastValue(100)))); // means the value is still falling ?? { return 4; }
However this only returns a "1" no matter what, so I obviously have done something wrong.
I was using "lastValue(101)", "lastValue(100)" & "lastValue(102)" only because the point is Persistent TCP (with Live updating) and I didn't want to be looking at the un-updated value. (if that makes sense). So perhaps this is part of the problem??
Or I have gone completely the wrong way around this and I need to be looking at an alternative solution.
Any assistance is as always greatly appreciated,
A picture paints 1000 words:
Cheers!
-
Hi @Pikey4
I believe your first if statement is short-circuiting. Your logical operators are not correct.
eg:
if (p445.lastValue(101) > (p445.lastValue(102), (p445.lastValue(100))));
should be
if (p445.lastValue(101) > (p445.lastValue(102) && p445.lastValue(101)>(p445.lastValue(100));
Might help to read through this site.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators -
@pikey4 said in Meta Point Help:
I was using "lastValue(101)", "lastValue(100)" & "lastValue(102)" only because the point is Persistent TCP (with Live updating) and I didn't want to be looking at the un-updated value. (if that makes sense). So perhaps this is part of the problem??
I didn't understand that. Using lastValue(100) will give you the hundredth value ago. That seems strange to do, and I'm not sure what this explanation is saying. I think I may go about doing something like this by having the meta point activate on a cron and check to see if the point has been updated / sync'ed and it can loop over the values in the next time period, based off the time of the source point and the last time of the meta point.
-
@Pikey4 as @CraigWeb said you have incorrect expressions inside your if statements. Try this -
var targetIndex = 100; var prevVal = p445.lastValue(targetIndex - 1); var thisVal = p445.lastValue(targetIndex); var nextVal = p445.lastValue(targetIndex + 1); if (thisVal > prevVal) { if (thisVal > nextVal) { // peak return 1; } else { // still climbing return 2; } } else { if (thisVal < nextVal) { // trough return 3; } else { // still falling return 4; } }
or a slight variation which you may prefer
var targetIndex = 100; var prevVal = p445.lastValue(targetIndex - 1); var thisVal = p445.lastValue(targetIndex); var nextVal = p445.lastValue(targetIndex + 1); if (thisVal >= prevVal && thisVal >= nextVal) { // peak return 1; } else if (thisVal >= prevVal && thisVal < nextVal) { // still climbing return 2; } else if (thisVal < prevVal && thisVal < nextVal) { // trough return 3; } else { // still falling return 4; }
-
Thanks for helping out @CraigWeb @phildunlap @Jared-Wiltshire ,
I couldn't get it to work with a Persistent TCP data on central server, so set up on an ES on Site and it seems to be tracking good. All the 4's and 1's are lining up where I expect them.
Thanks Again.
I got this to work:
var prevVal = p709.lastValue(2); var thisVal = p709.lastValue(1); var nextVal = p709.lastValue(); if (thisVal >= prevVal && thisVal >= nextVal) { // peak return 4; } else if (thisVal >= prevVal && thisVal < nextVal) { // still climbing return 3; } else if (thisVal < prevVal && thisVal < nextVal) { // trough return 1; } else { // falling return 2; }