Temperature MIN/MAX/AVG



  • Hello,
    How can I get MIN/MAX/AVG informations about temperature variable ?
    I see in ScriptAPI about metrics, method : getSensorVariableMetricsDouble
    it's the right way ?

    When I try this on my sensor variable :
    var list = mcApi.metric().getSensorVariableMetricsDouble(1,0,1479823903);
    list is empty :-(

    Can you help me ?
    Thanks


  • ADMIN

    @Tetnobic You can get it on two ways,

    Option 1:

    Assign uidTag for your temperature variable, and use it on the script. In this method it will return single object. You will not get list.

    var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
    
    with(myImports) {
    var sVar = mcApi.uidTag().getByUid("temp-outside").getResource(); // Get sensor variable object with UidTag api
    var minMaxData = mcApi.metric().getSensorVariableMetricDouble(sVar, 0,1479833863195); //(sensor-variable-object, from-timestamp, to-timestamp)
    }
    

    on minMaxData object will be as follows,

    "minMaxData": {
        "minimum": 0,
        "average": 73.51,
        "maximum": 115.4,
        "current": 34.9,
        "previous": 34.9,
        "variable": {....}
    }
    
    Option 2:

    You can call list of metrics range with timestamp and bucket-duration. BucketDuration is nothing but interval between metric values.

    var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
    
    with(myImports) {
    var sVar = mcApi.uidTag().getByUid("temp-outside").getResource(); // Get sensor variable object with UidTag api
    var listOfData = mcApi.metric().getMetricData(sVar.id, "Sensor variable", 1479733863195, 1479833863195, "6h", true); //(sensor-variable-id, from-timestamp, to-timestamp, bucket-duration, boolean-get-generic), here the bucket duration is 6 hours
    }
    

    Output as follows,

      "listOfData": [
        {
          "start": 1479755463195,
          "end": 1479777063195,
          "empty": false,
          "min": 40.5,
          "max": 43.3,
          "avg": 42.672998137802615,
          "samples": 537
        },
        {
          "start": 1479777063195,
          "end": 1479798663195,
          "empty": false,
          "min": 37.7,
          "max": 42.6,
          "avg": 40.97185185185186,
          "samples": 540
        },
        {
          "start": 1479798663195,
          "end": 1479820263195,
          "empty": false,
          "min": 34.9,
          "max": 38.4,
          "avg": 37.71923076923077,
          "samples": 546
        },
        {
          "start": 1479820263195,
          "end": 1479841863195,
          "empty": false,
          "min": 34.9,
          "max": 35.6,
          "avg": 34.96143617021263,
          "samples": 376
        }
      ]
    

    hope this example will help you.



  • Wonderful !!!
    Option 1 works for me like a charm !

    Many thanks, MyController is the best ;)


Log in to reply
 

7
Online

439
Users

231
Topics

1378
Posts

Looks like your connection to MYCONTROLLER.ORG was lost, please wait while we try to reconnect.