Compare commits
45 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
da62a0f5c6 | |
|
|
1a0d26f4ca | |
|
|
c9ab304460 | |
|
|
e32b65926f | |
|
|
e49a1738ec | |
|
|
29cdd41966 | |
|
|
6bbdea1908 | |
|
|
cec3c57477 | |
|
|
198d678ccd | |
|
|
5de1049834 | |
|
|
93684069f0 | |
|
|
574272602f | |
|
|
ba92dd50d1 | |
|
|
99dd16199d | |
|
|
a61f80cde4 | |
|
|
67f09cc0bd | |
|
|
7d934408fd | |
|
|
22f71ba51f | |
|
|
9012a38917 | |
|
|
dd6410d896 | |
|
|
bfae2b12e0 | |
|
|
5aa11ddb3d | |
|
|
6fd4b1c75f | |
|
|
6200dc75c1 | |
|
|
9a2e3dafc9 | |
|
|
f2b293ba21 | |
|
|
7b30277143 | |
|
|
effa11ad75 | |
|
|
c958e5e007 | |
|
|
c6aa02bb06 | |
|
|
97f6beb1a8 | |
|
|
7910e74367 | |
|
|
c1cbdc28e8 | |
|
|
a0bf62998e | |
|
|
fb1eba6db0 | |
|
|
38fb79b2a3 | |
|
|
92b21d2095 | |
|
|
3c3bd3a6a0 | |
|
|
798b05c014 | |
|
|
90e1664ed6 | |
|
|
ea00d550fe | |
|
|
2f7b11d4ac | |
|
|
1a720c2b21 | |
|
|
51590f1f61 | |
|
|
cb7e439a90 |
|
|
@ -18,7 +18,7 @@ Editing .zwo files by hand is also inconvenient:
|
||||||
|
|
||||||
- you'll have to constantly convert minutes to seconds,
|
- you'll have to constantly convert minutes to seconds,
|
||||||
- you can easily make errors in XML syntax, rendering the file invalid,
|
- you can easily make errors in XML syntax, rendering the file invalid,
|
||||||
- The syntax is quite inconsistent, making it hard to memoize.
|
- [it's really a bad format.][zwo-sucks]
|
||||||
|
|
||||||
There are a few alternative editors online:
|
There are a few alternative editors online:
|
||||||
|
|
||||||
|
|
@ -115,8 +115,11 @@ console.log(stats(workout));
|
||||||
- Repeats (and nested repeats)
|
- Repeats (and nested repeats)
|
||||||
- Unsupported params: message duration & y-position
|
- Unsupported params: message duration & y-position
|
||||||
- More restricted syntax for text (with quotes)
|
- More restricted syntax for text (with quotes)
|
||||||
|
- Concatenate similar intervals
|
||||||
|
- Distinguish between terrain-sensitive and insensitive free-ride.
|
||||||
|
|
||||||
[zwift]: https://zwift.com/
|
[zwift]: https://zwift.com/
|
||||||
[zwofactory]: https://zwofactory.com/
|
[zwofactory]: https://zwofactory.com/
|
||||||
[simple zwo creator]: https://zwifthacks.com/app/simple-zwo-creator/
|
[simple zwo creator]: https://zwifthacks.com/app/simple-zwo-creator/
|
||||||
[workout-editor]: https://nene.github.io/workout-editor/
|
[workout-editor]: https://nene.github.io/workout-editor/
|
||||||
|
[zwo-sucks]: http://nene.github.io/2021/01/14/zwo-sucks
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
Name: Ramps
|
||||||
|
Author: R.Saarsoo
|
||||||
|
Description:
|
||||||
|
Various kinds of ramp intervals.
|
||||||
|
|
||||||
|
Ramp: 5:00 40%..75%
|
||||||
|
|
||||||
|
Ramp: 10:00 80%..90%
|
||||||
|
Ramp: 10:00 90%..80%
|
||||||
|
|
||||||
|
Warmup: 10:00 80%..90%
|
||||||
|
Cooldown: 10:00 90%..80%
|
||||||
|
|
||||||
|
Ramp: 5:00 75%..40%
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
Name: Threshold Dev
|
||||||
|
Description: From 10-12WK FTP Builder
|
||||||
|
Author: Zwift
|
||||||
|
|
||||||
|
Warmup: 10:00 50%..65%
|
||||||
|
Warmup: 5:00 50%..100%
|
||||||
|
Interval: 2:00 65%
|
||||||
|
Interval: 2:00 81%
|
||||||
|
Interval: 1:00 95%
|
||||||
|
|
||||||
|
Rest: 5:00 50%
|
||||||
|
|
||||||
|
Interval: 12:00 81%
|
||||||
|
Rest: 8:00 50%
|
||||||
|
Interval: 12:00 81%
|
||||||
|
Rest: 8:00 50%
|
||||||
|
|
||||||
|
Interval: 5:00 95%
|
||||||
|
Rest: 2:00 50%
|
||||||
|
Interval: 5:00 95%
|
||||||
|
Rest: 2:00 50%
|
||||||
|
Interval: 5:00 95%
|
||||||
|
Rest: 2:00 50%
|
||||||
|
Interval: 5:00 95%
|
||||||
|
Rest: 2:00 50%
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "zwiftout",
|
"name": "zwiftout",
|
||||||
"version": "0.3.0",
|
"version": "2.3.0",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"description": "Zwift workout generator command line tool and library",
|
"description": "Zwift workout generator command line tool and library",
|
||||||
"author": "Rene Saarsoo <github@triin.net>",
|
"author": "Rene Saarsoo <github@triin.net>",
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"bin": {
|
"bin": {
|
||||||
"zwiftout": "./bin/zwiftout.js"
|
"zwiftout": "bin/zwiftout.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"argparse": "^2.0.1",
|
"argparse": "^2.0.1",
|
||||||
|
|
|
||||||
|
|
@ -47,17 +47,38 @@ export class RangeIntensity implements Intensity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FreeIntensity implements Intensity {
|
export class RangeIntensityEnd implements Intensity {
|
||||||
|
constructor(private _end: number) {}
|
||||||
|
|
||||||
get value() {
|
get value() {
|
||||||
return 0;
|
return this._end;
|
||||||
}
|
}
|
||||||
|
|
||||||
get start() {
|
get start(): number {
|
||||||
return 0;
|
throw new Error("RangeIntensityEnd has no start");
|
||||||
}
|
}
|
||||||
|
|
||||||
get end() {
|
get end() {
|
||||||
return 0;
|
return this._end;
|
||||||
|
}
|
||||||
|
|
||||||
|
get zone() {
|
||||||
|
return intensityValueToZoneType(this.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FreeIntensity implements Intensity {
|
||||||
|
get value() {
|
||||||
|
// To match Zwift, which gives 64 TSS for 1h of freeride.
|
||||||
|
return 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
get start() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get end() {
|
||||||
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
get zone() {
|
get zone() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { IntervalType } from "./parser/tokenizer";
|
import { IntervalType, SourceLocation } from "./parser/tokenizer";
|
||||||
import { Duration } from "./Duration";
|
import { Duration } from "./Duration";
|
||||||
import { Intensity } from "./Intensity";
|
import { Intensity } from "./Intensity";
|
||||||
|
|
||||||
|
|
@ -21,4 +21,5 @@ export type Interval = {
|
||||||
export type Comment = {
|
export type Comment = {
|
||||||
offset: Duration;
|
offset: Duration;
|
||||||
text: string;
|
text: string;
|
||||||
|
loc: SourceLocation;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -176,9 +176,9 @@ describe("detectRepeats()", () => {
|
||||||
duration: new Duration(100),
|
duration: new Duration(100),
|
||||||
intensity: new ConstantIntensity(1),
|
intensity: new ConstantIntensity(1),
|
||||||
comments: [
|
comments: [
|
||||||
{ offset: new Duration(0), text: "Let's start" },
|
{ offset: new Duration(0), text: "Let's start", loc: { row: 1, col: 1 } },
|
||||||
{ offset: new Duration(20), text: "Stay strong!" },
|
{ offset: new Duration(20), text: "Stay strong!", loc: { row: 2, col: 1 } },
|
||||||
{ offset: new Duration(90), text: "Finish it!" },
|
{ offset: new Duration(90), text: "Finish it!", loc: { row: 3, col: 1 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -186,8 +186,8 @@ describe("detectRepeats()", () => {
|
||||||
duration: new Duration(100),
|
duration: new Duration(100),
|
||||||
intensity: new ConstantIntensity(0.5),
|
intensity: new ConstantIntensity(0.5),
|
||||||
comments: [
|
comments: [
|
||||||
{ offset: new Duration(0), text: "Huh... have a rest" },
|
{ offset: new Duration(0), text: "Huh... have a rest", loc: { row: 4, col: 1 } },
|
||||||
{ offset: new Duration(80), text: "Ready for next?" },
|
{ offset: new Duration(80), text: "Ready for next?", loc: { row: 5, col: 1 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -195,9 +195,9 @@ describe("detectRepeats()", () => {
|
||||||
duration: new Duration(100),
|
duration: new Duration(100),
|
||||||
intensity: new ConstantIntensity(1),
|
intensity: new ConstantIntensity(1),
|
||||||
comments: [
|
comments: [
|
||||||
{ offset: new Duration(0), text: "Bring it on again!" },
|
{ offset: new Duration(0), text: "Bring it on again!", loc: { row: 6, col: 1 } },
|
||||||
{ offset: new Duration(50), text: "Half way" },
|
{ offset: new Duration(50), text: "Half way", loc: { row: 7, col: 1 } },
|
||||||
{ offset: new Duration(90), text: "Almost there!" },
|
{ offset: new Duration(90), text: "Almost there!", loc: { row: 8, col: 1 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -205,9 +205,9 @@ describe("detectRepeats()", () => {
|
||||||
duration: new Duration(100),
|
duration: new Duration(100),
|
||||||
intensity: new ConstantIntensity(0.5),
|
intensity: new ConstantIntensity(0.5),
|
||||||
comments: [
|
comments: [
|
||||||
{ offset: new Duration(30), text: "Wow... you did it!" },
|
{ offset: new Duration(30), text: "Wow... you did it!", loc: { row: 9, col: 1 } },
|
||||||
{ offset: new Duration(40), text: "Nice job." },
|
{ offset: new Duration(40), text: "Nice job.", loc: { row: 10, col: 1 } },
|
||||||
{ offset: new Duration(50), text: "Until next time..." },
|
{ offset: new Duration(50), text: "Until next time...", loc: { row: 11, col: 1 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -220,20 +220,20 @@ describe("detectRepeats()", () => {
|
||||||
{ type: "Rest", duration: new Duration(100), intensity: new ConstantIntensity(0.5), comments: [] },
|
{ type: "Rest", duration: new Duration(100), intensity: new ConstantIntensity(0.5), comments: [] },
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{ offset: new Duration(0), text: "Let's start" },
|
{ offset: new Duration(0), text: "Let's start", loc: { row: 1, col: 1 } },
|
||||||
{ offset: new Duration(20), text: "Stay strong!" },
|
{ offset: new Duration(20), text: "Stay strong!", loc: { row: 2, col: 1 } },
|
||||||
{ offset: new Duration(90), text: "Finish it!" },
|
{ offset: new Duration(90), text: "Finish it!", loc: { row: 3, col: 1 } },
|
||||||
|
|
||||||
{ offset: new Duration(100), text: "Huh... have a rest" },
|
{ offset: new Duration(100), text: "Huh... have a rest", loc: { row: 4, col: 1 } },
|
||||||
{ offset: new Duration(180), text: "Ready for next?" },
|
{ offset: new Duration(180), text: "Ready for next?", loc: { row: 5, col: 1 } },
|
||||||
|
|
||||||
{ offset: new Duration(200), text: "Bring it on again!" },
|
{ offset: new Duration(200), text: "Bring it on again!", loc: { row: 6, col: 1 } },
|
||||||
{ offset: new Duration(250), text: "Half way" },
|
{ offset: new Duration(250), text: "Half way", loc: { row: 7, col: 1 } },
|
||||||
{ offset: new Duration(290), text: "Almost there!" },
|
{ offset: new Duration(290), text: "Almost there!", loc: { row: 8, col: 1 } },
|
||||||
|
|
||||||
{ offset: new Duration(330), text: "Wow... you did it!" },
|
{ offset: new Duration(330), text: "Wow... you did it!", loc: { row: 9, col: 1 } },
|
||||||
{ offset: new Duration(340), text: "Nice job." },
|
{ offset: new Duration(340), text: "Nice job.", loc: { row: 10, col: 1 } },
|
||||||
{ offset: new Duration(350), text: "Until next time..." },
|
{ offset: new Duration(350), text: "Until next time...", loc: { row: 11, col: 1 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const generateTextEvents = (comments: Comment[]): xml.XmlObject[] => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateRangeInterval = (
|
const generateRangeInterval = (
|
||||||
tagName: "Warmup" | "Cooldown",
|
tagName: "Warmup" | "Cooldown" | "Ramp",
|
||||||
{ duration, intensity, cadence, comments }: Interval,
|
{ duration, intensity, cadence, comments }: Interval,
|
||||||
): xml.XmlObject => {
|
): xml.XmlObject => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -79,16 +79,22 @@ const generateRepeatInterval = (repInterval: RepeatedInterval): xml.XmlObject =>
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateInterval = (interval: Interval | RepeatedInterval): xml.XmlObject => {
|
const generateInterval = (
|
||||||
|
interval: Interval | RepeatedInterval,
|
||||||
|
index: number,
|
||||||
|
allIntervals: (Interval | RepeatedInterval)[],
|
||||||
|
): xml.XmlObject => {
|
||||||
if (interval.type === "repeat") {
|
if (interval.type === "repeat") {
|
||||||
return generateRepeatInterval(interval);
|
return generateRepeatInterval(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { intensity } = interval;
|
const { intensity } = interval;
|
||||||
if (intensity.start < intensity.end) {
|
if (index === 0 && intensity.start < intensity.end) {
|
||||||
return generateRangeInterval("Warmup", interval);
|
return generateRangeInterval("Warmup", interval);
|
||||||
} else if (intensity.start > intensity.end) {
|
} else if (index === allIntervals.length - 1 && intensity.start > intensity.end) {
|
||||||
return generateRangeInterval("Cooldown", interval);
|
return generateRangeInterval("Cooldown", interval);
|
||||||
|
} else if (intensity.start !== intensity.end) {
|
||||||
|
return generateRangeInterval("Ramp", interval);
|
||||||
} else if (intensity.zone === "free") {
|
} else if (intensity.zone === "free") {
|
||||||
return generateFreeRideInterval(interval);
|
return generateFreeRideInterval(interval);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,13 @@ export { parseCliOptions } from "./parseCliOptions";
|
||||||
export { Workout, Interval, Comment } from "./ast";
|
export { Workout, Interval, Comment } from "./ast";
|
||||||
export { Duration } from "./Duration";
|
export { Duration } from "./Duration";
|
||||||
export { Intensity, ConstantIntensity, RangeIntensity, FreeIntensity } from "./Intensity";
|
export { Intensity, ConstantIntensity, RangeIntensity, FreeIntensity } from "./Intensity";
|
||||||
export { ZoneType } from "./ZoneType";
|
export { ZoneType, intensityValueToZoneType } from "./ZoneType";
|
||||||
|
export { SourceLocation } from "./parser/tokenizer";
|
||||||
|
import { ParseError } from "./parser/ParseError";
|
||||||
|
import { ValidationError } from "./parser/ValidationError";
|
||||||
|
export type ZwiftoutException = ParseError | ValidationError;
|
||||||
|
export { ParseError, ValidationError };
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
export { totalDuration } from "./stats/totalDuration";
|
export { totalDuration } from "./stats/totalDuration";
|
||||||
export { maximumIntensity } from "./stats/maximumIntensity";
|
export { maximumIntensity } from "./stats/maximumIntensity";
|
||||||
export { chunkRangeIntervals } from "./utils/chunkRangeIntervals";
|
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,10 @@ export const parseCliOptions = (): CliOptions => {
|
||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
argParser.add_argument("file", { nargs: 1 });
|
argParser.add_argument("file", {
|
||||||
|
nargs: "?",
|
||||||
|
default: 0, // Default to reading STDIN
|
||||||
|
});
|
||||||
|
|
||||||
// As we only allow one file as input,
|
return argParser.parse_args();
|
||||||
// convert filenames array to just a single string.
|
|
||||||
const { file, ...rest } = argParser.parse_args();
|
|
||||||
return {
|
|
||||||
file: file[0],
|
|
||||||
...rest,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { SourceLocation } from "./tokenizer";
|
import { SourceLocation } from "./tokenizer";
|
||||||
|
|
||||||
export class ParseError extends Error {
|
export class ParseError extends Error {
|
||||||
constructor(msg: string, { row, col }: SourceLocation) {
|
public loc: SourceLocation;
|
||||||
super(`${msg} at line ${row + 1} char ${col + 1}`);
|
constructor(msg: string, loc: SourceLocation) {
|
||||||
|
super(`${msg} at line ${loc.row + 1} char ${loc.col + 1}`);
|
||||||
|
this.loc = loc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { SourceLocation } from "./tokenizer";
|
||||||
|
|
||||||
|
export class ValidationError extends Error {
|
||||||
|
public loc: SourceLocation;
|
||||||
|
constructor(msg: string, loc: SourceLocation) {
|
||||||
|
super(`${msg} at line ${loc.row + 1} char ${loc.col + 1}`);
|
||||||
|
this.loc = loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Interval, Workout } from "../ast";
|
||||||
|
import { FreeIntensity, RangeIntensity, RangeIntensityEnd } from "../Intensity";
|
||||||
|
|
||||||
|
const fillIntensities = (prevInterval: Interval, interval: Interval): Interval => {
|
||||||
|
if (!(interval.intensity instanceof RangeIntensityEnd)) {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevInterval.intensity instanceof FreeIntensity) {
|
||||||
|
throw new Error("range-intensity-end interval can't be after free-intensity interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...interval,
|
||||||
|
intensity: new RangeIntensity(prevInterval.intensity.end, interval.intensity.end),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Given: [1, 2, 3, 4]
|
||||||
|
// Returns: [[1,2], [2,3], [3,4]]
|
||||||
|
const pairs = <T>(arr: T[]): T[][] => {
|
||||||
|
const result: T[][] = [];
|
||||||
|
for (let i = 1; i < arr.length; i++) {
|
||||||
|
result.push([arr[i - 1], arr[i]]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fillIntensitiesInIntervals = (intervals: Interval[]): Interval[] => {
|
||||||
|
if (intervals.length <= 1) {
|
||||||
|
if (intervals.length === 1 && intervals[0].intensity instanceof RangeIntensityEnd) {
|
||||||
|
throw new Error("range-intensity-end interval can't be the first interval");
|
||||||
|
}
|
||||||
|
return intervals;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [intervals[0], ...pairs(intervals).map(([prev, curr]) => fillIntensities(prev, curr))];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fillRangeIntensities = (workout: Workout): Workout => {
|
||||||
|
return {
|
||||||
|
...workout,
|
||||||
|
intervals: fillIntensitiesInIntervals(workout.intervals),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { Workout } from "../ast";
|
import { Workout } from "../ast";
|
||||||
|
import { fillRangeIntensities } from "./fillRangeIntensities";
|
||||||
import { parseTokens } from "./parser";
|
import { parseTokens } from "./parser";
|
||||||
import { tokenize } from "./tokenizer";
|
import { tokenize } from "./tokenizer";
|
||||||
|
import { validate } from "./validate";
|
||||||
|
|
||||||
export const parse = (source: string): Workout => parseTokens(tokenize(source));
|
export const parse = (source: string): Workout => validate(fillRangeIntensities(parseTokens(tokenize(source))));
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,7 @@ Name: My Workout
|
||||||
|
|
||||||
Warmup: 5:30 50%..80% 100rpm
|
Warmup: 5:30 50%..80% 100rpm
|
||||||
Cooldown: 5:30 70%..45%
|
Cooldown: 5:30 70%..45%
|
||||||
|
Ramp: 5:30 90%..100%
|
||||||
`).intervals,
|
`).intervals,
|
||||||
).toMatchInlineSnapshot(`
|
).toMatchInlineSnapshot(`
|
||||||
Array [
|
Array [
|
||||||
|
|
@ -258,10 +259,147 @@ Cooldown: 5:30 70%..45%
|
||||||
},
|
},
|
||||||
"type": "Cooldown",
|
"type": "Cooldown",
|
||||||
},
|
},
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 330,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 1,
|
||||||
|
"_start": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("parses end-of-range intervals after power-range interval", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
|
||||||
|
Ramp: 5:00 50%..75%
|
||||||
|
Ramp: 5:00 ..100%
|
||||||
|
Ramp: 5:00 ..50%
|
||||||
|
`).intervals,
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 0.75,
|
||||||
|
"_start": 0.5,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 1,
|
||||||
|
"_start": 0.75,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 0.5,
|
||||||
|
"_start": 1,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses end-of-range intervals after normal interval", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
|
||||||
|
Interval: 5:00 75%
|
||||||
|
Ramp: 5:00 ..100%
|
||||||
|
Ramp: 5:00 ..50%
|
||||||
|
`).intervals,
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.75,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 1,
|
||||||
|
"_start": 0.75,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"intensity": RangeIntensity {
|
||||||
|
"_end": 0.5,
|
||||||
|
"_start": 1,
|
||||||
|
},
|
||||||
|
"type": "Ramp",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when end-of-range intervals after free-ride interval", () => {
|
||||||
|
expect(
|
||||||
|
() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
|
||||||
|
FreeRide: 5:00
|
||||||
|
Ramp: 5:00 ..100%
|
||||||
|
Ramp: 5:00 ..50%
|
||||||
|
`).intervals,
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"range-intensity-end interval can't be after free-intensity interval"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when end-of-range intervals is the first interval", () => {
|
||||||
|
expect(
|
||||||
|
() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
|
||||||
|
Ramp: 5:00 ..50%
|
||||||
|
`).intervals,
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"range-intensity-end interval can't be the first interval"`);
|
||||||
|
});
|
||||||
|
|
||||||
it("parses free-ride intervals", () => {
|
it("parses free-ride intervals", () => {
|
||||||
expect(
|
expect(
|
||||||
parse(`
|
parse(`
|
||||||
|
|
@ -458,30 +596,50 @@ Rest: 5:00 50%
|
||||||
"cadence": undefined,
|
"cadence": undefined,
|
||||||
"comments": Array [
|
"comments": Array [
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 0,
|
"seconds": 0,
|
||||||
},
|
},
|
||||||
"text": "Find your rythm.",
|
"text": "Find your rythm.",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 60,
|
"seconds": 60,
|
||||||
},
|
},
|
||||||
"text": "Try to settle in for the effort",
|
"text": "Try to settle in for the effort",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 6,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 300,
|
"seconds": 300,
|
||||||
},
|
},
|
||||||
"text": "Half way through",
|
"text": "Half way through",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 8,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 540,
|
"seconds": 540,
|
||||||
},
|
},
|
||||||
"text": "Almost there",
|
"text": "Almost there",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 9,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 570,
|
"seconds": 570,
|
||||||
},
|
},
|
||||||
|
|
@ -500,12 +658,20 @@ Rest: 5:00 50%
|
||||||
"cadence": undefined,
|
"cadence": undefined,
|
||||||
"comments": Array [
|
"comments": Array [
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 12,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 0,
|
"seconds": 0,
|
||||||
},
|
},
|
||||||
"text": "Great effort!",
|
"text": "Great effort!",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 13,
|
||||||
|
},
|
||||||
"offset": Duration {
|
"offset": Duration {
|
||||||
"seconds": 30,
|
"seconds": 30,
|
||||||
},
|
},
|
||||||
|
|
@ -526,4 +692,475 @@ Rest: 5:00 50%
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("parses last comment with negative offset", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 10:00 90%
|
||||||
|
@ 0:10 Find your rythm.
|
||||||
|
@ -0:10 Final push. YOU GOT IT!
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 10,
|
||||||
|
},
|
||||||
|
"text": "Find your rythm.",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 590,
|
||||||
|
},
|
||||||
|
"text": "Final push. YOU GOT IT!",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 600,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses comment with negative offset before absolutely offset comment", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 1:00 90%
|
||||||
|
@ -0:10 Before last
|
||||||
|
@ 0:50 Last!
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 40,
|
||||||
|
},
|
||||||
|
"text": "Before last",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 50,
|
||||||
|
},
|
||||||
|
"text": "Last!",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 60,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses multiple comments with negative offsets in row", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 1:00 90%
|
||||||
|
@ -0:10 One more before last
|
||||||
|
@ -0:10 Before last
|
||||||
|
@ -0:10 Last!
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 30,
|
||||||
|
},
|
||||||
|
"text": "One more before last",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 40,
|
||||||
|
},
|
||||||
|
"text": "Before last",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 5,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 50,
|
||||||
|
},
|
||||||
|
"text": "Last!",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 60,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses intervals with positive comment offsets", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 10:00 90%
|
||||||
|
@ 0:50 First comment
|
||||||
|
@ +0:10 Comment #2 10 seconds later
|
||||||
|
@ +0:10 Comment #3 another 10 seconds later
|
||||||
|
@ 5:00 Half way!
|
||||||
|
@ +0:10 Comment #5 10 seconds later
|
||||||
|
@ +0:10 Comment #6 another 10 seconds later
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 50,
|
||||||
|
},
|
||||||
|
"text": "First comment",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 60,
|
||||||
|
},
|
||||||
|
"text": "Comment #2 10 seconds later",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 5,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 70,
|
||||||
|
},
|
||||||
|
"text": "Comment #3 another 10 seconds later",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 6,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 300,
|
||||||
|
},
|
||||||
|
"text": "Half way!",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 7,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 310,
|
||||||
|
},
|
||||||
|
"text": "Comment #5 10 seconds later",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 8,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 320,
|
||||||
|
},
|
||||||
|
"text": "Comment #6 another 10 seconds later",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 600,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats positive comment offset as relative to interval start when there's no previous comment", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 10:00 90%
|
||||||
|
@ +1:00 First comment
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 60,
|
||||||
|
},
|
||||||
|
"text": "First comment",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 600,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when negative offset is followed by positive offset", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ -0:10 Comment 1
|
||||||
|
@ +0:30 Comment 2
|
||||||
|
@ 1:30 Comment 3
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Negative offset followed by positive offset at line 5 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("works fine when positive offset is followed by negative offset", () => {
|
||||||
|
expect(
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 1:00 90%
|
||||||
|
@ +0:10 Comment 1
|
||||||
|
@ -0:10 Comment 2
|
||||||
|
`),
|
||||||
|
).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"author": "",
|
||||||
|
"description": "",
|
||||||
|
"intervals": Array [
|
||||||
|
Object {
|
||||||
|
"cadence": undefined,
|
||||||
|
"comments": Array [
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 3,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 10,
|
||||||
|
},
|
||||||
|
"text": "Comment 1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"loc": Object {
|
||||||
|
"col": 4,
|
||||||
|
"row": 4,
|
||||||
|
},
|
||||||
|
"offset": Duration {
|
||||||
|
"seconds": 50,
|
||||||
|
},
|
||||||
|
"text": "Comment 2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"duration": Duration {
|
||||||
|
"seconds": 60,
|
||||||
|
},
|
||||||
|
"intensity": ConstantIntensity {
|
||||||
|
"_value": 0.9,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "My Workout",
|
||||||
|
"tags": Array [],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when comment offset is outside of interval length", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 Find your rythm.
|
||||||
|
@ 3:10 Try to settle in for the effort
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Comment offset is larger than interval length at line 5 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when negative comment offset is outside of interval", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 Find your rythm.
|
||||||
|
@ -3:10 Try to settle in for the effort
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Negative comment offset is larger than interval length at line 5 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when comment offset is the same as another comment offset", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 First comment
|
||||||
|
@ 1:00 Comment
|
||||||
|
@ 1:00 Overlapping comment
|
||||||
|
@ 1:50 Last comment
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Comment overlaps previous comment at line 6 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when comment offset is greater than next comment offset", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 First comment
|
||||||
|
@ 1:20 Comment
|
||||||
|
@ 1:00 Misplaced comment
|
||||||
|
@ 1:50 Last comment
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Comment overlaps previous comment at line 6 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when comments too close together", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 First comment
|
||||||
|
@ 0:01 Second Comment
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Less than 10 seconds between comments at line 5 char 5"`);
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 First comment
|
||||||
|
@ 0:09 Second Comment
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(`"Less than 10 seconds between comments at line 5 char 5"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("triggers no error when comments at least 10 seconds apart", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 2:00 90%
|
||||||
|
@ 0:00 First comment
|
||||||
|
@ 0:10 Second Comment
|
||||||
|
`),
|
||||||
|
).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws error when comment does not finish before end of interval", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 1:00 80%
|
||||||
|
@ 0:51 First comment
|
||||||
|
Interval: 1:00 90%
|
||||||
|
`),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(
|
||||||
|
`"Less than 10 seconds between comment start and interval end at line 4 char 5"`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("triggers no error when comment finishes right at interval end", () => {
|
||||||
|
expect(() =>
|
||||||
|
parse(`
|
||||||
|
Name: My Workout
|
||||||
|
Interval: 1:00 80%
|
||||||
|
@ 0:50 First comment
|
||||||
|
Interval: 1:00 90%
|
||||||
|
`),
|
||||||
|
).not.toThrowError();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { last } from "ramda";
|
||||||
import { Interval, Workout, Comment } from "../ast";
|
import { Interval, Workout, Comment } from "../ast";
|
||||||
import { Duration } from "../Duration";
|
import { Duration } from "../Duration";
|
||||||
import { ConstantIntensity, FreeIntensity, RangeIntensity } from "../Intensity";
|
import { ConstantIntensity, FreeIntensity, RangeIntensity, RangeIntensityEnd } from "../Intensity";
|
||||||
import { ParseError } from "./ParseError";
|
import { ParseError } from "./ParseError";
|
||||||
import { IntervalType, SourceLocation, Token } from "./tokenizer";
|
import { IntervalType, OffsetToken, SourceLocation, Token } from "./tokenizer";
|
||||||
|
|
||||||
type Header = Partial<Omit<Workout, "intervals">>;
|
type Header = Partial<Omit<Workout, "intervals">>;
|
||||||
|
|
||||||
|
|
@ -57,12 +58,18 @@ const parseHeader = (tokens: Token[]): [Header, Token[]] => {
|
||||||
return [header, tokens];
|
return [header, tokens];
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseIntervalComments = (tokens: Token[]): [Comment[], Token[]] => {
|
type PartialComment = {
|
||||||
const comments: Comment[] = [];
|
offsetToken: OffsetToken;
|
||||||
|
text: string;
|
||||||
|
loc: SourceLocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseIntervalComments = (tokens: Token[], intervalDuration: Duration): [Comment[], Token[]] => {
|
||||||
|
const comments: PartialComment[] = [];
|
||||||
while (tokens[0]) {
|
while (tokens[0]) {
|
||||||
const [start, offset, text, ...rest] = tokens;
|
const [start, offset, text, ...rest] = tokens;
|
||||||
if (start.type === "comment-start") {
|
if (start.type === "comment-start") {
|
||||||
if (!offset || offset.type !== "duration") {
|
if (!offset || offset.type !== "offset") {
|
||||||
throw new ParseError(
|
throw new ParseError(
|
||||||
`Expected [comment offset] instead got ${tokenToString(offset)}`,
|
`Expected [comment offset] instead got ${tokenToString(offset)}`,
|
||||||
offset?.loc || start.loc,
|
offset?.loc || start.loc,
|
||||||
|
|
@ -72,15 +79,64 @@ const parseIntervalComments = (tokens: Token[]): [Comment[], Token[]] => {
|
||||||
throw new ParseError(`Expected [comment text] instead got ${tokenToString(text)}`, text?.loc || offset.loc);
|
throw new ParseError(`Expected [comment text] instead got ${tokenToString(text)}`, text?.loc || offset.loc);
|
||||||
}
|
}
|
||||||
comments.push({
|
comments.push({
|
||||||
offset: new Duration(offset.value),
|
offsetToken: offset,
|
||||||
text: text.value,
|
text: text.value,
|
||||||
|
loc: offset.loc,
|
||||||
});
|
});
|
||||||
tokens = rest;
|
tokens = rest;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [comments, tokens];
|
|
||||||
|
return [computeAbsoluteOffsets(comments, intervalDuration), tokens];
|
||||||
|
};
|
||||||
|
|
||||||
|
const computeAbsoluteOffsets = (partialComments: PartialComment[], intervalDuration: Duration): Comment[] => {
|
||||||
|
const comments: Comment[] = [];
|
||||||
|
for (let i = 0; i < partialComments.length; i++) {
|
||||||
|
const pComment = partialComments[i];
|
||||||
|
const offsetToken = pComment.offsetToken;
|
||||||
|
|
||||||
|
// Assume absolute offset by default
|
||||||
|
let offset: Duration = new Duration(offsetToken.value);
|
||||||
|
|
||||||
|
if (offsetToken.kind === "relative-plus") {
|
||||||
|
// Position relative to previous already-computed comment offset
|
||||||
|
const previousComment = last(comments);
|
||||||
|
if (previousComment) {
|
||||||
|
offset = new Duration(previousComment.offset.seconds + offset.seconds);
|
||||||
|
}
|
||||||
|
} else if (offsetToken.kind === "relative-minus") {
|
||||||
|
// Position relative to next comment or interval end
|
||||||
|
offset = new Duration(nextCommentOffset(partialComments, i, intervalDuration).seconds - offset.seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
comments.push({
|
||||||
|
offset,
|
||||||
|
loc: pComment.loc,
|
||||||
|
text: pComment.text,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return comments;
|
||||||
|
};
|
||||||
|
|
||||||
|
const nextCommentOffset = (partialComments: PartialComment[], i: number, intervalDuration: Duration): Duration => {
|
||||||
|
const nextComment = partialComments[i + 1];
|
||||||
|
if (!nextComment) {
|
||||||
|
return intervalDuration;
|
||||||
|
}
|
||||||
|
switch (nextComment.offsetToken.kind) {
|
||||||
|
case "relative-minus":
|
||||||
|
return new Duration(
|
||||||
|
nextCommentOffset(partialComments, i + 1, intervalDuration).seconds - nextComment.offsetToken.value,
|
||||||
|
);
|
||||||
|
case "relative-plus":
|
||||||
|
throw new ParseError("Negative offset followed by positive offset", nextComment.offsetToken.loc);
|
||||||
|
case "absolute":
|
||||||
|
default:
|
||||||
|
return new Duration(nextComment.offsetToken.value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseIntervalParams = (type: IntervalType, tokens: Token[], loc: SourceLocation): [Interval, Token[]] => {
|
const parseIntervalParams = (type: IntervalType, tokens: Token[], loc: SourceLocation): [Interval, Token[]] => {
|
||||||
|
|
@ -102,6 +158,9 @@ const parseIntervalParams = (type: IntervalType, tokens: Token[], loc: SourceLoc
|
||||||
} else if (token.type === "intensity-range") {
|
} else if (token.type === "intensity-range") {
|
||||||
intensity = new RangeIntensity(token.value[0], token.value[1]);
|
intensity = new RangeIntensity(token.value[0], token.value[1]);
|
||||||
tokens.shift();
|
tokens.shift();
|
||||||
|
} else if (token.type === "intensity-range-end") {
|
||||||
|
intensity = new RangeIntensityEnd(token.value);
|
||||||
|
tokens.shift();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +173,7 @@ const parseIntervalParams = (type: IntervalType, tokens: Token[], loc: SourceLoc
|
||||||
intensity = new FreeIntensity();
|
intensity = new FreeIntensity();
|
||||||
}
|
}
|
||||||
|
|
||||||
const [comments, rest] = parseIntervalComments(tokens);
|
const [comments, rest] = parseIntervalComments(tokens, duration);
|
||||||
|
|
||||||
return [{ type, duration, intensity, cadence, comments }, rest];
|
return [{ type, duration, intensity, cadence, comments }, rest];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { ParseError } from "./ParseError";
|
import { ParseError } from "./ParseError";
|
||||||
|
|
||||||
export type HeaderType = "Name" | "Author" | "Description" | "Tags";
|
export type HeaderType = "Name" | "Author" | "Description" | "Tags";
|
||||||
export type IntervalType = "Warmup" | "Rest" | "Interval" | "Cooldown" | "FreeRide";
|
export type IntervalType = "Warmup" | "Rest" | "Interval" | "Cooldown" | "FreeRide" | "Ramp";
|
||||||
|
|
||||||
const isHeaderType = (value: string): value is HeaderType => {
|
const isHeaderType = (value: string): value is HeaderType => {
|
||||||
return ["Name", "Author", "Description", "Tags"].includes(value);
|
return ["Name", "Author", "Description", "Tags"].includes(value);
|
||||||
};
|
};
|
||||||
const isIntervalType = (value: string): value is IntervalType => {
|
const isIntervalType = (value: string): value is IntervalType => {
|
||||||
return ["Warmup", "Rest", "Interval", "Cooldown", "FreeRide"].includes(value);
|
return ["Warmup", "Rest", "Interval", "Cooldown", "FreeRide", "Ramp"].includes(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 0-based row and column indexes. First line is 0th.
|
// 0-based row and column indexes. First line is 0th.
|
||||||
|
|
@ -36,17 +36,36 @@ export type NumberToken = {
|
||||||
value: number;
|
value: number;
|
||||||
loc: SourceLocation;
|
loc: SourceLocation;
|
||||||
};
|
};
|
||||||
|
export type OffsetToken = {
|
||||||
|
type: "offset";
|
||||||
|
kind: "absolute" | "relative-plus" | "relative-minus";
|
||||||
|
value: number;
|
||||||
|
loc: SourceLocation;
|
||||||
|
};
|
||||||
export type RangeIntensityToken = {
|
export type RangeIntensityToken = {
|
||||||
type: "intensity-range";
|
type: "intensity-range";
|
||||||
value: [number, number];
|
value: [number, number];
|
||||||
loc: SourceLocation;
|
loc: SourceLocation;
|
||||||
};
|
};
|
||||||
|
export type RangeIntensityEndToken = {
|
||||||
|
type: "intensity-range-end";
|
||||||
|
value: number;
|
||||||
|
loc: SourceLocation;
|
||||||
|
};
|
||||||
export type CommentStartToken = {
|
export type CommentStartToken = {
|
||||||
type: "comment-start";
|
type: "comment-start";
|
||||||
value?: undefined;
|
value?: undefined;
|
||||||
loc: SourceLocation;
|
loc: SourceLocation;
|
||||||
};
|
};
|
||||||
export type Token = HeaderToken | IntervalToken | TextToken | NumberToken | RangeIntensityToken | CommentStartToken;
|
export type Token =
|
||||||
|
| HeaderToken
|
||||||
|
| IntervalToken
|
||||||
|
| TextToken
|
||||||
|
| NumberToken
|
||||||
|
| OffsetToken
|
||||||
|
| RangeIntensityToken
|
||||||
|
| RangeIntensityEndToken
|
||||||
|
| CommentStartToken;
|
||||||
|
|
||||||
const toInteger = (str: string): number => {
|
const toInteger = (str: string): number => {
|
||||||
return parseInt(str.replace(/[^0-9]/, ""), 10);
|
return parseInt(str.replace(/[^0-9]/, ""), 10);
|
||||||
|
|
@ -68,10 +87,14 @@ const tokenizeValueParam = (text: string, loc: SourceLocation): Token => {
|
||||||
if (/^[0-9]+rpm$/.test(text)) {
|
if (/^[0-9]+rpm$/.test(text)) {
|
||||||
return { type: "cadence", value: toInteger(text), loc };
|
return { type: "cadence", value: toInteger(text), loc };
|
||||||
}
|
}
|
||||||
if (/^[0-9]+%..[0-9]+%$/.test(text)) {
|
if (/^[0-9]+%\.\.[0-9]+%$/.test(text)) {
|
||||||
const [from, to] = text.split("..").map(toInteger).map(toFraction);
|
const [from, to] = text.split("..").map(toInteger).map(toFraction);
|
||||||
return { type: "intensity-range", value: [from, to], loc };
|
return { type: "intensity-range", value: [from, to], loc };
|
||||||
}
|
}
|
||||||
|
if (/^\.\.[0-9]+%$/.test(text)) {
|
||||||
|
const [, /* _ */ to] = text.split("..").map(toInteger).map(toFraction);
|
||||||
|
return { type: "intensity-range-end", value: to, loc };
|
||||||
|
}
|
||||||
if (/^[0-9]+%$/.test(text)) {
|
if (/^[0-9]+%$/.test(text)) {
|
||||||
return { type: "intensity", value: toFraction(toInteger(text)), loc };
|
return { type: "intensity", value: toFraction(toInteger(text)), loc };
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +112,7 @@ const tokenizeParams = (text: string, loc: SourceLocation): Token[] => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const tokenizeComment = (line: string, row: number): Token[] | undefined => {
|
const tokenizeComment = (line: string, row: number): Token[] | undefined => {
|
||||||
const [, commentHead, offset, commentText] = line.match(/^(\s*@\s*)([0-9:]+)(.*?)$/) || [];
|
const [, commentHead, sign, offset, commentText] = line.match(/^(\s*@\s*)([-+]?)([0-9:]+)(.*?)$/) || [];
|
||||||
if (!commentHead) {
|
if (!commentHead) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
@ -98,11 +121,27 @@ const tokenizeComment = (line: string, row: number): Token[] | undefined => {
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
{ type: "comment-start", loc: { row, col: line.indexOf("@") } },
|
{ type: "comment-start", loc: { row, col: line.indexOf("@") } },
|
||||||
{ type: "duration", value: toSeconds(offset), loc: { row, col: commentHead.length } },
|
{
|
||||||
|
type: "offset",
|
||||||
|
kind: signToKind(sign),
|
||||||
|
value: toSeconds(offset),
|
||||||
|
loc: { row, col: commentHead.length },
|
||||||
|
},
|
||||||
{ type: "text", value: commentText.trim(), loc: { row, col: commentHead.length + offset.length } },
|
{ type: "text", value: commentText.trim(), loc: { row, col: commentHead.length + offset.length } },
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const signToKind = (sign: string) => {
|
||||||
|
switch (sign) {
|
||||||
|
case "-":
|
||||||
|
return "relative-minus";
|
||||||
|
case "+":
|
||||||
|
return "relative-plus";
|
||||||
|
default:
|
||||||
|
return "absolute";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const tokenizeHeader = (label: HeaderType, separator: string, paramString: string, row: number): Token[] => {
|
const tokenizeHeader = (label: HeaderType, separator: string, paramString: string, row: number): Token[] => {
|
||||||
const token: HeaderToken = {
|
const token: HeaderToken = {
|
||||||
type: "header",
|
type: "header",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { Workout, Interval } from "../ast";
|
||||||
|
import { ValidationError } from "./ValidationError";
|
||||||
|
|
||||||
|
const validateCommentOffsets = ({ comments, duration }: Interval) => {
|
||||||
|
for (let i = 0; i < comments.length; i++) {
|
||||||
|
const comment = comments[i];
|
||||||
|
if (comment.offset.seconds >= duration.seconds) {
|
||||||
|
throw new ValidationError(`Comment offset is larger than interval length`, comment.loc);
|
||||||
|
}
|
||||||
|
if (comment.offset.seconds < 0) {
|
||||||
|
throw new ValidationError(`Negative comment offset is larger than interval length`, comment.loc);
|
||||||
|
}
|
||||||
|
if (i > 0 && comment.offset.seconds <= comments[i - 1].offset.seconds) {
|
||||||
|
throw new ValidationError(`Comment overlaps previous comment`, comment.loc);
|
||||||
|
}
|
||||||
|
if (i > 0 && comment.offset.seconds < comments[i - 1].offset.seconds + 10) {
|
||||||
|
throw new ValidationError(`Less than 10 seconds between comments`, comment.loc);
|
||||||
|
}
|
||||||
|
if (comment.offset.seconds + 10 > duration.seconds) {
|
||||||
|
throw new ValidationError(`Less than 10 seconds between comment start and interval end`, comment.loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validate = (workout: Workout): Workout => {
|
||||||
|
workout.intervals.forEach(validateCommentOffsets);
|
||||||
|
return workout;
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { pipe, sum } from "ramda";
|
import { map, pipe, sum } from "ramda";
|
||||||
import { Interval } from "../ast";
|
import { Interval } from "../ast";
|
||||||
import { ConstantIntensity } from "../Intensity";
|
import { ConstantIntensity } from "../Intensity";
|
||||||
import { average } from "./average";
|
import { average } from "./average";
|
||||||
|
|
@ -32,12 +32,6 @@ const fourthRoot = (x: number) => Math.pow(x, 1 / 4);
|
||||||
|
|
||||||
export const normalizedIntensity = (intervals: Interval[]): ConstantIntensity => {
|
export const normalizedIntensity = (intervals: Interval[]): ConstantIntensity => {
|
||||||
return new ConstantIntensity(
|
return new ConstantIntensity(
|
||||||
pipe(
|
pipe(intervalsToIntensityNumbers, rollingAverages, map(fourthPower), average, fourthRoot)(intervals),
|
||||||
intervalsToIntensityNumbers,
|
|
||||||
rollingAverages,
|
|
||||||
(averages) => averages.map(fourthPower),
|
|
||||||
average,
|
|
||||||
fourthRoot,
|
|
||||||
)(intervals),
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,11 @@ describe("xp()", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
|
// [50, 4], // Doesn't work :(
|
||||||
|
[51, 5],
|
||||||
|
[52, 5],
|
||||||
|
[53, 5],
|
||||||
|
[54, 5],
|
||||||
[55, 5],
|
[55, 5],
|
||||||
[56, 5],
|
[56, 5],
|
||||||
[57, 5],
|
[57, 5],
|
||||||
|
|
@ -60,6 +65,10 @@ describe("xp()", () => {
|
||||||
[59, 5],
|
[59, 5],
|
||||||
[60, 6],
|
[60, 6],
|
||||||
[61, 6],
|
[61, 6],
|
||||||
|
[65, 6],
|
||||||
|
[66, 6],
|
||||||
|
[67, 6],
|
||||||
|
[68, 6],
|
||||||
[5 * 60, 30],
|
[5 * 60, 30],
|
||||||
].forEach(([seconds, expectedXp]) => {
|
].forEach(([seconds, expectedXp]) => {
|
||||||
it(`${seconds}s produces ${expectedXp} XP`, () => {
|
it(`${seconds}s produces ${expectedXp} XP`, () => {
|
||||||
|
|
@ -77,16 +86,26 @@ describe("xp()", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
|
[51, 5],
|
||||||
|
[52, 5],
|
||||||
|
[53, 5],
|
||||||
[54, 5],
|
[54, 5],
|
||||||
[55, 5],
|
[55, 5],
|
||||||
[56, 5],
|
[56, 5],
|
||||||
[57, 5],
|
[57, 5],
|
||||||
[58, 5],
|
[58, 5],
|
||||||
[59, 5],
|
[59, 5],
|
||||||
|
// [60, 6], // Doesn't work :(
|
||||||
[61, 6],
|
[61, 6],
|
||||||
[62, 6],
|
[62, 6],
|
||||||
[63, 6],
|
[63, 6],
|
||||||
[64, 6],
|
[64, 6],
|
||||||
|
[65, 6],
|
||||||
|
[66, 6],
|
||||||
|
[67, 6],
|
||||||
|
[68, 6],
|
||||||
|
[69, 6],
|
||||||
|
[2 * 60, 11],
|
||||||
[3 * 60, 17],
|
[3 * 60, 17],
|
||||||
].forEach(([seconds, expectedXp]) => {
|
].forEach(([seconds, expectedXp]) => {
|
||||||
it(`${seconds}s produces ${expectedXp} XP`, () => {
|
it(`${seconds}s produces ${expectedXp} XP`, () => {
|
||||||
|
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
import { Interval } from "../ast";
|
|
||||||
import { Duration } from "../Duration";
|
|
||||||
import { ConstantIntensity, RangeIntensity } from "../Intensity";
|
|
||||||
import { chunkRangeIntervals } from "./chunkRangeIntervals";
|
|
||||||
|
|
||||||
describe("chunkRangeIntervals()", () => {
|
|
||||||
const minute = new Duration(60);
|
|
||||||
|
|
||||||
it("does nothing with empty array", () => {
|
|
||||||
expect(chunkRangeIntervals([], minute)).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing with constant-intensity intervals", () => {
|
|
||||||
const intervals: Interval[] = [
|
|
||||||
{
|
|
||||||
type: "Interval",
|
|
||||||
duration: new Duration(2 * 60),
|
|
||||||
intensity: new ConstantIntensity(0.7),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "Interval",
|
|
||||||
duration: new Duration(10 * 60),
|
|
||||||
intensity: new ConstantIntensity(1),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "Rest",
|
|
||||||
duration: new Duration(30),
|
|
||||||
intensity: new ConstantIntensity(0.5),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(chunkRangeIntervals(intervals, minute)).toEqual(intervals);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("converts 1-minute range-interval to 1-minute constant-interval", () => {
|
|
||||||
expect(
|
|
||||||
chunkRangeIntervals(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
type: "Warmup",
|
|
||||||
duration: minute,
|
|
||||||
intensity: new RangeIntensity(0.5, 1),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
minute,
|
|
||||||
),
|
|
||||||
).toMatchInlineSnapshot(`
|
|
||||||
Array [
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 60,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.75,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("splits 3-minute range-interval to three 1-minute constant-intervals", () => {
|
|
||||||
expect(
|
|
||||||
chunkRangeIntervals(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
type: "Warmup",
|
|
||||||
duration: new Duration(3 * 60),
|
|
||||||
intensity: new RangeIntensity(0.5, 1),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
minute,
|
|
||||||
),
|
|
||||||
).toMatchInlineSnapshot(`
|
|
||||||
Array [
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 60,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.5833333333333334,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 60,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.75,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 60,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.9166666666666667,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("splits 1:30 range-interval to 1min & 30sec constant-intervals", () => {
|
|
||||||
expect(
|
|
||||||
chunkRangeIntervals(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
type: "Warmup",
|
|
||||||
duration: new Duration(60 + 30),
|
|
||||||
intensity: new RangeIntensity(0.5, 1),
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
minute,
|
|
||||||
),
|
|
||||||
).toMatchInlineSnapshot(`
|
|
||||||
Array [
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 60,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.6666666666666666,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"comments": Array [],
|
|
||||||
"duration": Duration {
|
|
||||||
"seconds": 30,
|
|
||||||
},
|
|
||||||
"intensity": ConstantIntensity {
|
|
||||||
"_value": 0.9166666666666667,
|
|
||||||
},
|
|
||||||
"type": "Warmup",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
import { chain, curry } from "ramda";
|
|
||||||
import { Interval } from "../ast";
|
|
||||||
import { Duration } from "../Duration";
|
|
||||||
import { ConstantIntensity, Intensity } from "../Intensity";
|
|
||||||
|
|
||||||
const chunkDuration = (seconds: number, chunkSize: Duration, intervalDuration: Duration): Duration => {
|
|
||||||
return seconds + chunkSize.seconds > intervalDuration.seconds
|
|
||||||
? new Duration(intervalDuration.seconds % chunkSize.seconds)
|
|
||||||
: chunkSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
const chunkIntensity = (
|
|
||||||
startSeconds: number,
|
|
||||||
chunkSize: Duration,
|
|
||||||
{ start, end }: Intensity,
|
|
||||||
intervalDuration: Duration,
|
|
||||||
): ConstantIntensity => {
|
|
||||||
const endSeconds =
|
|
||||||
startSeconds + chunkSize.seconds > intervalDuration.seconds
|
|
||||||
? intervalDuration.seconds
|
|
||||||
: startSeconds + chunkSize.seconds;
|
|
||||||
|
|
||||||
const middleSeconds = (startSeconds + endSeconds) / 2;
|
|
||||||
|
|
||||||
return new ConstantIntensity(start + (end - start) * (middleSeconds / intervalDuration.seconds));
|
|
||||||
};
|
|
||||||
|
|
||||||
const chunkInterval = curry((chunkSize: Duration, interval: Interval): Interval[] => {
|
|
||||||
if (interval.intensity.start === interval.intensity.end) {
|
|
||||||
return [interval];
|
|
||||||
}
|
|
||||||
|
|
||||||
const intervals: Interval[] = [];
|
|
||||||
for (let seconds = 0; seconds < interval.duration.seconds; seconds += chunkSize.seconds) {
|
|
||||||
intervals.push({
|
|
||||||
...interval,
|
|
||||||
duration: chunkDuration(seconds, chunkSize, interval.duration),
|
|
||||||
intensity: chunkIntensity(seconds, chunkSize, interval.intensity, interval.duration),
|
|
||||||
comments: [], // TODO: for now, ignoring comments
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return intervals;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Breaks intervals that use RangeIntensity into multiple intervals with ConstantIntensity
|
|
||||||
*/
|
|
||||||
export const chunkRangeIntervals = (intervals: Interval[], chunkSize: Duration): Interval[] =>
|
|
||||||
chain(chunkInterval(chunkSize), intervals);
|
|
||||||
|
|
@ -226,6 +226,31 @@ The workouts are alphabetically ordered from easiest to hardest, so enjoy the mi
|
||||||
</workout_file>"
|
</workout_file>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Generate ZWO examples/ramps.txt 1`] = `
|
||||||
|
"<workout_file>
|
||||||
|
<name>Ramps</name>
|
||||||
|
<author>R.Saarsoo</author>
|
||||||
|
<description>Various kinds of ramp intervals.</description>
|
||||||
|
<tags>
|
||||||
|
</tags>
|
||||||
|
<sportType>bike</sportType>
|
||||||
|
<workout>
|
||||||
|
<Warmup Duration=\\"300\\" PowerLow=\\"0.4\\" PowerHigh=\\"0.75\\">
|
||||||
|
</Warmup>
|
||||||
|
<Ramp Duration=\\"600\\" PowerLow=\\"0.8\\" PowerHigh=\\"0.9\\">
|
||||||
|
</Ramp>
|
||||||
|
<Ramp Duration=\\"600\\" PowerLow=\\"0.9\\" PowerHigh=\\"0.8\\">
|
||||||
|
</Ramp>
|
||||||
|
<Ramp Duration=\\"600\\" PowerLow=\\"0.8\\" PowerHigh=\\"0.9\\">
|
||||||
|
</Ramp>
|
||||||
|
<Ramp Duration=\\"600\\" PowerLow=\\"0.9\\" PowerHigh=\\"0.8\\">
|
||||||
|
</Ramp>
|
||||||
|
<Cooldown Duration=\\"300\\" PowerLow=\\"0.75\\" PowerHigh=\\"0.4\\">
|
||||||
|
</Cooldown>
|
||||||
|
</workout>
|
||||||
|
</workout_file>"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Generate ZWO examples/threshold-pushing.txt 1`] = `
|
exports[`Generate ZWO examples/threshold-pushing.txt 1`] = `
|
||||||
"<workout_file>
|
"<workout_file>
|
||||||
<name>Threshold pushing</name>
|
<name>Threshold pushing</name>
|
||||||
|
|
@ -300,10 +325,10 @@ exports[`Generate stats examples/ftp-test.txt 1`] = `
|
||||||
"
|
"
|
||||||
Total duration: 45 minutes
|
Total duration: 45 minutes
|
||||||
|
|
||||||
Average intensity: 36%
|
Average intensity: 72%
|
||||||
Normalized intensity: 71%
|
Normalized intensity: 81%
|
||||||
|
|
||||||
TSS: 37
|
TSS: 49
|
||||||
XP: 336
|
XP: 336
|
||||||
|
|
||||||
Zone Distribution:
|
Zone Distribution:
|
||||||
|
|
@ -338,6 +363,27 @@ Zone Distribution:
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Generate stats examples/ramps.txt 1`] = `
|
||||||
|
"
|
||||||
|
Total duration: 50 minutes
|
||||||
|
|
||||||
|
Average intensity: 80%
|
||||||
|
Normalized intensity: 82%
|
||||||
|
|
||||||
|
TSS: 56
|
||||||
|
XP: 300
|
||||||
|
|
||||||
|
Zone Distribution:
|
||||||
|
6 min - Z1: Recovery
|
||||||
|
4 min - Z2: Endurance
|
||||||
|
40 min - Z3: Tempo
|
||||||
|
0 min - Z4: Threshold
|
||||||
|
0 min - Z5: VO2 Max
|
||||||
|
0 min - Z6: Anaerobic
|
||||||
|
0 min - Freeride
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Generate stats examples/threshold-pushing.txt 1`] = `
|
exports[`Generate stats examples/threshold-pushing.txt 1`] = `
|
||||||
"
|
"
|
||||||
Total duration: 79 minutes
|
Total duration: 79 minutes
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ const filenames = [
|
||||||
"examples/ftp-test.txt",
|
"examples/ftp-test.txt",
|
||||||
"examples/halvfems.txt",
|
"examples/halvfems.txt",
|
||||||
"examples/threshold-pushing.txt",
|
"examples/threshold-pushing.txt",
|
||||||
|
"examples/ramps.txt",
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("Generate ZWO", () => {
|
describe("Generate ZWO", () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue