This commit is contained in:
Ryder Damen 2021-07-01 01:24:11 -04:00
parent 9df325b73e
commit c6ff5cb22b
No known key found for this signature in database
GPG key ID: A0BB4C56DC7699FF
2 changed files with 5 additions and 4 deletions

View file

@ -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)]

View file

@ -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],