From 249ead70b1e15d92e1f6d6f1fa7ab550c50044bd Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 27 Dec 2024 09:59:30 +0000 Subject: [PATCH] Updates --- .config/Code - OSS/User/settings.json | 3 +- .local/bin/fitness_data_to_fnf_import.js | 94 ++++++++++++++++++++++++ .local/bin/setup/setupprinter | 2 +- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 .local/bin/fitness_data_to_fnf_import.js diff --git a/.config/Code - OSS/User/settings.json b/.config/Code - OSS/User/settings.json index d5f645d..84615ba 100644 --- a/.config/Code - OSS/User/settings.json +++ b/.config/Code - OSS/User/settings.json @@ -24,5 +24,6 @@ "extensions.experimental.affinity": { "asvetliakov.vscode-neovim": 1 }, - "explorer.confirmDragAndDrop": false + "explorer.confirmDragAndDrop": false, + "terminal.integrated.enableMultiLinePasteWarning": false } diff --git a/.local/bin/fitness_data_to_fnf_import.js b/.local/bin/fitness_data_to_fnf_import.js new file mode 100644 index 0000000..e8143f8 --- /dev/null +++ b/.local/bin/fitness_data_to_fnf_import.js @@ -0,0 +1,94 @@ +const fs = require('fs'); + +const input = fs.readFileSync('./Chris S. Coaching Tracker - Weekly Tracker.csv', 'utf8'); + +const rows = []; + +const week = { + 'Chest': null, + 'Right thigh': null, + 'Left thigh': null, + 'Waist': null, + 'Left biceps': null, + 'Right biceps': null, +} + +let year = 2023; + +input.split("\n").forEach((line) => { + if (line.includes(' 1 Jan')) { + year++; + } + const map = { + 'R Arm': 'Right biceps', + 'L Arm': 'Left biceps', + 'Navel': 'Waist', + 'Chest': 'Chest', + 'R Leg': 'Right thigh', + 'L Leg': 'Left thigh', + } + for (let key in map) { + const val = map[key]; + const match = line.match(new RegExp(`${key},([^,]+)`)); + if (match) { + week[val] = (1*match[1]).toPrecision(3); + } + } + if (line.startsWith('"Sun')) { + const match = line.match(/^"(Sun[^"]+)\s*"/)[1]; + const date = new Date(`${match} UTC`); + date.setFullYear(year); + + for (let key in week) { + const val = week[key]; + rows.push(`BODYMEASURE,${date.toJSON().split('T')[0]},${key},${val},cm`); + } + } +}); + +['Weight', 'Weight(1)', 'Weight(2)', 'Weight(3)'].forEach((name) => { + const weightInput = fs.readFileSync(`./${name}.csv`, 'utf8').split("\n"); + + weightInput.shift(); + for (let i = 0; i < weightInput.length;) { + if (!weightInput[i] || !weightInput[i + 1]) { + i++; + continue; + } + const date = new Date(`${weightInput[i].substring(2, weightInput[i].length - 2)} UTC`); + const [time, weight, change, bmi, fat, muscle, bone, water] = weightInput[i + 1].split(',') + + if (weight && weight !== '--') { + const [kg, units] = weight.split(' '); + rows.push(`BODYMEASURE,${date.toJSON().split('T')[0]},Weight,${kg},${units}`); + } + + if (fat && fat !== '--') { + const [perc, units] = fat.split(' '); + rows.push(`BODYMEASURE,${date.toJSON().split('T')[0]},Fat,${perc},${units}`); + } + + if (muscle && muscle !== '--' && weight && weight !== '--') { + const [kg, units] = muscle.split(' '); + const weightKg = weight.split(' ')[0]; + const perc = (100 * kg / weightKg).toPrecision(3); + rows.push(`BODYMEASURE,${date.toJSON().split('T')[0]},Muscles,${perc},%`); + } + + if (water && water !== '--') { + const [perc, units] = water.split(' '); + rows.push(`BODYMEASURE,${date.toJSON().split('T')[0]},Water,${perc},${units}`); + } + + i++; + while (weightInput[i] && weightInput[i][0] !== '"') { + i++; + } + } +}); + +rows.sort(); + +rows.unshift('TABLE,DATE,BODYPART_NAME,MEASURE,UNIT'); + +fs.writeFileSync('./fnfImport.csv', rows.join("\n")); diff --git a/.local/bin/setup/setupprinter b/.local/bin/setup/setupprinter index d39e65a..ae5b790 100755 --- a/.local/bin/setup/setupprinter +++ b/.local/bin/setup/setupprinter @@ -6,7 +6,7 @@ sudo sed -i 's/hosts: files mymachines myhostname resolve [!UNAVAIL=return] dns/ sudo systemctl enable --now avahi-daemon -hp-setup -i 192.168.1.20 +hp-setup -i 192.168.2.77 lpoptions -d DeskJet_3700