Skip to content

Can't get last data point from MySQL TimeSeries using Daily/Weekly/Yearly aggregation [patch] #1791

Description

@MrTimbones

I have some daily feeds that are only updated once a day. I noticed that I could never get the graph to show data for yesterday.

I've tracked this down to MysqlTimeSeries.php which could do with a couple tweaks:

diff --git a/Modules/feed/engine/MysqlTimeSeries.php b/Modules/feed/engine/MysqlTimeSeries.php
index 5bdc160d..808122e2 100644
--- a/Modules/feed/engine/MysqlTimeSeries.php
+++ b/Modules/feed/engine/MysqlTimeSeries.php
@@ -438,7 +438,7 @@ class MysqlTimeSeries implements engine_methods
                 }
             } else {
                 // Limit DB requests to available datapoints in feed
-                if ($start_time < $time && $time < $end_time) {
+                if ($start_time < $time && $time <= $end_time) {
                     // get datapoint using interpolation if necessary
                     $dp = $this->get_datapoint_interpolated($feedid, $time);
                     $value = $dp[1];
@@ -887,6 +887,9 @@ class MysqlTimeSeries implements engine_methods
                     }
                 }
             }
+            else if (count($dp) == 1 && $dp[0]['time'] == $time) {
+                $data = array($time, (float) $dp[0]['data']);
+            }
             else {
                 // only one datapoint found, interpolation not possible.
                 $data = array($time , null);

These changes ensure that get_data_DMY() requests all points including the last one and get_datapoint_interpolated() will return the final point without interpolation. I now get all the days up to yesterday, and the data is the same as using Fixed Interval 86400.

I don't know if this bug also exists in other feed engines.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions