Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
239db9758d | ||
|
|
d15fa26e79 | ||
|
|
4d1dd75c9d | ||
|
|
1bd6e0c905 |
@@ -30,6 +30,11 @@ async function main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!["walking", "cycling"].includes(act.activityType?.typeKey)) {
|
||||
console.error("Skipping", act.activityId, `(${act.activityType?.typeKey} activity not supported)`);
|
||||
blackList[id] = true;
|
||||
continue;
|
||||
}
|
||||
if (!act.startTimeLocal.startsWith(todayDate)) {
|
||||
console.error("Skipping", act.activityId, "(not today)");
|
||||
blackList[id] = true;
|
||||
@@ -46,8 +51,10 @@ async function main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("Going ahead with", act.activityId, act.activityType.typeKey)
|
||||
|
||||
await garmin.downloadOriginalActivityData(act, "/tmp/", "tcx")
|
||||
const input = await generateTrimlogInput(`/tmp/${act.activityId}.tcx`, act.activityName)
|
||||
const input = await generateTrimlogInput(`/tmp/${act.activityId}.tcx`, act.activityName, act.activityType?.typeKey)
|
||||
|
||||
input.tags.push({key: "gc:ActivityID", value: id})
|
||||
|
||||
|
||||
+15
-49
@@ -1,7 +1,7 @@
|
||||
import * as fs from "fs/promises";
|
||||
import { parseString } from "xml2js";
|
||||
|
||||
export function generateTrimlogInput(filename, name = "Walk") {
|
||||
export function generateTrimlogInput(filename, name = "Walk", type = "walk") {
|
||||
return new Promise(async(resolve, reject) => {
|
||||
parseString(await fs.readFile(filename, "utf-8"), (err, res) => {
|
||||
if (err != null) {
|
||||
@@ -26,9 +26,9 @@ export function generateTrimlogInput(filename, name = "Walk") {
|
||||
time: tp.Time[0],
|
||||
longitude: parseFloat(tp.Position?.[0]?.LongitudeDegrees[0]),
|
||||
latitude: parseFloat(tp.Position?.[0]?.LatitudeDegrees[0]),
|
||||
altitude: parseFloat(tp.AltitudeMeters[0]),
|
||||
distance: parseFloat(tp.DistanceMeters[0]),
|
||||
heartrate: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]),
|
||||
altitude: parseFloat(tp.AltitudeMeters?.[0]),
|
||||
distance: parseFloat(tp.DistanceMeters?.[0]),
|
||||
pulse: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]),
|
||||
};
|
||||
|
||||
if (minAltitude == null || point.altitude < minAltitude) {
|
||||
@@ -42,17 +42,25 @@ export function generateTrimlogInput(filename, name = "Walk") {
|
||||
}
|
||||
}
|
||||
|
||||
const list = Object.keys(map).sort().map(k => map[k]);
|
||||
const firstLon = list.find(e => !!e.longitude)?.longitude;
|
||||
const firstLat = list.find(e => !!e.latitude)?.latitude;
|
||||
const firstAlt = list.find(e => !!e.altitude)?.altitude;
|
||||
|
||||
const out = {
|
||||
date: dateStr,
|
||||
contents: [{rawActivity: {
|
||||
kind: "Walking",
|
||||
kind: type === "cycling" ? "Biking" : "Walking",
|
||||
sets: [],
|
||||
effortScale: 1,
|
||||
weight: 0,
|
||||
measurements: Object.keys(map).sort().map(k => map[k]).map(p => ({
|
||||
measurements: list.map(p => ({
|
||||
seconds: Math.round((new Date(p.time) - date) / 1000),
|
||||
meters: p.distance,
|
||||
pulse: p.heartrate,
|
||||
pulse: p.pulse,
|
||||
longitude: p.longitude || firstLon,
|
||||
latitude: p.latitude || firstLat,
|
||||
altitude: p.altitude || firstAlt,
|
||||
}))
|
||||
}}],
|
||||
description: name,
|
||||
@@ -75,45 +83,3 @@ export function today() {
|
||||
}
|
||||
|
||||
function pad(n) {return n > 9 ? n.toString() : `0${n}`}
|
||||
|
||||
/*
|
||||
|
||||
{
|
||||
"date": "2023-12-31",
|
||||
"contents": [
|
||||
{
|
||||
"rawActivity": {
|
||||
"kind": "Walking",
|
||||
"sets": [],
|
||||
"measurements": [
|
||||
{
|
||||
"seconds": 1234,
|
||||
"calories": 4321,
|
||||
"meters": 432553
|
||||
},
|
||||
{
|
||||
"seconds": 2468,
|
||||
"calories": 42342,
|
||||
"meters": 3424
|
||||
},
|
||||
{
|
||||
"seconds": 3702,
|
||||
"calories": 23423,
|
||||
"meters": 2342
|
||||
},
|
||||
{
|
||||
"seconds": 4936,
|
||||
"calories": 23423,
|
||||
"meters": 2342
|
||||
}
|
||||
],
|
||||
"effortScale": 1,
|
||||
"weight": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"description": "asdfasdfasdf",
|
||||
"tags": []
|
||||
}
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user