@racedayready/workouts 0.1.0 → 0.1.1
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/workouts/workout-types.d.ts +1 -1
- package/dist/workouts/workout-utils.d.ts +4 -0
- package/dist/workouts/workout-utils.d.ts.map +1 -1
- package/dist/workouts/workout-utils.js +30 -0
- package/dist/workouts/workout-utils.js.map +1 -1
- package/dist/workouts/workout-utils.test.d.ts +2 -0
- package/dist/workouts/workout-utils.test.d.ts.map +1 -0
- package/dist/workouts/workout-utils.test.js +61 -0
- package/dist/workouts/workout-utils.test.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC"}
|
|
@@ -163,9 +163,9 @@ export declare const WorkoutSegmentItemSchema: z.ZodUnion<readonly [z.ZodObject<
|
|
|
163
163
|
}, z.core.$strip>], "discipline">]>;
|
|
164
164
|
export type WorkoutSegmentItem = z.infer<typeof WorkoutSegmentItemSchema>;
|
|
165
165
|
export declare const WorkoutDisciplineSchema: z.ZodEnum<{
|
|
166
|
+
swim: "swim";
|
|
166
167
|
bike: "bike";
|
|
167
168
|
run: "run";
|
|
168
|
-
swim: "swim";
|
|
169
169
|
}>;
|
|
170
170
|
export type WorkoutDiscipline = z.infer<typeof WorkoutDisciplineSchema>;
|
|
171
171
|
//# sourceMappingURL=workout-types.d.ts.map
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import type { WorkoutSegmentItem } from './workout-types';
|
|
1
2
|
export declare const generateWorkoutItemId: () => string;
|
|
3
|
+
export declare function getTotalDistanceMeters(segments: WorkoutSegmentItem[]): number;
|
|
4
|
+
export declare function getTotalSegmentCount(segments: WorkoutSegmentItem[]): number;
|
|
5
|
+
export declare function getTotalDurationSeconds(segments: WorkoutSegmentItem[]): number;
|
|
2
6
|
//# sourceMappingURL=workout-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workout-utils.d.ts","sourceRoot":"","sources":["../../src/workouts/workout-utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,cAAmD,CAAC"}
|
|
1
|
+
{"version":3,"file":"workout-utils.d.ts","sourceRoot":"","sources":["../../src/workouts/workout-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,eAAO,MAAM,qBAAqB,cAAmD,CAAC;AAEtF,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAY7E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAO3E;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAU9E"}
|
|
@@ -1,2 +1,32 @@
|
|
|
1
1
|
export const generateWorkoutItemId = () => Math.random().toString(36).substring(2, 9);
|
|
2
|
+
export function getTotalDistanceMeters(segments) {
|
|
3
|
+
return segments.reduce((total, segment) => {
|
|
4
|
+
if (segment.type === 'group') {
|
|
5
|
+
const groupDistance = segment.segments.reduce((sum, item) => {
|
|
6
|
+
return sum + ('target_distance_meters' in item ? (item.target_distance_meters ?? 0) : 0);
|
|
7
|
+
}, 0);
|
|
8
|
+
return total + groupDistance * segment.repeatCount;
|
|
9
|
+
}
|
|
10
|
+
return (total + ('target_distance_meters' in segment ? (segment.target_distance_meters ?? 0) : 0));
|
|
11
|
+
}, 0);
|
|
12
|
+
}
|
|
13
|
+
export function getTotalSegmentCount(segments) {
|
|
14
|
+
return segments.reduce((total, segment) => {
|
|
15
|
+
if (segment.type === 'group') {
|
|
16
|
+
return total + segment.segments.length * segment.repeatCount;
|
|
17
|
+
}
|
|
18
|
+
return total + 1;
|
|
19
|
+
}, 0);
|
|
20
|
+
}
|
|
21
|
+
export function getTotalDurationSeconds(segments) {
|
|
22
|
+
return segments.reduce((total, segment) => {
|
|
23
|
+
if (segment.type === 'group') {
|
|
24
|
+
const groupDuration = segment.segments.reduce((sum, item) => {
|
|
25
|
+
return sum + (item.target_duration_seconds ?? 0);
|
|
26
|
+
}, 0);
|
|
27
|
+
return total + groupDuration * segment.repeatCount;
|
|
28
|
+
}
|
|
29
|
+
return total + (segment.target_duration_seconds ?? 0);
|
|
30
|
+
}, 0);
|
|
31
|
+
}
|
|
2
32
|
//# sourceMappingURL=workout-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workout-utils.js","sourceRoot":"","sources":["../../src/workouts/workout-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workout-utils.js","sourceRoot":"","sources":["../../src/workouts/workout-utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,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8B;IACpE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxC,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7B,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,IAA2B,EAAE,EAAE;gBACzF,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,CAAC,CAAC;YACnD,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,OAAO,KAAK,GAAG,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;QACrD,CAAC;QACD,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC,uBAAuB,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC,EAAE,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workout-utils.test.d.ts","sourceRoot":"","sources":["../../src/workouts/workout-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getTotalDistanceMeters, getTotalDurationSeconds, getTotalSegmentCount, } from './workout-utils';
|
|
3
|
+
const swim = (id, overrides) => ({
|
|
4
|
+
type: 'individual',
|
|
5
|
+
id,
|
|
6
|
+
name: id,
|
|
7
|
+
discipline: 'swim',
|
|
8
|
+
zone: 2,
|
|
9
|
+
...overrides,
|
|
10
|
+
});
|
|
11
|
+
const bike = (id, overrides) => ({
|
|
12
|
+
type: 'individual',
|
|
13
|
+
id,
|
|
14
|
+
name: id,
|
|
15
|
+
discipline: 'bike',
|
|
16
|
+
zone: 4,
|
|
17
|
+
...overrides,
|
|
18
|
+
});
|
|
19
|
+
const group = (repeatCount, segments) => ({
|
|
20
|
+
type: 'group',
|
|
21
|
+
id: 'group',
|
|
22
|
+
repeatCount,
|
|
23
|
+
segments: segments,
|
|
24
|
+
});
|
|
25
|
+
describe('getTotalDistanceMeters', () => {
|
|
26
|
+
it('sums individuals and groups, treating missing distance as 0', () => {
|
|
27
|
+
const segments = [
|
|
28
|
+
swim('warmup', { target_distance_meters: 400 }),
|
|
29
|
+
group(3, [
|
|
30
|
+
swim('fast', { target_distance_meters: 100 }),
|
|
31
|
+
swim('easy', { target_distance_meters: 50 }),
|
|
32
|
+
]),
|
|
33
|
+
bike('tempo'), // no distance field
|
|
34
|
+
];
|
|
35
|
+
expect(getTotalDistanceMeters(segments)).toBe(850);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('getTotalDurationSeconds', () => {
|
|
39
|
+
it('sums individuals and groups, treating missing duration as 0', () => {
|
|
40
|
+
const segments = [
|
|
41
|
+
bike('warmup', { target_duration_seconds: 600 }),
|
|
42
|
+
group(3, [
|
|
43
|
+
bike('on', { target_duration_seconds: 300 }),
|
|
44
|
+
bike('off', { target_duration_seconds: 300 }),
|
|
45
|
+
]),
|
|
46
|
+
swim('cooldown'), // no duration
|
|
47
|
+
];
|
|
48
|
+
expect(getTotalDurationSeconds(segments)).toBe(2400);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('getTotalSegmentCount', () => {
|
|
52
|
+
it('counts individuals as 1 and group segments multiplied by repeatCount', () => {
|
|
53
|
+
const segments = [
|
|
54
|
+
swim('warmup'),
|
|
55
|
+
group(3, [swim('on'), swim('off')]),
|
|
56
|
+
swim('cooldown'),
|
|
57
|
+
];
|
|
58
|
+
expect(getTotalSegmentCount(segments)).toBe(8);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=workout-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workout-utils.test.js","sourceRoot":"","sources":["../../src/workouts/workout-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C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