piggz / harbour-amazfish

Amazfit Bip support for SailfishOS
GNU General Public License v3.0
103 stars 51 forks source link

number of samples in mi_band_activity and heart rate activity and steps architecture #274

Closed jmlich closed 8 months ago

jmlich commented 11 months ago

I am checking how can I implement steps and heart rate sampling for PineTime.

I can see that table have following structure

mi_band_activity(id, timestamp, timestamp_db, device_id,user_id, raw_intensity, steps, raw_kind, heartrate)

I can insert either sparse data like this:

for steps: (id, timestamp, timestamp_db, device_id, user_id, null, steps, null, null)
for heartrate (id, timestamp, timestamp_db, device_id, user_id, null, null, null, heartrate)

or I can create separate tables steps_log(id, timestamp, timestamp_db, steps) and heart rate(id, timestamp, timestamp_db, heart rate) and store data independently. This would expect either have every query twice in datasource.cpp or to migrate old data to new structures and adjust code accordingly.

Other option would be to collect both steps and heartrate in daemon and then push them into database after some period of time. This can reduce also the number of stored data or somehow normalize the output.

I am also wondering what amount of data is written every day. How this will affect lifespan of NAND? Can you please run following query and give me some hint. I am thinking of preventing storing samples more often than once per minute.

adb shell
sqlite3 /home/phablet/.local/share/harbour-amazfish/harbour-amazfish/amazfish.kexi
SELECT date(timestamp_dt), count(*) FROM mi_band_activity GROUP BY date(timestamp_dt) ;

It would be helpful to see if the data in mi_band_activity are actually sparse or dense

SELECT * FROM mi_band_activity

I am already playing with the implementation, but I would like to create it compatible with other devices. screenshot20231006_155834908

piggz commented 11 months ago

sqlite> SELECT date(timestamp_dt), count(*) FROM mi_band_activity GROUP BY date(timestamp_dt) ; 2023-05-29|1038 2023-05-30|1440 2023-05-31|1440 2023-06-01|2358 2023-06-02|1166 2023-06-03|1440 2023-06-04|1440 2023-06-05|1440 2023-06-06|1440 2023-06-07|1440 2023-06-08|1440 2023-06-09|1440 2023-06-10|1440 2023-06-11|1360 2023-07-15|80 2023-07-16|1859 2023-07-17|1440 2023-07-18|1440 2023-07-19|1440 2023-07-20|1440 2023-07-21|1440 2023-07-22|1440 2023-07-23|1320 2023-07-24|1440 2023-07-25|1440 2023-07-26|1440 2023-07-27|1440 2023-07-28|1440 2023-07-29|1440 2023-07-30|1440 2023-07-31|1384 2023-08-01|1440 2023-08-02|1440 2023-08-03|1440 2023-08-04|1369 2023-08-06|723 2023-08-07|1440 2023-08-08|1440 2023-08-09|1440 2023-08-10|1440 2023-08-11|1440 2023-08-12|1440 2023-08-13|1440 2023-08-14|1440 2023-08-15|1440 2023-08-16|1262 2023-08-17|1440 2023-08-18|1440 2023-08-19|1440 2023-08-20|1440 2023-08-21|1440 2023-08-22|1440 2023-08-23|1440 2023-08-24|1440 2023-08-25|1440 2023-08-26|1440 2023-08-27|1440 2023-08-28|1031 2023-08-29|1440 2023-08-30|1440 2023-08-31|1439 2023-09-01|1440 2023-09-02|1440 2023-09-03|1440 2023-09-04|1440 2023-09-05|1440 2023-09-06|1266 2023-09-07|1440 2023-09-08|1440 2023-09-09|1439 2023-09-10|1440 2023-09-11|1440 2023-09-12|1440 2023-09-13|1439 2023-09-14|1438 2023-09-15|1440 2023-09-16|1440 2023-09-17|416 2023-09-18|1440 2023-09-19|1440 2023-09-20|1440 2023-09-21|1440 2023-09-22|1386 2023-09-23|1440 2023-09-24|1440 2023-09-25|1440 2023-09-26|1440 2023-09-27|1440 2023-09-28|888 2023-09-29|1440 2023-09-30|1440 2023-10-01|1440 2023-10-02|1440 2023-10-03|1440 2023-10-04|1440 2023-10-05|1440 2023-10-06|1290

piggz commented 11 months ago

data in mi_band_activity looks like 135366|1696626240|2023-10-06T22:04:00+01:00|1630542559|8080010|11|0|80|55 135367|1696626300|2023-10-06T22:05:00+01:00|1630542559|8080010|10|0|80|66 135368|1696626360|2023-10-06T22:06:00+01:00|1630542559|8080010|19|0|80|57 135369|1696626420|2023-10-06T22:07:00+01:00|1630542559|8080010|29|0|80|255 135370|1696626480|2023-10-06T22:08:00+01:00|1630542559|8080010|32|0|80|255 135371|1696626540|2023-10-06T22:09:00+01:00|1630542559|8080010|18|0|80|50 135372|1696626600|2023-10-06T22:10:00+01:00|1630542559|8080010|11|0|80|53 135373|1696626660|2023-10-06T22:11:00+01:00|1630542559|8080010|23|0|80|57 135374|1696626720|2023-10-06T22:12:00+01:00|1630542559|8080010|13|0|80|61 135375|1696626780|2023-10-06T22:13:00+01:00|1630542559|8080010|15|0|80|59 135376|1696626840|2023-10-06T22:14:00+01:00|1630542559|8080010|8|0|80|55 135377|1696626900|2023-10-06T22:15:00+01:00|1630542559|8080010|36|0|80|64 135378|1696626960|2023-10-06T22:16:00+01:00|1630542559|8080010|13|0|80|58 135379|1696627020|2023-10-06T22:17:00+01:00|1630542559|8080010|10|0|80|58 135380|1696627080|2023-10-06T22:18:00+01:00|1630542559|8080010|13|0|80|57 135381|1696627140|2023-10-06T22:19:00+01:00|1630542559|8080010|19|0|80|58 135382|1696627200|2023-10-06T22:20:00+01:00|1630542559|8080010|12|0|80|255 135383|1696627260|2023-10-06T22:21:00+01:00|1630542559|8080010|8|0|80|66 135384|1696627320|2023-10-06T22:22:00+01:00|1630542559|8080010|14|0|80|54 135385|1696627380|2023-10-06T22:23:00+01:00|1630542559|8080010|4|0|80|72 135386|1696627440|2023-10-06T22:24:00+01:00|1630542559|8080010|24|0|80|59 135387|1696627500|2023-10-06T22:25:00+01:00|1630542559|8080010|31|0|80|72 135388|1696627560|2023-10-06T22:26:00+01:00|1630542559|8080010|34|0|80|255 135389|1696627620|2023-10-06T22:27:00+01:00|1630542559|8080010|20|0|80|255 135390|1696627680|2023-10-06T22:28:00+01:00|1630542559|8080010|18|0|80|59 135391|1696627740|2023-10-06T22:29:00+01:00|1630542559|8080010|21|0|80|63

piggz commented 11 months ago

On the amazifit devices, you can configure an all-day-hrm interval, and it will log on hte watch, your heartrate at that interval ... it will also log other things, like steps over the last 5 minutes i think, and then weird things like when it thinks youre sleeping/still

the structure is taken directly from Gadget Bridge