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

How to purge/delete data point history programmatically


  • Can you, from a meta data point script, purge the history of another data point? How?
    Thanks


  • @till yes you can but it will require accessing Mango Java classes. There are many examples of loading Java classes into the script engine in this forum so please read up on those first.

    The basic idea is to get access to the Common class and the data point VO you want to purge and use one of these methods:

        /**
         * Purge values before a given time
         * @param vo data point VO
         * @param before epoch timestamp in ms
         * @return count of values deleted
         */
        long purgeDataPointValues(DataPointVO vo, long before);
    
        /**
             * Purge values between a time range inclusive of startTime exclusive of endTime
             * @param vo data point VO
             * @param startTime epoch timestamp in ms
             * @param endTime epoch timestamp in ms
             * @return count of values deleted
             */
        long purgeDataPointValuesBetween(DataPointVO vo, long startTime, long endTime);
    
        /**
         * Purge values before a given time
         * @param vo data point VO
         * @param before epoch timestamp in ms
         * @return true if any data was deleted
         */
        boolean purgeDataPointValuesWithoutCount(DataPointVO vo, long before);
    

    So your code will have something like this in it for the purge, note the syntax may be wrong as I'm doing this from memory:

    var Common = Java.type('com.serotonin.m2m2.Common');
    //--- get data point vo here --
    var vo = {};
    var before = 0;
    var purged = Common.purgeDataPointValues(vo, before);
    

  • Thanks @terrypacker,
    I'll read up on this.


  • @terrypacker, I had abit of a look.

    I realise that I can actually avoid this if there's an option to only keep the last (few) value(s) in the database and purge everything else.

    Of course there is the purge option in a data point but it's not very much customisable. Setting it to purge daily (fixed at 3.05am apparently) is too often but weekly is not often enough. Ideally I just keep a single value.

    Even better would be a way to only update the current value and not create a history of values in the first place. I'll never need any historic value, just the current one. Is there a setting or a specific data point type that allows this? I currently use a virtual data point.

    Thanks!


  • You can set the logging setting on your data point to not log any values. e3fa4f24-47c6-4a0b-94c6-fd60f3bd7d84-image.png


  • @joelhaggar Many thanks for your swift responses.

    I expected no logging to not hold the value for long enough for my purpose. But that works - currently.

    This way it's storing the value in memory only, instead of in the database, right? So in a fault situation, resulting in a Mango restart, that value is gone?

    Cheers


  • @till That is correct. The value will be held in the cache. You can even set the data point to hold x number of values in the cache so there is some history there.