It'd be useful to have a graph showing when data was last received from the watch - the might later turn into an alert if things haven't synced for quite some time
# Create a field to record when we last synced
now = time.time_ns()
last_dates_query = ("SELECT DEVICE_ID, max(TIMESTAMP) "
"FROM MI_BAND_ACTIVITY_SAMPLE "
f"WHERE TIMESTAMP >= {query_start_bound} "
"GROUP BY DEVICE_ID"
)
res = cur.execute(last_dates_query)
for r in res.fetchall():
row_ts = r[1] * 1000000000 # Convert to nanos
row_age = now - row_ts
row = {
"timestamp": now,
"fields" : {
"last_seen" : row_ts,
"last_seen_age" : row_age
},
"tags" : {
"device" : devices[f"dev-{r[0]}"],
"sample_type" : "sync_check"
}
}
results.append(row)
However, the reliance on MI_BAND_ACTIVITY_SAMPLE means we may only see a record periodically (if the wearer is asleep, there's not going to be much in there).
It might actually be worth moving away from relying on a query for this. Above that codeblock is all the queries used to extract metrics - we could conceivably capture timestamps from those and then have this block take the most recent. That way, the timestamp of any supported activity/metric would update the sync time.
Activity
26-Aug-23 11:21
assigned to @btasker
26-Aug-23 11:26
mentioned in commit b68ad532889c8df88d020b8a2f3a6ddf9da89370
Message
Track time of last observed sync (utilities/gadgetbridge_to_influxdb#7)
This adds two fields
last_seen
: The (nanosecond) timestamp of the last observed datapointlast_seen_age
: number of nanoseconds since that timestampThis currenty relies on the periodic sampling in
MI_BAND_ACTIVITY_SAMPLE
.Values are grouped by device ID, so if multiple devices are registered in gadgetbridge, there'll be an entry for each
26-Aug-23 11:28
The calculation is currently pretty simple
However, the reliance on
MI_BAND_ACTIVITY_SAMPLE
means we may only see a record periodically (if the wearer is asleep, there's not going to be much in there).It might actually be worth moving away from relying on a query for this. Above that codeblock is all the queries used to extract metrics - we could conceivably capture timestamps from those and then have this block take the most recent. That way, the timestamp of any supported activity/metric would update the sync time.
26-Aug-23 11:37
mentioned in commit ed97a5ab40f1dc8eb8fe9f0fdb19cf21a747d71e
Message
Use timestamps from all supported events to calculate
last_seen
andlast_seen_age
(utilities/gadgetbridge_to_influxdb#7)This pivots away from relying on a single query to assess when data was last synced
26-Aug-23 15:56
mentioned in issue #8
27-Aug-23 10:26
This is working
(That gap has been addressed in #11)
I've added these stats to the dashboard
The queries are variations of