Created
September 26, 2020 12:54
-
-
Save AWare/ff0ce68601039d97b63a0c7ce481e397 to your computer and use it in GitHub Desktop.
Google fit weight to garmin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const parse = require("csv-parse/lib/sync"); | |
| const moment = require("moment"); | |
| const dateRegex = /\d\d\d\d-\d\d-\d\d\.csv/; | |
| const dates = fs.readdirSync(".").filter((_) => dateRegex.test(_)); | |
| //Garmin doesn't want to import fitbit data without bmi and body fat, so just make something up. | |
| const h = 1 ** 2; //height in meters ** 2 | |
| const bf = 100; // current body fat percentage | |
| const current = 0; //current weight | |
| const weights = dates | |
| .map((d) => { | |
| const input = fs.readFileSync(d); | |
| const records = parse(input, { | |
| columns: true, | |
| skip_empty_lines: true, | |
| }); | |
| const withWeight = records.filter((_) => _["Max weight (kg)"] !== ""); | |
| return withWeight | |
| .map((_) => { | |
| const w = parseFloat(_["Max weight (kg)"]); | |
| const bmi = w / h; | |
| const fat = w * (bf / current); | |
| return { | |
| date: moment(d.replace(".csv", "")).format("DD-MM-YYYY"), | |
| weight: w.toFixed(1), | |
| bmi, | |
| fat, | |
| }; | |
| }) | |
| .slice(0, 1); | |
| }) | |
| .reduce((acc, cur) => [...acc, ...cur]); | |
| console.log("Body"); | |
| console.log("Date,Weight,BMI,Fat"); | |
| weights.map(({ date, weight, bmi, fat }) => { | |
| console.log(`"${date}","${weight}","${bmi}","${fat}"`); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this in your "Daily Aggregations" folder in a Google Fit takeout export and it will create a fitbit export file which can be uploaded to Garmin. I couldn't upload without a body fat percentage and bmi, and it did not seem to accept multiple entries per date.