@runnerpro/backend 1.19.9 → 1.19.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
interface WorkoutGarminStep {
|
|
2
|
+
type: string;
|
|
3
|
+
stepOrder: number;
|
|
4
|
+
intensity?: string;
|
|
5
|
+
durationType?: string;
|
|
6
|
+
durationValue?: number;
|
|
7
|
+
durationValueType?: string;
|
|
8
|
+
targetType?: string | null;
|
|
9
|
+
targetValue?: number | null;
|
|
10
|
+
targetValueLow?: number | null;
|
|
11
|
+
targetValueHigh?: number | null;
|
|
12
|
+
repeatType?: string;
|
|
13
|
+
repeatValue?: number;
|
|
14
|
+
steps?: WorkoutGarminStep[];
|
|
15
|
+
}
|
|
16
|
+
interface WorkoutGarmin {
|
|
17
|
+
workoutName: string;
|
|
18
|
+
description: string;
|
|
19
|
+
sport: string;
|
|
20
|
+
workoutProvider: string;
|
|
21
|
+
workoutSourceId: string;
|
|
22
|
+
steps: WorkoutGarminStep[];
|
|
23
|
+
}
|
|
24
|
+
declare const translateWorkoutGarmin: (workout: any) => WorkoutGarmin;
|
|
1
25
|
declare const createWorkoutGarmin: (userid: any, workout: any) => Promise<{
|
|
2
26
|
workoutGarminId: any;
|
|
3
27
|
workoutGarminOwnerId: any;
|
|
@@ -6,5 +30,5 @@ declare const updateWorkoutGarmin: (userid: any, workout: any) => Promise<any>;
|
|
|
6
30
|
declare const deleteWorkoutGarmin: (userid: any, workout: any) => Promise<any>;
|
|
7
31
|
declare const scheduleWorkoutGarmin: (userid: any, workout: any) => Promise<any>;
|
|
8
32
|
declare const updateScheduleWorkoutGarmin: (userid: any, schedule: any, workout: any) => Promise<any>;
|
|
9
|
-
export { createWorkoutGarmin, updateWorkoutGarmin, deleteWorkoutGarmin, scheduleWorkoutGarmin, updateScheduleWorkoutGarmin };
|
|
33
|
+
export { translateWorkoutGarmin, createWorkoutGarmin, updateWorkoutGarmin, deleteWorkoutGarmin, scheduleWorkoutGarmin, updateScheduleWorkoutGarmin, };
|
|
10
34
|
//# sourceMappingURL=garmin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"garmin.d.ts","sourceRoot":"","sources":["../../../../src/workout/garmin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"garmin.d.ts","sourceRoot":"","sources":["../../../../src/workout/garmin.ts"],"names":[],"mappings":"AAoBA,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC7B;AAED,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AA4FD,QAAA,MAAM,sBAAsB,iCAyD3B,CAAC;AA+EF,QAAA,MAAM,mBAAmB;;;EAWxB,CAAC;AAEF,QAAA,MAAM,mBAAmB,6CASxB,CAAC;AAEF,QAAA,MAAM,mBAAmB,6CAMxB,CAAC;AAEF,QAAA,MAAM,qBAAqB,6CAU1B,CAAC;AAEF,QAAA,MAAM,2BAA2B,4DAWhC,CAAC;AAIF,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,GAC5B,CAAC"}
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.updateScheduleWorkoutGarmin = exports.scheduleWorkoutGarmin = exports.deleteWorkoutGarmin = exports.updateWorkoutGarmin = exports.createWorkoutGarmin = void 0;
|
|
15
|
+
exports.updateScheduleWorkoutGarmin = exports.scheduleWorkoutGarmin = exports.deleteWorkoutGarmin = exports.updateWorkoutGarmin = exports.createWorkoutGarmin = exports.translateWorkoutGarmin = void 0;
|
|
16
16
|
const db_1 = require("../db");
|
|
17
17
|
const common_1 = require("@runnerpro/common");
|
|
18
18
|
const estructuraWorkout_1 = require("./estructuraWorkout");
|
|
@@ -65,6 +65,25 @@ const garminOauthActivity = ({ url, httpMethod, userid, params = {} }) => __awai
|
|
|
65
65
|
const secondsPerKmToMetersPerSecond = (secondsPerKm) => {
|
|
66
66
|
return Math.round((1000 / secondsPerKm) * 100) / 100;
|
|
67
67
|
};
|
|
68
|
+
const getWorkoutGarminDuration = (workout) => {
|
|
69
|
+
const rangePlanning = (0, common_1.getWorkoutRangePlanning)({
|
|
70
|
+
workoutType: workout.type,
|
|
71
|
+
distancePlanned: workout.distancePlanned,
|
|
72
|
+
durationPlanned: workout.durationPlanned,
|
|
73
|
+
zonePlanned: workout.zonePlanned,
|
|
74
|
+
});
|
|
75
|
+
if (rangePlanning.fixedMetric === common_1.WORKOUT_FIXED_METRIC.TIME) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'TIME',
|
|
78
|
+
value: Number(workout.durationPlanned),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
type: 'DISTANCE',
|
|
83
|
+
value: Number(workout.distancePlanned),
|
|
84
|
+
valueType: 'METER',
|
|
85
|
+
};
|
|
86
|
+
};
|
|
68
87
|
const typeTranslateWorkoutGarmin = (type) => {
|
|
69
88
|
if (type === common_1.WORKOUT_TYPE.FUERZA)
|
|
70
89
|
return 'STRENGTH_TRAINING';
|
|
@@ -111,13 +130,14 @@ const translateWorkoutGarmin = (workout) => {
|
|
|
111
130
|
return null;
|
|
112
131
|
const targetType = getWorkoutGarminTargetType(workout, null);
|
|
113
132
|
const targetValue = getWorkoutGarminTargetValue(workout, null);
|
|
133
|
+
const duration = getWorkoutGarminDuration(workout);
|
|
114
134
|
workoutGarmin.steps.push({
|
|
115
135
|
type: 'WorkoutStep',
|
|
116
136
|
stepOrder: 1,
|
|
117
137
|
intensity: 'ACTIVE',
|
|
118
|
-
durationType:
|
|
119
|
-
durationValue:
|
|
120
|
-
durationValueType:
|
|
138
|
+
durationType: duration.type,
|
|
139
|
+
durationValue: duration.value,
|
|
140
|
+
durationValueType: duration.valueType,
|
|
121
141
|
targetType,
|
|
122
142
|
targetValue: targetValue.value,
|
|
123
143
|
targetValueLow: targetValue.low,
|
|
@@ -148,6 +168,7 @@ const translateWorkoutGarmin = (workout) => {
|
|
|
148
168
|
}
|
|
149
169
|
return workoutGarmin;
|
|
150
170
|
};
|
|
171
|
+
exports.translateWorkoutGarmin = translateWorkoutGarmin;
|
|
151
172
|
const getWorkoutGarminStep = (workout, row, stepOrder) => {
|
|
152
173
|
const targetType = getWorkoutGarminTargetType(workout, row);
|
|
153
174
|
const targetValue = getWorkoutGarminTargetValue(workout, row);
|
|
@@ -174,6 +195,7 @@ const getWorkoutGarminTargetType = (workout, row) => {
|
|
|
174
195
|
};
|
|
175
196
|
const getWorkoutGarminTargetValue = (workout, row) => {
|
|
176
197
|
let value;
|
|
198
|
+
let paceRange = null;
|
|
177
199
|
if (!row) {
|
|
178
200
|
// Si es entrenamiento de bicicleta y tiene potencia -> value = potencia
|
|
179
201
|
// if (workout.type === WORKOUT_TYPE.BIKE && workout.powerPlanned) {
|
|
@@ -182,6 +204,12 @@ const getWorkoutGarminTargetValue = (workout, row) => {
|
|
|
182
204
|
// El resto calcular el ritmo
|
|
183
205
|
// No se puede añadir potencia ya que el valor que hay que dar es una zona, no absoluto
|
|
184
206
|
value = Number(workout.distancePlanned) / Number(workout.durationPlanned);
|
|
207
|
+
paceRange = (0, common_1.getWorkoutRangePlanning)({
|
|
208
|
+
workoutType: workout.type,
|
|
209
|
+
distancePlanned: workout.distancePlanned,
|
|
210
|
+
durationPlanned: workout.durationPlanned,
|
|
211
|
+
zonePlanned: workout.zonePlanned,
|
|
212
|
+
}).paceRange;
|
|
185
213
|
// }
|
|
186
214
|
}
|
|
187
215
|
else {
|
|
@@ -192,8 +220,15 @@ const getWorkoutGarminTargetValue = (workout, row) => {
|
|
|
192
220
|
else if (Number(row.typeMetric2) === 3)
|
|
193
221
|
value = Number(row.valueMetric2);
|
|
194
222
|
// El resto de casos se calcula el ritmo
|
|
195
|
-
else
|
|
223
|
+
else {
|
|
196
224
|
value = secondsPerKmToMetersPerSecond(row.valueMetric2);
|
|
225
|
+
if ([common_1.WORKOUT_TYPE.CORRER, common_1.WORKOUT_TYPE.COMPETICION].includes(workout.type)) {
|
|
226
|
+
paceRange = (0, common_1.getWorkoutPaceRangeByZone)({
|
|
227
|
+
pace: Number(row.valueMetric2),
|
|
228
|
+
zonePlanned: row.zoneMetric2,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
197
232
|
}
|
|
198
233
|
if (!value) {
|
|
199
234
|
return {
|
|
@@ -205,8 +240,8 @@ const getWorkoutGarminTargetValue = (workout, row) => {
|
|
|
205
240
|
else {
|
|
206
241
|
return {
|
|
207
242
|
value,
|
|
208
|
-
low: value - value * 0.02,
|
|
209
|
-
high: value + value * 0.02,
|
|
243
|
+
low: paceRange ? secondsPerKmToMetersPerSecond(paceRange.max) : value - value * 0.02,
|
|
244
|
+
high: paceRange ? secondsPerKmToMetersPerSecond(paceRange.min) : value + value * 0.02,
|
|
210
245
|
};
|
|
211
246
|
}
|
|
212
247
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runnerpro/backend",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.12",
|
|
4
4
|
"description": "A collection of common backend functions",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/cjs/index.js"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"deploy": "npm run build && npm publish",
|
|
17
17
|
"semantic-release": "semantic-release",
|
|
18
18
|
"lint": "eslint --ext .ts --ignore-path .gitignore .",
|
|
19
|
+
"test:translate-workout-garmin": "ts-node --transpile-only scripts/translateWorkoutGarmin.ts",
|
|
19
20
|
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
|
|
20
21
|
"prepare": "husky"
|
|
21
22
|
},
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"@napi-rs/canvas": "^0.1.53",
|
|
55
|
-
"@runnerpro/common": "^1.
|
|
56
|
+
"@runnerpro/common": "^1.7.0",
|
|
56
57
|
"axios": "^1.6.7",
|
|
57
58
|
"image-size": "^1.0.2",
|
|
58
59
|
"jimp": "^0.22.10",
|