Xiaomi Mi Band data extraction, analytics and Google Fit sync tools

Search This thread

xmxm

Senior Member
Sep 24, 2010
119
168
Current Version: Extraction Tool v5.92, Analytics Tool v5.60, iOS Extraction Tool v0.2, Fit Sync Tool v0.2 (Updated 6/20/2015)

Here is a tool I wrote for Xiaomi Mi band which provides following functionality:
1. Exports data from Xiaomi Mi band on both rooted and non-rooted Android phones and jailbroken (and possibly non-jailbroken) iPhones under Windows and Linux, generating file in CSV format which can be reviewed in Excel.
Bonoboo maintains a script to perform extraction directly on your smartphone (see link in post 3).
2. Extracts detailed (per minute) walking and running information from Mi Band database (thanks to the input provided by mritsch and Osid).
3. Produces files that can be uploaded to fitnesssyncer.com/ to syncronize data with various fitness services: FitBit/HealthVault/RunKeeper/JawBone and soon Google Fit! See 3rd post for details on data mapping for fitnesssyncer.
4. Provides multiple analytics reports to review extracted data. These reports can be shared on cloud drives to be accessed from anywhere (see post 3 for details)
5. Supports localized UI (currently supported languages are English, Russian, French, Spanish and Italian)
6. Support for synchronization data with Google Fit Service - see post #2 for details

How to use:
Preparation steps:
1. If you plan to use multiple packages, unpack them all to same directory.
1a. If you want to extract data from smartphone, download miband_extract package. To extract data from iOS devices, see to "To extract data from iOS devices" step.
1b. If you want to display local charts of your extracted data on your computer, download miband_analytics package.
1c. If you want to synchronize your extracted data with Google Fit, download miband_fit package.
2. Make sure you have USB drivers for your device properly installed and that your device is accessible by ADB when you connect it through USB
3. If you use it on windows, extract package has all binaries included, for Linux/OSX see comments below.

Checking configuration settings:
1. Review SDPath parameter value in run.bat/run.sh. The program will copy files from Mi app location to folder specified in SDPath before pulling them to desktop. In most cases default value (/sdcard) shoud work fine, however if your phone does not have this directory, find the path where your Internal/External SD is mounted and put that path string into SDPath value. Second most common value might be /storage/sdcard0
2. Review config.js and make any changes to your liking (set Goals for sleep hours and daily steps, force override UI language to specific value)
3. If you do not want main report being open every time you run extract, change OpenHTML=Y in run.bat/run.sh to OpenHTML=N
4. If your device is not rooted or have any issues with first (root) method that application uses and prefer to skip straight to the second (backup) method, set ForceBackupMode value to Y in run.bat.
5. If you want to generate Raw data extract in addition to summary data, set ExtractRaw parameter to Y, update Height parameter to your height in centimeters and update Weight parameter to your weight in kilograms. Please note that data extracted from raw blobs may be slightly different from total numbers in summary data.

If you are planning to use ADB over Wifi:

0. I would not be able to provide much support for ADB over Wifi - so many things could go wrong. Check you firewall settings, check TCPIP ports on both ends, but you are basically on your own.
1. If you are planning to use ADB over WiFi, edit run.sh and set up IPAddr value to IP address of your phone, if you use USB cable, leave IPAddr value blank. If you using non-default port, you may need to change TCPPort value.
2.You may also think of a great idea of running syncronization automatically and unattended using ADB over Wifi - at least I liked that idea initially. I gave that idea more thought and as of now I strongly recommend not to do it - having ADB running over Wifi is a security risk, if you have to use it over Wifi, enable it manually, run the sync and disable ADB over Wifi right away.

For Linux/OSX users:
1. You would need to to manually install android-sdk for (adb binary), sqlite3 version 3.8.3 or higher and openssl with zlib support (version 1.0.2 or higher with zlib support is recommended) to uncompress zlib data. Please note that versions of sqlite3 and openssl that are preinstalled on your machine might be too old to be used with this package, so you might need to obtain newer versions. For example, I was told that OSX has sqlite3 version 3.7.13 preinstalled and it is incompatible with some of functions used in script, so you would need version 3.8.3 at least. If you cannot get openssl with zlib support, you can use similar functionality from python instead - you will need to comment out a line with openssl zlib in run.sh and uncomment next line instead which invokes python script.
2. You'll need to grant execute permissions to run.sh by using chmod +x run.sh and you will need to execute run.sh instead of run.bat in steps listed below. You'll also need to make configuration changes in run.sh instead of run.bat
3. Check that your sqlite3 is properly configured for your time zone. Run following command and see if it returns correct timestamp:
bin\sqlite3 dbfile "select datetime('now','localtime');"

Running application:
1. Connect phone through USB and make sure USB debugging setting is enabled on your phone. Unlock phone screen.
2. Execute run.bat - if your phone is rooted, the data would be pulled automatically. If your phone is not rooted you would see backup screen and you need to press "Back up my data" button in the bottom left corner.
3. Data from your mi band will be saved to extract.csv file and extract.js. After extraction is complete, if OpenHTML is set to Y, mi_data.html will be opened automatically to show charts for your Mi usage.
4. HTML reports are using Google Charts framework and Google TOS does not allow storing their scripts offline along with the application, therefore you will need to have working internet access for reports to work. Your data is not being sent to Google, the internet connection is only used to download latest version of Google Charts javascripts.

Troubleshooting connectivity issues:
1. If you phone is rooted:
Review that your phone has /sdcard directory and it is writable. After you run extract, check if you have origin_db file in that directory. If you do not, ADB may have issues writing files to that directory. Check configuration settings section, item 1
2. If your phone is not rooted or if you use ForceBackupMode=Y:
Check if you get full backup screen, which looks like this:

MOXTYya.gif

If you do not get this screen, then Android backup functionality on your device is broken. If your phone is rooted, consider setting ForceBackupMode=N and using rooted method; if your phone is not rooted, try to run Helium Backup https://play.google.com/store/apps/details?id=com.koushikdutta.backup and see if it can backup MI app to sdcard.


To extract data from iOS devices:

Thanks to joshmosh for detailed instructions.
This is reported to work on jailbroken iPhone, but may work on regular iPhones as well - if you try it on non-jailbroken iPhone please let me know if it worked for you.
1. Get a copy of itools. Google it to find a download location (cnet might have it)
2. Plug in your iPhone to your PC
3. Open itools and click on Applications in top row
4. On the left you will find name of your iPhone and below "Applications". Click on Applications
5. Locate your application Mi Fit and click it. On the right you will find a button labelled "browse". Click it.
6. A window will open. Doubleclick on "Documents" then click on user.sqlite, then on "Export" above.
7. A window will open asking you where to export this file. Export it to a db subdirectory of miband extractor main directory and click OK. You should have a file db\user.sqlite now.
8. Once file is extracted to db\ directory, run runIOS.bat from main miband extractor directory. It should generate extract.js, extract.csv and minmaxtime.csv files and will open local charts in your browser if you have analytics package installed.


Screenshots:
ALWh4zf.gif



id5BV3q.gif



tg1XKO9.gif
 

Attachments

  • miband_analytics_v560.zip
    8 KB · Views: 14,288
  • miband_extract_ios_v02.zip
    308.1 KB · Views: 5,180
  • miband_fit_03.zip
    1.3 MB · Views: 11,069
  • miband_extract_v592.zip
    1.6 MB · Views: 17,448
  • miband_analytics_v560_src.zip
    6.3 KB · Views: 4,978
Last edited:

xmxm

Senior Member
Sep 24, 2010
119
168
Report descriptions:
mi_data.html:
This report shows overview of the data being extracted. It consists of 3 elements:
a. The chart on the left shows sleep data over time. Total bar height represents overall sleep time and colored segments represent light and deep sleep parts of it.
b. The chart on the right shows daily activity metrics over time. It shows total distance, number of steps and calories burned.
c. The chart on the bottom shows all data inside text table. You can sort the data by any column by clicking on the title of that column. If you select any specific row in the table, same day will be hightlighted in two other charts.

Both graphic charts also show target goals in green line, so you could see how well your results are matching target values. You can dynamically change target values by pressing + and - buttons. The table below has arrows next to Total Sleep and Total Steps columns which would be green for days when goal was met and red for days when goal was not achieved.

mi_data_byDoW.html:
This report allows you to see the scatter of your activities grouped by the day of the week.
This would be a good chart to see if you are performing better on any specific day of the week.
There are 4 charts on that report:

a. The left chart shows various metrics in scatter chart. You can select a specific metric from the dropdown located above the chart. You can also see a daily goal trendline in green and an approximation line in black. If the approximation line is not flat and you have statistics over many weeks, this might mean that your performance is consistently different depending on the day of the week.

b. The right chart shows line chart data for the metric selected in the left chart. It has time zoom controls at the top to only show the data over last day, last 5 days, 1 week, 1 month, 3 months, 6 months and 1 year. You can also select time interval manually by dragging time sliders at the bottom of the chart.

c. The chart at the bottom is a calendar view for your activity-related metrics. It shows a calendar and each days recorded activity is colored based on whether the value for that activity is above or below the goal. The days that have metric value below daily goal will be colored red, the days with metric value above the goal will be colored blue. The higher the deviation from the goal, the more intense color would be. In other words, the days where results are significantly above the goal would be colored in saturated blue and the days where results are significantly below the goal would be colored in saturated red.
This chart could help searching for more complicated patterns in your performance, patterns that are not just days of the week.
You can also change goal values dynamically by using + and - buttons at the top and see green trendline moving on the left chart and days changing colors on the bottom chart.

d. The last chart shows a timeline of your sleep on a daily level. This chart will only be visible if you select "Sleep Timeline" metric from the dropbox. This chart shows the time you went to sleep and the time you woke up. It shows this information for each day the history data is available and weekends are colored in a different color. This chart could help you to see how consistent your sleep/wake hours across different days and also if you have same sleeping patterns on weekends.

Google Fit Syncronization:
Limitations:
1. Daily summary statistics is synced, so charts by Week and Month will show correct data; chart by day will show correct totals, but not correct hourly breakdown.

Prerequisites:
1. You need to have at least version 5.71 of miband_extract package.
2. You will need to have Internet access and your browser should be configured to enable pop-ups at least from a specific domain below.
3. You need to open following URL: Get Fit Token and allow it to access your Google Fit data. Latest version of Chrome worked for me, while IE 11 had issues with popups.

Installation:
1. Download latest version of meband_fit package and unpack it to the directory where you have miband_extract v5.71 or above.
2. If you upgrade from previous version of fit sync package, you will need to clean up old data populated by old version. To do so run following command:
fit clean

Running Sync:
1. Synchronize your data from smartphone to desktop.
2. Obtain a new OATH key for syncing data with Fit - open Get Fit Token and copy resulting string to your clipboard.
3. Run fit.bat and when asked for new token paste the string from previous step and press enter. If fit.bat did not ask you for token and failed with Authentication error, just run it again.

Troubleshooting:
1. The process is logging into fit\*.log files. If you have errors, review these logs first.
2. The token from step 2 is valid for 1 hour - you will need to refresh the token after that. After 1 hour subsequent fit syncs will start failing until you obtain a new token.
3. Current token is cached in GKey environment variable. Once batch determines that old token is expired, it would clean the variable and will ask you for a new key on a subsequent run.
 
Last edited:

xmxm

Senior Member
Sep 24, 2010
119
168
Related links:

Latest version of Bonoboo port for smartphone extraction.

Known Issues:

1. Vertical axis is not always in sync for two charts in mi_data_byDoW.html
2. Timeline axis is only shown at the bottom of timeline

Version History:
Code:
[B]v5.92 06/20/2015[/B]
Added support for Mi Scale - extracting weight history into weight.csv

[B]v5.90 03/14/2015[/B]
Walking and Running statistics with minute granularity are now extracted from Raw data thanks to the input provided by mritsch and Osid.

[B]v5.80 03/07/2015[/B]
Google Fit sync package 0.3:
Fixed error in 1324438.json file which prevented Fit Sync for some users.
Added FitTools.bat which allows pulling various information from Google Fit account.


[B]v5.80 03/01/2015[/B]
Extraction package:
Added experimental support for raw data extraction. To enable raw data extraction, set ExtractRaw=Y in run.bat

Analytics package:
German localization added to analytics package (thanks to joshmosh)
default app_locale.js file is added to analytics package to support data extracted from iOS devices.

Data Extraction Tool v0.1 for iOS is added along with instructions on how to manually extract Mi Band data from iPhone

[B]v5.71 02/16/2015[/B]
Extraction package:
Extra fields added to extract.csv to support for Google Fit sync v0.2.
extract.json is not created anymore, this data is now calculated on the fly from extract.csv

Google Fit sync package 0.2:
Added sync for activity durations (walk duration, run duration, sleep duration)
Added sync for distance walked. Since distance metric is considered location, Token application will request new permission:
https://www.googleapis.com/auth/fitness.location.write
Fixed activity timestamps - Google Fit expects time to be in UTC time zone.

[B]v5.70 02/16/2015[/B]
Extraction package:
Initial support for Google Fit sync.

Google Fit package 0.1:
Initial release

[B]v5.50 02/05/2015[/B]
Extraction package:
Added new columns to CSV file for better FitnessSyncer compatibility.
Added support for time correction. See db\offset.sql for sample entries.
Updated run.sh from [URL="http://xdaforums.com/member.php?u=6091617"]jlaunay[/URL] to support new run.bat parameters and localization.

Analytics package:
Changed mi_data_byDoW.html to use AnnotationChart for right graph - support for time interval zooming.
Added new metric to mi_data_byDoW.html called "SleepTimeline" to show Sleep Timeline chart.
Various small fixes.

[B]v5.35 02/03/2015[/B]
Extraction package:
 Fixed logging issue - adb would sometimes lock the log files and subsequent extraction invocations would fail completely on locked log files.
 Added support for ADB over Wifi - see instructions in the first post.

Analytics package:
 Fixed sorting order on main table
 Second fix for incorrect sleep/wake hours calculation
 Updated colors across all reports to be consistent
 Converted total/deep/light sleep from minutes to hours and minutes in the main table. Show percentages of deep/light sleep compared to total sleep.
 Add fall asleep and wake up times as selecrable metrics to mi_data_byDoW.html
 mi_data_byDoW.html absorbed all functionality from mi_data_Sleep.html - the sleep calendar functionality and sleep timeline is available when you select Total Sleep metric. You will need to scroll down to see sleep timeline chart.

[B]v5.3 02/02/2015[/B]
Extraction package:
 Add new column with number of walk time + run time in seconds (as per request)
 Added new parameter ForceBackupMode to skip attempt at rooted extraction and go straight for backup mode

[B]v5.2 02/1/2015[/B]
 Splitted program into data extract package and analytics packages. Data extract should be pretty stable now and reports could be updated independently.
 Spanish translation (thanks to Viriatox)

[B]v5.1 01/31/2015 [/B]
 Fix for incorrect sleep/wake hours calculation

[B]v5.0 01/31/2015[/B]
 Localization setting is pulled from Mi database - no need to set it manually anymore (in most cases)
 Two completely new reports - Sleep Report and Statistics by day of the week.
 Fixes to unix shell script encoding.

[B]v4.0 01/29/2015[/B]
 Month number calculation fixed.
 Removed extra rows with zeroes that we incorrectly extracted
 Localization moved to separate file, all other components are unified for all languages
 Scripts for rooted and non-rooted phones combined into one.
 Daily goals and data grouping added on main report.
 Unix shell script for data extraction (thanks to jlaunay)
 French translation (thanks to jlaunay)

[B]v3.0 01/26/2015[/B]
 New script to support data extraction for non-rooted phones
 Reverse sort order in table part of report, so newest dates are on top.
 Week number and day of the week added to report.

[B]v2.0 01/25/2015 [/B]
 All needed Windows binaries included in the package.
 Batch file to automatically run all binaries to extract the data.
 First report showing overall statistics.

[B]v1 01/24/2015[/B]
 Initial release.
Syncronizing with fitnesssyncer.com

FitnessSyncer FAQ: https://www.fitnesssyncer.com/frequently-asked-questions

How to set up import and export.
1. Open account at fitnesssyncer.com/
2. On Dashboard, go to Sources and Destinations and select Add New Source
3. Select Type: Activity, source Amazon S3 (CSB), Dropbox (CSV) or OneDrive (CSV) depending on where your files are stored. Enter path and file name in Path field. Select highlighted columns mappings:
Activity:
Include Date (US) - Column 18
Include Activity - Column 19
Include Distance in Meters - Column 8
Include Duration in Seconds - Column 17
Include Calories Burned - Column 10
Include Total Steps - Column 9
46zy4jo.gif

4. Click on Save and authenticate into your cloud storage account.
5. Back on Sources and Destinations account, click on Sync Now link next to your newly added connection to confirm that it loads without errors. Click on Dashboard button and confirm that you see some data in charts there.
6. Go back to Sources and Destinations and select Add New Source again
7. This time, select Type: Sleep, same Source entry, same Path value and set up highlighted column mappings:
Sleep:
Include Date (US) - Column 18
Include Bed Time Hour - Column 20
Include Bed Time minute - Column 21
Include Awake Hour - Column 22
Include Awake Minute - Column 23
Include Sleeping Minutes - Column 2
DiNbtiC.gif

8. Click Save, go to Sources and Destinations and click Sync Now on Sleep source now to see that it imports without issues.
9. Click on Stream option and see that you have both Daily Activity and Sleep data loaded.
10. Go back to Sources and Destinations and select Add New Destination Task
Fz6xrJf.gif

11. Select SyncType Activity and select Destination from the dropdown list
QssJ4Lq.gif

12. Repeat same steps for Sleep syncronization

Accessing your charts directly from Dropbox:
If you have a Public folder on your dropbox, you can copy all the .js and .html files there and get the shared url by selecting one of htmk files and selecting "Copy public link..." button. It would give you a URL that you can use from anywhere. You need to have Dropbox Pro account or free account created before October 4, 2012 for Public folder functionality to work on your dropbox.
jnFSzaf.gif

Accessing your charts directly from Google Drive:
1. It is recommended that you create new folder in your Drive for this purpose.
2. Select the folder and Choose Share... option
3. On Share with others page dialog, click on Advanced button in bottom right corner.
4. On Sharing Settings dialog, click on Change... link at the top line of Who has access list.
5. On Link sharing dialog, select On - Public on the web option and click Save button.
6. Copy the URL that is shown on Sharing Settings page and click Done to close it
7. The URL that you copied will look something like the sample below. Copy just the alphanumeric sequence that is located between ?id= and &usp=sharing
Code:
https://drive.google.com/folderview?id=[B][COLOR="Red"]123-abcdcdefghijklmnopqrstUV[/COLOR][/B]&usp=sharing
8. Put www.googledrive.com/host/ before this string and /mi_data.html (or any other report) after it, you should get something like www.googledrive.com/host/123-abcdcdefghijklmnopqrstUV/mi_data.html - this should be your sharing link

Here is Google support page on sharing files/directories: https://support.google.com/drive/answer/2881970?hl=en

Using Helium backup instead of Android backup:

Helium produces .ab files that are ALMOST correct tar file, however besides extra characters on file header level they also have some differences in header entries for each file. I've looked through different methods and utilities and the best option so far is to use Helium_ab2tar.zip package (credit goes to xaos.cz for writing it and to johnny1176 for discovering it). It used to be available on xaos.ic.cz/Helium_ab2tar.zip, but that site is down now. You can still google for Helium_ab2tar.zip to find other locations that have copy of this file.

Plans for future versions:
Code:
0. Get more sleep :)
1. Titles for each chart
2. Implement dashboard comparing current week with previous statistical data. (For same days of week)
3. Use timeline component for right chart in data_byDow.htm
4. Show percentage of good days based on selected goals. Show min/max values for each metric.
5. Modify scatter chart to allow using any other series for X axis (Search/display correlations between sleep time and total number of steps).
6. Make a help page showing all the charts and how to use them.
7. Add ratio of deep/light sleep as part of selectable charts.
8. Merge all reports into single multi-tab document.
9. Parse detailed daily binary data - this is going to be a big one.
How to translate application to your language:

To add support for a new language:
For HTML pages
1. Open locale.js in editor supporting UTF-8 encoding.
2. Create a new section starting with
if (lang == "ru_RU") { }
and replace ru_RU with a locale string for your language.
3. Copy all strings from english version to inside { } brackets and translate the text.
4. Save file in UTF-8 encoding.
5. Add reference to your new language in comments section of config.js

For unix shell script:
For all subsequent entries, replace XX with 2-character locale name of your language

1. Create new po file using following command:
bash --dump-po-strings run.sh > po/XX.po
2. Edit newly generated file and translate msgstr entries using msgid entries as references
3. Save the file and generate new directory for the compiled langage file (.mo) using following command:
mkdir -p i18n/XX/LC_MESSAGES/
4. Compile .po file to .mo file by running following command:
msgfmt -o i18n/XX/LC_MESSAGES/mibandextract.mo po/XX.po

If you do not want to use the i18n folder and want the langage file to be system wide, you just have to comment (adding a #) the line "export TEXTDOMAINDIR=./i18n/" in the script.
Then you will have to move your po file to /usr/share/locale/XX/LC_MESSAGES/ (where XX is your langage).
 
Last edited:

xmxm

Senior Member
Sep 24, 2010
119
168
Changelog:
v5.2 released on 2/1/2015.
v5.3 released on 2/2/2015.
v5.32 released on 2/3/2015
v5.7 released on 2/16/2015
v5.71 + fit v0.2 released on 2/21/2015
v5.8 + fit v0.3 released on 3/7/2015
v5.9 released on 3/14/2015
v5.92 released on 6/20/2015
 
Last edited:

macia10

Senior Member
Nov 25, 2010
445
63
Łódź
Hi,
It does not work for me at all ... :( All the time the same thing.


C:\Users\plmaciejewk\Desktop\miband_extract_v53>run
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
Press "Backup My Data" button on device...
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
bin\tail: mi.ab: No such file or directory
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
Could Not Find C:\Users\plmaciejewk\Desktop\miband_extract_v53\mi.ab
Could Not Find C:\Users\plmaciejewk\Desktop\miband_extract_v53\mi.tar
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
Extraction failed
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.

Can I do anything with this?
 

xmxm

Senior Member
Sep 24, 2010
119
168
Hi,
It does not work for me at all ... :( All the time the same thing.


C:\Users\plmaciejewk\Desktop\miband_extract_v53>run
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
Can I do anything with this?

This might be caused by adb process still running in memory and locking log file. I've modified script not to redirect output from adb commands into log file and also added few commands to kill previous adb service once extraction is complete. Could you please download v5.33 and see if it works?
 
Last edited:

macia10

Senior Member
Nov 25, 2010
445
63
Łódź
This might be caused by adb process still running in memory and locking log file. I've modified script not to redirect output from adb commands into log file and also added few commands to kill previous adb service once extraction is complete. Could you please download v5.33 and see if it works?

works perfectly :)
Thanx!! :D
 

SynerG

New member
Feb 3, 2015
2
3
Thanks, very useful!!
FYI, I needed to make some modifications to make it work in my case:
- In 'run.sh', I had to modify the SDPath variable to the correct path (in my version of Cyanogenmod):
SDPath=/storage/sdcard0
- run.sh log indicated a "permission denied" error. It was caused because adb did not have root privileges in my android. To correct it:
In Android: Settings > Administrative access > Select "Applications and ADB"
- sqlite3 in OSX is an old version, so run.sh complains with:
Error: unknown command or invalid arguments: "once". Enter ".help" for help
Error: unknown command or invalid arguments: "print". Enter ".help" for help
To solve it, install a new version of sqlite3. For example using brew:
> brew install sqlite3
and replace sqlite3 in run.sh for the brew version: /usr/local/Cellar/sqlite/3.8.6/bin/sqlite3
- Files from: miband_analytics need to be in the same folder than miband_extract

With these modifications it is working properly in my mac.
Keep up the good work!
 
  • Like
Reactions: clip78 and xmxm

herpez

Senior Member
Nov 5, 2007
673
25
Hi.
I'm extracting data with Bonoboo Mi Band Export Stats, which exports to sd card the files:
app_locale.js; config.js; extract.js; locale.js; Mi_Band_Table.csv; Mi_Band_Table.html and Mi_Band_Graphs.html.

In order to used that exported data with your analytics tools, which files should i move to your folder which contains multiple files like mi_data_byDoW.html and mi_data.html ?

Thanks
 

xmxm

Senior Member
Sep 24, 2010
119
168
Hi.
I'm extracting data with Bonoboo Mi Band Export Stats, which exports to sd card the files:
app_locale.js; config.js; extract.js; locale.js; Mi_Band_Table.csv; Mi_Band_Table.html and Mi_Band_Graphs.html.

In order to used that exported data with your analytics tools, which files should i move to your folder which contains multiple files like mi_data_byDoW.html and mi_data.html ?

Thanks
You'll just need at app_locale.js and extract.js. The folder with analytic tools already has config.js and locale.js and CSV file is not required for analytic tools, you only need it if you want to see your data in Excel.
 
Last edited:
  • Like
Reactions: herpez

xmxm

Senior Member
Sep 24, 2010
119
168
Thanks, very useful!!
FYI, I needed to make some modifications to make it work in my case:
- In 'run.sh', I had to modify the SDPath variable to the correct path (in my version of Cyanogenmod):
SDPath=/storage/sdcard0
- run.sh log indicated a "permission denied" error. It was caused because adb did not have root privileges in my android. To correct it:
In Android: Settings > Administrative access > Select "Applications and ADB"
- sqlite3 in OSX is an old version, so run.sh complains with:
Error: unknown command or invalid arguments: "once". Enter ".help" for help
Error: unknown command or invalid arguments: "print". Enter ".help" for help
To solve it, install a new version of sqlite3. For example using brew:
> brew install sqlite3
and replace sqlite3 in run.sh for the brew version: /usr/local/Cellar/sqlite/3.8.6/bin/sqlite3
- Files from: miband_analytics need to be in the same folder than miband_extract

With these modifications it is working properly in my mac.
Keep up the good work!

Thank you for your feedback.

Regarding SDPath, I'll put a a more clear explanation that SDPath may need to be changed depending on device.
For ADB privileges, the way you had to enable it might be specific to your Android version (I've granted permissions in a different way on my phone), but generally speaking the application should work through Backup logic even when adb has no root permissions.
For sqlite3 issue, could you please tell me which version of sqlite3 OSX has by default, so can add a note in instructions about version compatibility?
Regarding same folder location, I think there is already a mention about the need to have both packages exptracted to the same folder.
 

SynerG

New member
Feb 3, 2015
2
3
Thank you for your feedback.
For ADB privileges, the way you had to enable it might be specific to your Android version (I've granted permissions in a different way on my phone), but generally speaking the application should work through Backup logic even when adb has no root permissions.

I got a message in my Android asking for permission to do the backup, but at the same time I saw the "permission denied" message in the console. Maybe I got both because the script tries to get data from two different mechanisms. Even if I clicked yes to do the backup, the script was not able to get the data until adb was granted permissions.

For sqlite3 issue, could you please tell me which version of sqlite3 OSX has by default, so can add a note in instructions about version compatibility?
My Mac with OSX 10.9 (Mavericks) had installed sqlite3 version 3.7.13. I think that the required commands were added in 3.7.15, but I could be wrong. Brew has installed 3.8.6 and is working properly.
 
  • Like
Reactions: xmxm

xmxm

Senior Member
Sep 24, 2010
119
168
I got a message in my Android asking for permission to do the backup, but at the same time I saw the "permission denied" message in the console. Maybe I got both because the script tries to get data from two different mechanisms. Even if I clicked yes to do the backup, the script was not able to get the data until adb was granted permissions.
Windows version supports ForceBackupMode=Y setting to skip root-specific method and go straight for backup method, but I guess that run.sh is outdated by now - I'll need to find a way to copy newest logic changes to unix script. I still think hope that giving ADB root is not mandatory for extract to work.

My Mac with OSX 10.9 (Mavericks) had installed sqlite3 version 3.7.13. I think that the required commands were added in 3.7.15, but I could be wrong. Brew has installed 3.8.6 and is working properly.
Thank you for this information - I'll put version numbers in the header.
 

jlaunay

Member
Oct 17, 2014
8
7
Windows version supports ForceBackupMode=Y setting to skip root-specific method and go straight for backup method, but I guess that run.sh is outdated by now - I'll need to find a way to copy newest logic changes to unix script.

You will find attached a zip with a new version of run.sh.
run.sh now support ForceBackupMode and internalization.
Thats why I add 2 folders (po and i18n).

If you want to add support for a new langage, let's say spanish for example, you will first have to create a new po file

Code:
bash --dump-po-strings run.sh > po/es.po

Then edit the file newly created with any text editor and translate the "msgid" with the "msgstr"

Once done, you have to create a new directory for the compiled langage file (.mo)

Code:
mkdir mkdir -p i18n/es/LC_MESSAGES/

Then compile the file with

Code:
msgfmt -o i18n/es/LC_MESSAGES/mibandextract.mo po/es.po

For another langage replace "es" with the one you want.
If you do not want to use the i18n folder and want the langage file to be system wide, you just have to comment (adding a #) the line "export TEXTDOMAINDIR=./i18n/" in the script.
Then you will have to move your po file to /usr/share/locale/XX/LC_MESSAGES/ (where XX is your langage).
 

Attachments

  • miband_extract_v535_i18n.zip
    1.6 MB · Views: 138
  • Like
Reactions: Bonoboo and xmxm

Top Liked Posts

  • There are no posts matching your filters.
  • 56
    Current Version: Extraction Tool v5.92, Analytics Tool v5.60, iOS Extraction Tool v0.2, Fit Sync Tool v0.2 (Updated 6/20/2015)

    Here is a tool I wrote for Xiaomi Mi band which provides following functionality:
    1. Exports data from Xiaomi Mi band on both rooted and non-rooted Android phones and jailbroken (and possibly non-jailbroken) iPhones under Windows and Linux, generating file in CSV format which can be reviewed in Excel.
    Bonoboo maintains a script to perform extraction directly on your smartphone (see link in post 3).
    2. Extracts detailed (per minute) walking and running information from Mi Band database (thanks to the input provided by mritsch and Osid).
    3. Produces files that can be uploaded to fitnesssyncer.com/ to syncronize data with various fitness services: FitBit/HealthVault/RunKeeper/JawBone and soon Google Fit! See 3rd post for details on data mapping for fitnesssyncer.
    4. Provides multiple analytics reports to review extracted data. These reports can be shared on cloud drives to be accessed from anywhere (see post 3 for details)
    5. Supports localized UI (currently supported languages are English, Russian, French, Spanish and Italian)
    6. Support for synchronization data with Google Fit Service - see post #2 for details

    How to use:
    Preparation steps:
    1. If you plan to use multiple packages, unpack them all to same directory.
    1a. If you want to extract data from smartphone, download miband_extract package. To extract data from iOS devices, see to "To extract data from iOS devices" step.
    1b. If you want to display local charts of your extracted data on your computer, download miband_analytics package.
    1c. If you want to synchronize your extracted data with Google Fit, download miband_fit package.
    2. Make sure you have USB drivers for your device properly installed and that your device is accessible by ADB when you connect it through USB
    3. If you use it on windows, extract package has all binaries included, for Linux/OSX see comments below.

    Checking configuration settings:
    1. Review SDPath parameter value in run.bat/run.sh. The program will copy files from Mi app location to folder specified in SDPath before pulling them to desktop. In most cases default value (/sdcard) shoud work fine, however if your phone does not have this directory, find the path where your Internal/External SD is mounted and put that path string into SDPath value. Second most common value might be /storage/sdcard0
    2. Review config.js and make any changes to your liking (set Goals for sleep hours and daily steps, force override UI language to specific value)
    3. If you do not want main report being open every time you run extract, change OpenHTML=Y in run.bat/run.sh to OpenHTML=N
    4. If your device is not rooted or have any issues with first (root) method that application uses and prefer to skip straight to the second (backup) method, set ForceBackupMode value to Y in run.bat.
    5. If you want to generate Raw data extract in addition to summary data, set ExtractRaw parameter to Y, update Height parameter to your height in centimeters and update Weight parameter to your weight in kilograms. Please note that data extracted from raw blobs may be slightly different from total numbers in summary data.

    If you are planning to use ADB over Wifi:

    0. I would not be able to provide much support for ADB over Wifi - so many things could go wrong. Check you firewall settings, check TCPIP ports on both ends, but you are basically on your own.
    1. If you are planning to use ADB over WiFi, edit run.sh and set up IPAddr value to IP address of your phone, if you use USB cable, leave IPAddr value blank. If you using non-default port, you may need to change TCPPort value.
    2.You may also think of a great idea of running syncronization automatically and unattended using ADB over Wifi - at least I liked that idea initially. I gave that idea more thought and as of now I strongly recommend not to do it - having ADB running over Wifi is a security risk, if you have to use it over Wifi, enable it manually, run the sync and disable ADB over Wifi right away.

    For Linux/OSX users:
    1. You would need to to manually install android-sdk for (adb binary), sqlite3 version 3.8.3 or higher and openssl with zlib support (version 1.0.2 or higher with zlib support is recommended) to uncompress zlib data. Please note that versions of sqlite3 and openssl that are preinstalled on your machine might be too old to be used with this package, so you might need to obtain newer versions. For example, I was told that OSX has sqlite3 version 3.7.13 preinstalled and it is incompatible with some of functions used in script, so you would need version 3.8.3 at least. If you cannot get openssl with zlib support, you can use similar functionality from python instead - you will need to comment out a line with openssl zlib in run.sh and uncomment next line instead which invokes python script.
    2. You'll need to grant execute permissions to run.sh by using chmod +x run.sh and you will need to execute run.sh instead of run.bat in steps listed below. You'll also need to make configuration changes in run.sh instead of run.bat
    3. Check that your sqlite3 is properly configured for your time zone. Run following command and see if it returns correct timestamp:
    bin\sqlite3 dbfile "select datetime('now','localtime');"

    Running application:
    1. Connect phone through USB and make sure USB debugging setting is enabled on your phone. Unlock phone screen.
    2. Execute run.bat - if your phone is rooted, the data would be pulled automatically. If your phone is not rooted you would see backup screen and you need to press "Back up my data" button in the bottom left corner.
    3. Data from your mi band will be saved to extract.csv file and extract.js. After extraction is complete, if OpenHTML is set to Y, mi_data.html will be opened automatically to show charts for your Mi usage.
    4. HTML reports are using Google Charts framework and Google TOS does not allow storing their scripts offline along with the application, therefore you will need to have working internet access for reports to work. Your data is not being sent to Google, the internet connection is only used to download latest version of Google Charts javascripts.

    Troubleshooting connectivity issues:
    1. If you phone is rooted:
    Review that your phone has /sdcard directory and it is writable. After you run extract, check if you have origin_db file in that directory. If you do not, ADB may have issues writing files to that directory. Check configuration settings section, item 1
    2. If your phone is not rooted or if you use ForceBackupMode=Y:
    Check if you get full backup screen, which looks like this:

    MOXTYya.gif

    If you do not get this screen, then Android backup functionality on your device is broken. If your phone is rooted, consider setting ForceBackupMode=N and using rooted method; if your phone is not rooted, try to run Helium Backup https://play.google.com/store/apps/details?id=com.koushikdutta.backup and see if it can backup MI app to sdcard.


    To extract data from iOS devices:

    Thanks to joshmosh for detailed instructions.
    This is reported to work on jailbroken iPhone, but may work on regular iPhones as well - if you try it on non-jailbroken iPhone please let me know if it worked for you.
    1. Get a copy of itools. Google it to find a download location (cnet might have it)
    2. Plug in your iPhone to your PC
    3. Open itools and click on Applications in top row
    4. On the left you will find name of your iPhone and below "Applications". Click on Applications
    5. Locate your application Mi Fit and click it. On the right you will find a button labelled "browse". Click it.
    6. A window will open. Doubleclick on "Documents" then click on user.sqlite, then on "Export" above.
    7. A window will open asking you where to export this file. Export it to a db subdirectory of miband extractor main directory and click OK. You should have a file db\user.sqlite now.
    8. Once file is extracted to db\ directory, run runIOS.bat from main miband extractor directory. It should generate extract.js, extract.csv and minmaxtime.csv files and will open local charts in your browser if you have analytics package installed.


    Screenshots:
    ALWh4zf.gif



    id5BV3q.gif



    tg1XKO9.gif
    9
    Report descriptions:
    mi_data.html:
    This report shows overview of the data being extracted. It consists of 3 elements:
    a. The chart on the left shows sleep data over time. Total bar height represents overall sleep time and colored segments represent light and deep sleep parts of it.
    b. The chart on the right shows daily activity metrics over time. It shows total distance, number of steps and calories burned.
    c. The chart on the bottom shows all data inside text table. You can sort the data by any column by clicking on the title of that column. If you select any specific row in the table, same day will be hightlighted in two other charts.

    Both graphic charts also show target goals in green line, so you could see how well your results are matching target values. You can dynamically change target values by pressing + and - buttons. The table below has arrows next to Total Sleep and Total Steps columns which would be green for days when goal was met and red for days when goal was not achieved.

    mi_data_byDoW.html:
    This report allows you to see the scatter of your activities grouped by the day of the week.
    This would be a good chart to see if you are performing better on any specific day of the week.
    There are 4 charts on that report:

    a. The left chart shows various metrics in scatter chart. You can select a specific metric from the dropdown located above the chart. You can also see a daily goal trendline in green and an approximation line in black. If the approximation line is not flat and you have statistics over many weeks, this might mean that your performance is consistently different depending on the day of the week.

    b. The right chart shows line chart data for the metric selected in the left chart. It has time zoom controls at the top to only show the data over last day, last 5 days, 1 week, 1 month, 3 months, 6 months and 1 year. You can also select time interval manually by dragging time sliders at the bottom of the chart.

    c. The chart at the bottom is a calendar view for your activity-related metrics. It shows a calendar and each days recorded activity is colored based on whether the value for that activity is above or below the goal. The days that have metric value below daily goal will be colored red, the days with metric value above the goal will be colored blue. The higher the deviation from the goal, the more intense color would be. In other words, the days where results are significantly above the goal would be colored in saturated blue and the days where results are significantly below the goal would be colored in saturated red.
    This chart could help searching for more complicated patterns in your performance, patterns that are not just days of the week.
    You can also change goal values dynamically by using + and - buttons at the top and see green trendline moving on the left chart and days changing colors on the bottom chart.

    d. The last chart shows a timeline of your sleep on a daily level. This chart will only be visible if you select "Sleep Timeline" metric from the dropbox. This chart shows the time you went to sleep and the time you woke up. It shows this information for each day the history data is available and weekends are colored in a different color. This chart could help you to see how consistent your sleep/wake hours across different days and also if you have same sleeping patterns on weekends.

    Google Fit Syncronization:
    Limitations:
    1. Daily summary statistics is synced, so charts by Week and Month will show correct data; chart by day will show correct totals, but not correct hourly breakdown.

    Prerequisites:
    1. You need to have at least version 5.71 of miband_extract package.
    2. You will need to have Internet access and your browser should be configured to enable pop-ups at least from a specific domain below.
    3. You need to open following URL: Get Fit Token and allow it to access your Google Fit data. Latest version of Chrome worked for me, while IE 11 had issues with popups.

    Installation:
    1. Download latest version of meband_fit package and unpack it to the directory where you have miband_extract v5.71 or above.
    2. If you upgrade from previous version of fit sync package, you will need to clean up old data populated by old version. To do so run following command:
    fit clean

    Running Sync:
    1. Synchronize your data from smartphone to desktop.
    2. Obtain a new OATH key for syncing data with Fit - open Get Fit Token and copy resulting string to your clipboard.
    3. Run fit.bat and when asked for new token paste the string from previous step and press enter. If fit.bat did not ask you for token and failed with Authentication error, just run it again.

    Troubleshooting:
    1. The process is logging into fit\*.log files. If you have errors, review these logs first.
    2. The token from step 2 is valid for 1 hour - you will need to refresh the token after that. After 1 hour subsequent fit syncs will start failing until you obtain a new token.
    3. Current token is cached in GKey environment variable. Once batch determines that old token is expired, it would clean the variable and will ask you for a new key on a subsequent run.
    6
    Related links:

    Latest version of Bonoboo port for smartphone extraction.

    Known Issues:

    1. Vertical axis is not always in sync for two charts in mi_data_byDoW.html
    2. Timeline axis is only shown at the bottom of timeline

    Version History:
    Code:
    [B]v5.92 06/20/2015[/B]
    Added support for Mi Scale - extracting weight history into weight.csv
    
    [B]v5.90 03/14/2015[/B]
    Walking and Running statistics with minute granularity are now extracted from Raw data thanks to the input provided by mritsch and Osid.
    
    [B]v5.80 03/07/2015[/B]
    Google Fit sync package 0.3:
    Fixed error in 1324438.json file which prevented Fit Sync for some users.
    Added FitTools.bat which allows pulling various information from Google Fit account.
    
    
    [B]v5.80 03/01/2015[/B]
    Extraction package:
    Added experimental support for raw data extraction. To enable raw data extraction, set ExtractRaw=Y in run.bat
    
    Analytics package:
    German localization added to analytics package (thanks to joshmosh)
    default app_locale.js file is added to analytics package to support data extracted from iOS devices.
    
    Data Extraction Tool v0.1 for iOS is added along with instructions on how to manually extract Mi Band data from iPhone
    
    [B]v5.71 02/16/2015[/B]
    Extraction package:
    Extra fields added to extract.csv to support for Google Fit sync v0.2.
    extract.json is not created anymore, this data is now calculated on the fly from extract.csv
    
    Google Fit sync package 0.2:
    Added sync for activity durations (walk duration, run duration, sleep duration)
    Added sync for distance walked. Since distance metric is considered location, Token application will request new permission:
    https://www.googleapis.com/auth/fitness.location.write
    Fixed activity timestamps - Google Fit expects time to be in UTC time zone.
    
    [B]v5.70 02/16/2015[/B]
    Extraction package:
    Initial support for Google Fit sync.
    
    Google Fit package 0.1:
    Initial release
    
    [B]v5.50 02/05/2015[/B]
    Extraction package:
    Added new columns to CSV file for better FitnessSyncer compatibility.
    Added support for time correction. See db\offset.sql for sample entries.
    Updated run.sh from [URL="http://xdaforums.com/member.php?u=6091617"]jlaunay[/URL] to support new run.bat parameters and localization.
    
    Analytics package:
    Changed mi_data_byDoW.html to use AnnotationChart for right graph - support for time interval zooming.
    Added new metric to mi_data_byDoW.html called "SleepTimeline" to show Sleep Timeline chart.
    Various small fixes.
    
    [B]v5.35 02/03/2015[/B]
    Extraction package:
     Fixed logging issue - adb would sometimes lock the log files and subsequent extraction invocations would fail completely on locked log files.
     Added support for ADB over Wifi - see instructions in the first post.
    
    Analytics package:
     Fixed sorting order on main table
     Second fix for incorrect sleep/wake hours calculation
     Updated colors across all reports to be consistent
     Converted total/deep/light sleep from minutes to hours and minutes in the main table. Show percentages of deep/light sleep compared to total sleep.
     Add fall asleep and wake up times as selecrable metrics to mi_data_byDoW.html
     mi_data_byDoW.html absorbed all functionality from mi_data_Sleep.html - the sleep calendar functionality and sleep timeline is available when you select Total Sleep metric. You will need to scroll down to see sleep timeline chart.
    
    [B]v5.3 02/02/2015[/B]
    Extraction package:
     Add new column with number of walk time + run time in seconds (as per request)
     Added new parameter ForceBackupMode to skip attempt at rooted extraction and go straight for backup mode
    
    [B]v5.2 02/1/2015[/B]
     Splitted program into data extract package and analytics packages. Data extract should be pretty stable now and reports could be updated independently.
     Spanish translation (thanks to Viriatox)
    
    [B]v5.1 01/31/2015 [/B]
     Fix for incorrect sleep/wake hours calculation
    
    [B]v5.0 01/31/2015[/B]
     Localization setting is pulled from Mi database - no need to set it manually anymore (in most cases)
     Two completely new reports - Sleep Report and Statistics by day of the week.
     Fixes to unix shell script encoding.
    
    [B]v4.0 01/29/2015[/B]
     Month number calculation fixed.
     Removed extra rows with zeroes that we incorrectly extracted
     Localization moved to separate file, all other components are unified for all languages
     Scripts for rooted and non-rooted phones combined into one.
     Daily goals and data grouping added on main report.
     Unix shell script for data extraction (thanks to jlaunay)
     French translation (thanks to jlaunay)
    
    [B]v3.0 01/26/2015[/B]
     New script to support data extraction for non-rooted phones
     Reverse sort order in table part of report, so newest dates are on top.
     Week number and day of the week added to report.
    
    [B]v2.0 01/25/2015 [/B]
     All needed Windows binaries included in the package.
     Batch file to automatically run all binaries to extract the data.
     First report showing overall statistics.
    
    [B]v1 01/24/2015[/B]
     Initial release.
    Syncronizing with fitnesssyncer.com

    FitnessSyncer FAQ: https://www.fitnesssyncer.com/frequently-asked-questions

    How to set up import and export.
    1. Open account at fitnesssyncer.com/
    2. On Dashboard, go to Sources and Destinations and select Add New Source
    3. Select Type: Activity, source Amazon S3 (CSB), Dropbox (CSV) or OneDrive (CSV) depending on where your files are stored. Enter path and file name in Path field. Select highlighted columns mappings:
    Activity:
    Include Date (US) - Column 18
    Include Activity - Column 19
    Include Distance in Meters - Column 8
    Include Duration in Seconds - Column 17
    Include Calories Burned - Column 10
    Include Total Steps - Column 9
    46zy4jo.gif

    4. Click on Save and authenticate into your cloud storage account.
    5. Back on Sources and Destinations account, click on Sync Now link next to your newly added connection to confirm that it loads without errors. Click on Dashboard button and confirm that you see some data in charts there.
    6. Go back to Sources and Destinations and select Add New Source again
    7. This time, select Type: Sleep, same Source entry, same Path value and set up highlighted column mappings:
    Sleep:
    Include Date (US) - Column 18
    Include Bed Time Hour - Column 20
    Include Bed Time minute - Column 21
    Include Awake Hour - Column 22
    Include Awake Minute - Column 23
    Include Sleeping Minutes - Column 2
    DiNbtiC.gif

    8. Click Save, go to Sources and Destinations and click Sync Now on Sleep source now to see that it imports without issues.
    9. Click on Stream option and see that you have both Daily Activity and Sleep data loaded.
    10. Go back to Sources and Destinations and select Add New Destination Task
    Fz6xrJf.gif

    11. Select SyncType Activity and select Destination from the dropdown list
    QssJ4Lq.gif

    12. Repeat same steps for Sleep syncronization

    Accessing your charts directly from Dropbox:
    If you have a Public folder on your dropbox, you can copy all the .js and .html files there and get the shared url by selecting one of htmk files and selecting "Copy public link..." button. It would give you a URL that you can use from anywhere. You need to have Dropbox Pro account or free account created before October 4, 2012 for Public folder functionality to work on your dropbox.
    jnFSzaf.gif

    Accessing your charts directly from Google Drive:
    1. It is recommended that you create new folder in your Drive for this purpose.
    2. Select the folder and Choose Share... option
    3. On Share with others page dialog, click on Advanced button in bottom right corner.
    4. On Sharing Settings dialog, click on Change... link at the top line of Who has access list.
    5. On Link sharing dialog, select On - Public on the web option and click Save button.
    6. Copy the URL that is shown on Sharing Settings page and click Done to close it
    7. The URL that you copied will look something like the sample below. Copy just the alphanumeric sequence that is located between ?id= and &usp=sharing
    Code:
    https://drive.google.com/folderview?id=[B][COLOR="Red"]123-abcdcdefghijklmnopqrstUV[/COLOR][/B]&usp=sharing
    8. Put www.googledrive.com/host/ before this string and /mi_data.html (or any other report) after it, you should get something like www.googledrive.com/host/123-abcdcdefghijklmnopqrstUV/mi_data.html - this should be your sharing link

    Here is Google support page on sharing files/directories: https://support.google.com/drive/answer/2881970?hl=en

    Using Helium backup instead of Android backup:

    Helium produces .ab files that are ALMOST correct tar file, however besides extra characters on file header level they also have some differences in header entries for each file. I've looked through different methods and utilities and the best option so far is to use Helium_ab2tar.zip package (credit goes to xaos.cz for writing it and to johnny1176 for discovering it). It used to be available on xaos.ic.cz/Helium_ab2tar.zip, but that site is down now. You can still google for Helium_ab2tar.zip to find other locations that have copy of this file.

    Plans for future versions:
    Code:
    0. Get more sleep :)
    1. Titles for each chart
    2. Implement dashboard comparing current week with previous statistical data. (For same days of week)
    3. Use timeline component for right chart in data_byDow.htm
    4. Show percentage of good days based on selected goals. Show min/max values for each metric.
    5. Modify scatter chart to allow using any other series for X axis (Search/display correlations between sleep time and total number of steps).
    6. Make a help page showing all the charts and how to use them.
    7. Add ratio of deep/light sleep as part of selectable charts.
    8. Merge all reports into single multi-tab document.
    9. Parse detailed daily binary data - this is going to be a big one.
    How to translate application to your language:

    To add support for a new language:
    For HTML pages
    1. Open locale.js in editor supporting UTF-8 encoding.
    2. Create a new section starting with
    if (lang == "ru_RU") { }
    and replace ru_RU with a locale string for your language.
    3. Copy all strings from english version to inside { } brackets and translate the text.
    4. Save file in UTF-8 encoding.
    5. Add reference to your new language in comments section of config.js

    For unix shell script:
    For all subsequent entries, replace XX with 2-character locale name of your language

    1. Create new po file using following command:
    bash --dump-po-strings run.sh > po/XX.po
    2. Edit newly generated file and translate msgstr entries using msgid entries as references
    3. Save the file and generate new directory for the compiled langage file (.mo) using following command:
    mkdir -p i18n/XX/LC_MESSAGES/
    4. Compile .po file to .mo file by running following command:
    msgfmt -o i18n/XX/LC_MESSAGES/mibandextract.mo po/XX.po

    If you do not want to use the i18n folder and want the langage file to be system wide, you just have to comment (adding a #) the line "export TEXTDOMAINDIR=./i18n/" in the script.
    Then you will have to move your po file to /usr/share/locale/XX/LC_MESSAGES/ (where XX is your langage).
    5
    Changelog:
    v5.2 released on 2/1/2015.
    v5.3 released on 2/2/2015.
    v5.32 released on 2/3/2015
    v5.7 released on 2/16/2015
    v5.71 + fit v0.2 released on 2/21/2015
    v5.8 + fit v0.3 released on 3/7/2015
    v5.9 released on 3/14/2015
    v5.92 released on 6/20/2015
    5
    From my perception the corresponding class is located in cn\com\smartdevices\bracelet\analysis\DataAnalysis.java

    I'll share my findings.
    Sorry for my bad English.

    Mi band sends ActivityData to app. Each ActivityData is 1 minute long and are 3 bytes.

    (category, intensity, steps)

    steps is the most obvious.

    You'll find those bytes in data blob of date_data table or, if you have miband_log.txt on /sdcard in JSON sended to server (data property, base64 encoded).

    App "rewrites" them in SportData class.

    SportData is

    (timeIndex, activity, mode, runs, step)

    timeIndex = minute of day (1-1440)
    step = steps in a minute

    the others are calculated as follows (pseudo Java code):

    category, intensity, steps

    if (category == 0x7f) {
    mode = category;
    } else {
    mode = category & 0xf;
    if (step > 0) {
    runs = category >> 4;
    }
    activity = intensity
    step = steps

    Now, some formula which Mi fit uses to calculate distance and calories burned every minute

    d = height_in_cm * 3 / 100
    iDistance = (step <= 90) ? (step*d*0.9) : (step^2*d)/(step > 120 ? 125 : 100)

    runDistance = (((runs * 2) + 3) * iDistance) / 15;

    For calories it uses a lookup table of doubles:

    calList = {40.233d, 0.95d}, {53.645d, 1.19d}, {67.056d, 1.41d}, {80.467d, 1.57d}, {93.878d, 1.78d}, {107.29d, 2.36d}, {120.7d, 2.97d}, {134.11d, 3.79d}, {160.94d, 4.67d}, {187.76d, 5.24d}, {214.58d, 5.62d}, {241.4d, 6.1d}, {268.23d, 6.91d}, {295.05d, 7.62d}, {321.87d, 9.05d}, {348.69d, 9.43d}, {375.52d, 10.95d}};

    calList index is the max of calList 1st value less than iDistance.

    cals = (weight_in_kg * 2.2046 * calList i-th tuple[1] * iDistance) / (60 * calList i-th tuple[0])

    runCalories = (cals * ((runs * 2) + 3) / 15);

    Some examples taken for logcat:

    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis i=2274:steps=67
    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis iDistance=42.547680,p=1,cals=119.911552
    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis i=2275:steps=100
    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis iDistance=70.560000,p=3,cals=123.047801
    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis i=2276:steps=97
    03-13 23:05:54.220 5092-5140/com.xiaomi.hm.health D/dataProcess? DataAnalysis iDistance=66.389904,p=2,cals=126.227996

    BTW: I'm 168cm and 62kg :D

    After that algorithm finds intervals. How?


    for (Iterating over all sportDatas, i used as index [minute]) }
    startMode = sportData.mode;
    if (spordData.mode != sportData[i-1].mode) {
    if ((sportmode[i - 1] == 0 && sportmode - startmode >= 10) || !(sportmode[i - 1] == 1 || sportmode[i - 1] == 2 || sportmode[i - 1] == 0)) {
    this is an interval startMode -> i-1
    }
    } else {
    i++;
    }
    }

    Intervals are discarded.
    The remaining gaps are filtered (I have't still reverse engineered Java method filterData) and under some conditions it finds sections which are the real sections showed in graphs on Mi Fit app.

    I haven't see SleepAnalysis.


    I've developed, for internal use, an Xposed module which hooks into MiLiProfile class of Mi Fit and through intents is able to control vibration, LEDs, realtime steps, sensors, etc.
    Maybe, in the future, I'll release it with Tasker integration and/or as a standalone app (without Xposed) if there's some interest.

    Hope to help you ;)