• Recent
    • Tags
    • Popular
    • Register
    • Login

    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.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Meta Point Help

    How-To
    4
    5
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Pikey4
      last edited by

      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:

      0_1546930069795_Untitled.jpg

      Cheers!

      Mango Core version: 3.5.6
      Mango API module version: 3.5.2
      MangoUi module version: 3.5.5
      Platform: 10.14 MacOS Mojave
      Chrome: Version 70.0.3538.110 (64-bit)

      1 Reply Last reply Reply Quote 0
      • CraigWebC
        CraigWeb
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • Jared WiltshireJ
            Jared Wiltshire
            last edited by Jared Wiltshire

            @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;
            }
            

            Developer at Radix IoT

            1 Reply Last reply Reply Quote 0
            • P
              Pikey4
              last edited by

              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;
              }
              

              0_1547002473983_mangoChart.png

              Mango Core version: 3.5.6
              Mango API module version: 3.5.2
              MangoUi module version: 3.5.5
              Platform: 10.14 MacOS Mojave
              Chrome: Version 70.0.3538.110 (64-bit)

              1 Reply Last reply Reply Quote 1
              • First post
                Last post