I'm trying to wrap my head around how the movement data tracking works in the health app. The figures in the hourly data make sense, generally ranging from, say, 50 to 800 depending on the amount of movement, but the daily averages for the same metric don't. I'm getting values for each day like 6, 8, 8, 8, 8, 8, etc—definitely not an arithmetical average. That seems fishy to me.
So I'm digging deep into the Health app code and trying to understand how the data is being calculated and written to the underlying DB. The first thing I notice is this part where it writes the daily summaries: I think it's reading byte 2 of the record for movement data, but that seems to be the same byte that it's reading for heart rate data? Other places in the code use byte 3 for movement instead (and 2 for HR), so I wonder if I missed something or if that's actually a bug.
So I tried modifying this code to what I'm guessing it should be, but it doesn't seem to change the result much. Yesterday's movement summary was still just 6. Looking a bit deeper, though, I see the definition of getRecordData(), which bundles the data up into a DB record for writing, and it divides the movement data by 8 before writing. But that gets called twice. I might be reading the code wrong, but it seems like it's doing that when writing normal records (every ten minutes?), but then it gets called again when doing the summary… So I'm wondering if maybe it's accidentally doing the division twice, once for the initial data and then again when averaged for the day (meaning the dailies are now divided by 64 while the hourly is only divided by 8). Which isn't a difference I would expect to see in the user-facing interface when comparing hourly vs. daily data.
If anyone could shed some light on this or confirm/debunk what I'm thinking, that would be helpful.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'm trying to wrap my head around how the movement data tracking works in the health app. The figures in the hourly data make sense, generally ranging from, say, 50 to 800 depending on the amount of movement, but the daily averages for the same metric don't. I'm getting values for each day like 6, 8, 8, 8, 8, 8, etc—definitely not an arithmetical average. That seems fishy to me.
So I'm digging deep into the Health app code and trying to understand how the data is being calculated and written to the underlying DB. The first thing I notice is this part where it writes the daily summaries: I think it's reading byte 2 of the record for movement data, but that seems to be the same byte that it's reading for heart rate data? Other places in the code use byte 3 for movement instead (and 2 for HR), so I wonder if I missed something or if that's actually a bug.
So I tried modifying this code to what I'm guessing it should be, but it doesn't seem to change the result much. Yesterday's movement summary was still just 6. Looking a bit deeper, though, I see the definition of getRecordData(), which bundles the data up into a DB record for writing, and it divides the movement data by 8 before writing. But that gets called twice. I might be reading the code wrong, but it seems like it's doing that when writing normal records (every ten minutes?), but then it gets called again when doing the summary… So I'm wondering if maybe it's accidentally doing the division twice, once for the initial data and then again when averaged for the day (meaning the dailies are now divided by 64 while the hourly is only divided by 8). Which isn't a difference I would expect to see in the user-facing interface when comparing hourly vs. daily data.
If anyone could shed some light on this or confirm/debunk what I'm thinking, that would be helpful.