thrimshim: Fix odometer endpoint

pull/361/head
Mike Lang 1 year ago
parent a83dbb58f7
commit f0e2aae519

@ -555,18 +555,20 @@ def get_odometer(channel):
AND timestamp <= %(end)s AND timestamp <= %(end)s
ORDER BY timestamp DESC ORDER BY timestamp DESC
LIMIT 1 LIMIT 1
""", channel, start, end) """, channel=channel, start=start, end=end)
result = results.fetchone() result = results.fetchone()
if result is None: if result is None:
# By Sokar's request, we want to return an invalid value rather than an error response. # By Sokar's request, we want to return an invalid value rather than an error response.
return "0" odometer = 0
if not extrapolate: elif extrapolate:
return str(result.odometer) # Current extrapolate strategy is very simple: presume we're going at full speed (45mph).
# Current extrapolate strategy is very simple: presume we're going at full speed (45mph). SPEED = 45. / 3600 # in miles per second
SPEED = 45. / 3600 # in miles per second delta_t = time - timestamp
delta_t = time - timestamp delta_odo = delta_t * SPEED
delta_odo = delta_t * SPEED odometer = result.odometer + delta_odo
return str(result.odometer + delta_odo) else:
odometer = result.odometer
return {"odometer": odometer}
@argh.arg('--host', help='Address or socket server will listen to. Default is 0.0.0.0 (everything on the local machine).') @argh.arg('--host', help='Address or socket server will listen to. Default is 0.0.0.0 (everything on the local machine).')

Loading…
Cancel
Save