diff --git a/src/AirQualityMonitor.py b/src/AirQualityMonitor.py index f8d6018..94dec68 100644 --- a/src/AirQualityMonitor.py +++ b/src/AirQualityMonitor.py @@ -23,6 +23,6 @@ class AirQualityMonitor(): """Saves measurement to redis db""" redis_client.lpush('measurements', json.dumps(self.get_measurement(), default=str)) - def get_last_n_measurements(self, n=10): + def get_last_n_measurements(self): """Returns the last n measurements in the list""" - return [json.loads(x) for x in redis_client.lrange('measurements', -n, -1)] + return [json.loads(x) for x in redis_client.lrange('measurements', 0, -1)] diff --git a/src/app.py b/src/app.py index cb8391b..34c2562 100644 --- a/src/app.py +++ b/src/app.py @@ -23,9 +23,10 @@ atexit.register(lambda: scheduler.shutdown()) def reconfigure_data(measurement): """Reconfigures data for chart.js""" current = int(time.time()) - measurement = measurement.reverse() + measurement = measurement[:30] + measurement.reverse() return { - 'labels': [int((current - (x['time'])) / 60) for x in measurement], + 'labels': [x['measurement']['timestamp'] for x in measurement], 'pm10': { 'label': 'pm10', 'data': [x['measurement']['pm10'] for x in measurement],