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

Issue with kWh averaging meta script during a power outage.


  • I have the following configuration:

    "kW" (p40):
    Modbus kW Sampled at the data source every 10 seconds

    "kW" (p40) Logging Type:
    When point value changes

    "kWh" Meta Script for hourly kWh chart display:

    return p40.past(HOUR, 1).average;
    

    Script is triggered:
    Start of hour

    "kWh" Logging Type:
    When point value changes

    We Had no kW readings logged at all (power outage) from 10AM to 1PM today, but the kWh meta script still calculated values every hour during this outage. It seems to just re-use entries prior to 10AM over producing false data. I expected a zero reading for those (power outage) 11AM-1PM hourly timeslots. What's the best way to show these "zero" hourly entries on a chart?

    Thanks.


  • Hi raylatbasix,

    I understand why one could expect a zero in that condition, but the statistic reflects the average value of the point over the interval. Most things measured by sensors are continuous series even if only discrete measurements are taken. An alternative position would be that in regular conditions most people's intervals will be large enough relative to the polling (and their data uniform enough) such that considering the prior value or value durations is insignificant, and that in anomalous conditions like this it could be in keeping with one's sense of what's true. That position can be rebuked that the average of an empty data set (discrete average = sum / count) is 0/0 which is indeterminate instead of 0, and that treating values in time as persisting in time seems more general.

    To the question, I would solve this with a slight modification to the script:

    var stats = p40.past(HOUR, 1);
    if(stats.count != 0) return stats.average;
    return 0;
    

    and you can purge the history then regenerate it.

    Edit: Some parts of the statistics object are discrete, such as the sum and count. So, if you wanted a discrete average you could do return stats.sum / stats.count; which would have likely given NaN in those periods (which also may not chart as desired).


  • Hi Phil,

    Thanks for the advice, and also the script help. I will give this a try.

    Kindest Regards,
    Ray