Monday, February 20, 2017

SMA Q2 extracting data.

SMA Q2 extracting data.

See my SMA-Q2 first impressions and do-not-disturb-automation blogs about SMA Q2.

SMA Care 

SMA Care app fetches Activity and Sleep data from SMA Q2 watch and store them in SQLITE3 database.

SMA Care:                                         Detailed HR data:                             Detailed Sleep data:     
Data are stored in a very light text based server less database: SQLITE3. 
Sqlite is very popular in android apps because data can be handled with standard SQL commands.
Fast and efficient way to store recurring data.

Place of databases:

You can find SMA Care application files (config files and data) on your Android device root directory: 


The databases are here:     /data/data/com.szabh.sma_new/databases

Copy these database files to your SDCard and send to your PC.
I copy databases directory to SDcard with Tasker :

Then I send this directory to my NAS storage server with SCP.
See detailes here.
Copy databases to PC to further export and analysis.

Python for data analysis

Python is very popular language for data analysis.
You will soon understand why?

Database read with Python:

import sqlite3
import pandas as pd
from sqlalchemy import create_engine
db=sqlite3.connect('python/sma/mydb') # data/data/com.szabh.sma_new/databases
engine = create_engine('sqlite:///python/sma/mydb')

Read Table names from Database:

df = pd.read_sql_query('SELECT * FROM sqlite_master WHERE type="table" ', db)df.head(6)                                                                                                                            # List tables in database.

Export all tables to CSV:

for table in tables:
    df = pd.read_sql_table(table, engine)

You will find 4 CSV file in your home directory

  • Sport.csv
  • Sleep.csv
  • HeartRate.csv
  • Alarm.csv
for example HR data seems like this:

Sleep data sample:


I also made data export in python.

df = pd.read_sql_query('SELECT * FROM Sleep WHERE date like "2017-02-18%" ', db)

Python chart example:

1 comment:

  1. Amazing blog. This post is looking interesting. Thanks for sharing this with us.crownbestreview