Commit e99e15e6 authored by Nelso Jost's avatar Nelso Jost

FIX last raw data of empty boards

parent 42da4364
......@@ -66,9 +66,17 @@ class Board(db.Model, BaseMixin):
@property
def last_rawdata_json(self):
d = {}
last_data = self.rawdata.order_by(RawSensorData.datetime.desc())\
.first()
d['datetime'] = last_data.datetime.strftime("%Y-%m-%d %H:%M:%S")
try:
last_data = self.rawdata.order_by(RawSensorData.datetime.desc())\
.first_or_404()
except:
last_data = None
if last_data and last_data.datetime:
d['datetime'] = last_data.datetime.strftime("%Y-%m-%d %H:%M:%S")
else:
d['datetime'] = None
d['board_url'] = url_for('board.main', id=self.id)
d['sensors'] = {}
......@@ -79,7 +87,10 @@ class Board(db.Model, BaseMixin):
s['unity'] = bs.sensor.unitymeasurement.unity.json
s['url'] = url_for('board.sensor',
id=self.id, sensor_nickname=bs.sensor.name)
s['value'] = last_data.sensor_values[bs.id]
if last_data and last_data.sensor_values:
s['value'] = last_data.sensor_values[bs.id]
else:
s['value'] = None
d['sensors'][bs.id] = s
d['sensor_order'] = [s.id for s in self.sensors.order_by('order').all()]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment