Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
239db9758d | ||
|
|
d15fa26e79 | ||
|
|
4d1dd75c9d |
@@ -54,7 +54,7 @@ async function main() {
|
|||||||
console.log("Going ahead with", act.activityId, act.activityType.typeKey)
|
console.log("Going ahead with", act.activityId, act.activityType.typeKey)
|
||||||
|
|
||||||
await garmin.downloadOriginalActivityData(act, "/tmp/", "tcx")
|
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})
|
input.tags.push({key: "gc:ActivityID", value: id})
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -53,4 +53,4 @@ export default class Trimlog {
|
|||||||
this.token = data.access_token;
|
this.token = data.access_token;
|
||||||
this.tokenExpiry = new Date(Date.now() + (data.expires_in * 1000 * 0.95));
|
this.tokenExpiry = new Date(Date.now() + (data.expires_in * 1000 * 0.95));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-49
@@ -1,7 +1,7 @@
|
|||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import { parseString } from "xml2js";
|
import { parseString } from "xml2js";
|
||||||
|
|
||||||
export function generateTrimlogInput(filename, name = "Walk") {
|
export function generateTrimlogInput(filename, name = "Walk", type = "walk") {
|
||||||
return new Promise(async(resolve, reject) => {
|
return new Promise(async(resolve, reject) => {
|
||||||
parseString(await fs.readFile(filename, "utf-8"), (err, res) => {
|
parseString(await fs.readFile(filename, "utf-8"), (err, res) => {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
@@ -26,9 +26,9 @@ export function generateTrimlogInput(filename, name = "Walk") {
|
|||||||
time: tp.Time[0],
|
time: tp.Time[0],
|
||||||
longitude: parseFloat(tp.Position?.[0]?.LongitudeDegrees[0]),
|
longitude: parseFloat(tp.Position?.[0]?.LongitudeDegrees[0]),
|
||||||
latitude: parseFloat(tp.Position?.[0]?.LatitudeDegrees[0]),
|
latitude: parseFloat(tp.Position?.[0]?.LatitudeDegrees[0]),
|
||||||
altitude: parseFloat(tp.AltitudeMeters[0]),
|
altitude: parseFloat(tp.AltitudeMeters?.[0]),
|
||||||
distance: parseFloat(tp.DistanceMeters[0]),
|
distance: parseFloat(tp.DistanceMeters?.[0]),
|
||||||
heartrate: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]),
|
pulse: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (minAltitude == null || point.altitude < minAltitude) {
|
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 = {
|
const out = {
|
||||||
date: dateStr,
|
date: dateStr,
|
||||||
contents: [{rawActivity: {
|
contents: [{rawActivity: {
|
||||||
kind: "Walking",
|
kind: type === "cycling" ? "Biking" : "Walking",
|
||||||
sets: [],
|
sets: [],
|
||||||
effortScale: 1,
|
effortScale: 1,
|
||||||
weight: 0,
|
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),
|
seconds: Math.round((new Date(p.time) - date) / 1000),
|
||||||
meters: p.distance,
|
meters: p.distance,
|
||||||
pulse: p.heartrate,
|
pulse: p.pulse,
|
||||||
|
longitude: p.longitude || firstLon,
|
||||||
|
latitude: p.latitude || firstLat,
|
||||||
|
altitude: p.altitude || firstAlt,
|
||||||
}))
|
}))
|
||||||
}}],
|
}}],
|
||||||
description: name,
|
description: name,
|
||||||
@@ -75,45 +83,3 @@ export function today() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pad(n) {return n > 9 ? n.toString() : `0${n}`}
|
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