Rename Seconds to Duration

This commit is contained in:
Rene Saarsoo 2020-09-25 13:48:16 +03:00
parent 564faf95e7
commit 61ea726187
10 changed files with 138 additions and 138 deletions

7
src/Duration.ts Normal file
View File

@ -0,0 +1,7 @@
export class Duration {
constructor(readonly value: number) {}
add(other: Duration): Duration {
return new Duration(this.value + other.value);
}
}

View File

@ -1,7 +0,0 @@
export class Seconds {
constructor(readonly value: number) {}
add(other: Seconds): Seconds {
return new Seconds(this.value + other.value);
}
}

View File

@ -1,5 +1,5 @@
import { IntervalType } from "./parser/tokenizer"; import { IntervalType } from "./parser/tokenizer";
import { Seconds } from "./Seconds"; import { Duration } from "./Duration";
export type Workout = { export type Workout = {
name: string; name: string;
@ -10,13 +10,13 @@ export type Workout = {
export type Interval = { export type Interval = {
type: IntervalType; type: IntervalType;
duration: Seconds; duration: Duration;
intensity: { from: number; to: number }; intensity: { from: number; to: number };
cadence?: number; cadence?: number;
comments: Comment[]; comments: Comment[];
}; };
export type Comment = { export type Comment = {
offset: Seconds; offset: Duration;
text: string; text: string;
}; };

View File

@ -1,6 +1,6 @@
import { Interval } from "./ast"; import { Interval } from "./ast";
import { detectRepeats } from "./detectRepeats"; import { detectRepeats } from "./detectRepeats";
import { Seconds } from "./Seconds"; import { Duration } from "./Duration";
describe("detectRepeats()", () => { describe("detectRepeats()", () => {
it("does nothing with empty array", () => { it("does nothing with empty array", () => {
@ -9,32 +9,32 @@ describe("detectRepeats()", () => {
it("does nothing when no interval repeats", () => { it("does nothing when no interval repeats", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Interval", duration: new Seconds(30), intensity: { from: 1.2, to: 1.2 }, comments: [] }, { type: "Interval", duration: new Duration(30), intensity: { from: 1.2, to: 1.2 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(60), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(60), intensity: { from: 1, to: 0.5 }, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual(intervals); expect(detectRepeats(intervals)).toEqual(intervals);
}); });
it("detects whole workout consisting of repetitions", () => { it("detects whole workout consisting of repetitions", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual([ expect(detectRepeats(intervals)).toEqual([
{ {
type: "repeat", type: "repeat",
times: 4, times: 4,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
], ],
comments: [], comments: [],
}, },
@ -43,54 +43,54 @@ describe("detectRepeats()", () => {
it("detects repetitions in the middle of workout", () => { it("detects repetitions in the middle of workout", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.5, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.5, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(120), intensity: { from: 0.2, to: 0.2 }, comments: [] }, { type: "Rest", duration: new Duration(120), intensity: { from: 0.2, to: 0.2 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Rest", duration: new Seconds(120), intensity: { from: 0.2, to: 0.2 }, comments: [] }, { type: "Rest", duration: new Duration(120), intensity: { from: 0.2, to: 0.2 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(60), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(60), intensity: { from: 1, to: 0.5 }, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual([ expect(detectRepeats(intervals)).toEqual([
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.5, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.5, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(120), intensity: { from: 0.2, to: 0.2 }, comments: [] }, { type: "Rest", duration: new Duration(120), intensity: { from: 0.2, to: 0.2 }, comments: [] },
{ {
type: "repeat", type: "repeat",
times: 4, times: 4,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
], ],
comments: [], comments: [],
}, },
{ type: "Rest", duration: new Seconds(120), intensity: { from: 0.2, to: 0.2 }, comments: [] }, { type: "Rest", duration: new Duration(120), intensity: { from: 0.2, to: 0.2 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(60), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(60), intensity: { from: 1, to: 0.5 }, comments: [] },
]); ]);
}); });
it("detects multiple repetitions", () => { it("detects multiple repetitions", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(100), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(100), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(100), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(100), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(100), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(100), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(100), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(100), intensity: { from: 0.5, to: 0.5 }, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual([ expect(detectRepeats(intervals)).toEqual([
{ {
type: "repeat", type: "repeat",
times: 2, times: 2,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(60), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(60), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
], ],
comments: [], comments: [],
}, },
@ -98,8 +98,8 @@ describe("detectRepeats()", () => {
type: "repeat", type: "repeat",
times: 2, times: 2,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(100), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(100), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(100), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(100), intensity: { from: 0.5, to: 0.5 }, comments: [] },
], ],
comments: [], comments: [],
}, },
@ -108,22 +108,22 @@ describe("detectRepeats()", () => {
it("takes cadence differences into account", () => { it("takes cadence differences into account", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] },
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual([ expect(detectRepeats(intervals)).toEqual([
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, comments: [] },
{ {
type: "repeat", type: "repeat",
times: 2, times: 2,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] }, { type: "Interval", duration: new Duration(120), intensity: { from: 1, to: 1 }, cadence: 100, comments: [] },
{ type: "Rest", duration: new Seconds(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] }, { type: "Rest", duration: new Duration(60), intensity: { from: 0.5, to: 0.5 }, cadence: 80, comments: [] },
], ],
comments: [], comments: [],
}, },
@ -132,14 +132,14 @@ describe("detectRepeats()", () => {
it("does not consider warmup/cooldown-range intervals to be repeatable", () => { it("does not consider warmup/cooldown-range intervals to be repeatable", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.1, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.1, to: 1 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(120), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(120), intensity: { from: 1, to: 0.5 }, comments: [] },
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.1, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.1, to: 1 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(120), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(120), intensity: { from: 1, to: 0.5 }, comments: [] },
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.1, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.1, to: 1 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(120), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(120), intensity: { from: 1, to: 0.5 }, comments: [] },
{ type: "Warmup", duration: new Seconds(60), intensity: { from: 0.1, to: 1 }, comments: [] }, { type: "Warmup", duration: new Duration(60), intensity: { from: 0.1, to: 1 }, comments: [] },
{ type: "Cooldown", duration: new Seconds(120), intensity: { from: 1, to: 0.5 }, comments: [] }, { type: "Cooldown", duration: new Duration(120), intensity: { from: 1, to: 0.5 }, comments: [] },
]; ];
expect(detectRepeats(intervals)).toEqual(intervals); expect(detectRepeats(intervals)).toEqual(intervals);
}); });
@ -148,41 +148,41 @@ describe("detectRepeats()", () => {
const intervals: Interval[] = [ const intervals: Interval[] = [
{ {
type: "Interval", type: "Interval",
duration: new Seconds(100), duration: new Duration(100),
intensity: { from: 1, to: 1 }, intensity: { from: 1, to: 1 },
comments: [ comments: [
{ offset: new Seconds(0), text: "Let's start" }, { offset: new Duration(0), text: "Let's start" },
{ offset: new Seconds(20), text: "Stay strong!" }, { offset: new Duration(20), text: "Stay strong!" },
{ offset: new Seconds(90), text: "Finish it!" }, { offset: new Duration(90), text: "Finish it!" },
], ],
}, },
{ {
type: "Rest", type: "Rest",
duration: new Seconds(100), duration: new Duration(100),
intensity: { from: 0.5, to: 0.5 }, intensity: { from: 0.5, to: 0.5 },
comments: [ comments: [
{ offset: new Seconds(0), text: "Huh... have a rest" }, { offset: new Duration(0), text: "Huh... have a rest" },
{ offset: new Seconds(80), text: "Ready for next?" }, { offset: new Duration(80), text: "Ready for next?" },
], ],
}, },
{ {
type: "Interval", type: "Interval",
duration: new Seconds(100), duration: new Duration(100),
intensity: { from: 1, to: 1 }, intensity: { from: 1, to: 1 },
comments: [ comments: [
{ offset: new Seconds(0), text: "Bring it on again!" }, { offset: new Duration(0), text: "Bring it on again!" },
{ offset: new Seconds(50), text: "Half way" }, { offset: new Duration(50), text: "Half way" },
{ offset: new Seconds(90), text: "Almost there!" }, { offset: new Duration(90), text: "Almost there!" },
], ],
}, },
{ {
type: "Rest", type: "Rest",
duration: new Seconds(100), duration: new Duration(100),
intensity: { from: 0.5, to: 0.5 }, intensity: { from: 0.5, to: 0.5 },
comments: [ comments: [
{ offset: new Seconds(30), text: "Wow... you did it!" }, { offset: new Duration(30), text: "Wow... you did it!" },
{ offset: new Seconds(40), text: "Nice job." }, { offset: new Duration(40), text: "Nice job." },
{ offset: new Seconds(50), text: "Until next time..." }, { offset: new Duration(50), text: "Until next time..." },
], ],
}, },
]; ];
@ -191,24 +191,24 @@ describe("detectRepeats()", () => {
type: "repeat", type: "repeat",
times: 2, times: 2,
intervals: [ intervals: [
{ type: "Interval", duration: new Seconds(100), intensity: { from: 1, to: 1 }, comments: [] }, { type: "Interval", duration: new Duration(100), intensity: { from: 1, to: 1 }, comments: [] },
{ type: "Rest", duration: new Seconds(100), intensity: { from: 0.5, to: 0.5 }, comments: [] }, { type: "Rest", duration: new Duration(100), intensity: { from: 0.5, to: 0.5 }, comments: [] },
], ],
comments: [ comments: [
{ offset: new Seconds(0), text: "Let's start" }, { offset: new Duration(0), text: "Let's start" },
{ offset: new Seconds(20), text: "Stay strong!" }, { offset: new Duration(20), text: "Stay strong!" },
{ offset: new Seconds(90), text: "Finish it!" }, { offset: new Duration(90), text: "Finish it!" },
{ offset: new Seconds(100), text: "Huh... have a rest" }, { offset: new Duration(100), text: "Huh... have a rest" },
{ offset: new Seconds(180), text: "Ready for next?" }, { offset: new Duration(180), text: "Ready for next?" },
{ offset: new Seconds(200), text: "Bring it on again!" }, { offset: new Duration(200), text: "Bring it on again!" },
{ offset: new Seconds(250), text: "Half way" }, { offset: new Duration(250), text: "Half way" },
{ offset: new Seconds(290), text: "Almost there!" }, { offset: new Duration(290), text: "Almost there!" },
{ offset: new Seconds(330), text: "Wow... you did it!" }, { offset: new Duration(330), text: "Wow... you did it!" },
{ offset: new Seconds(340), text: "Nice job." }, { offset: new Duration(340), text: "Nice job." },
{ offset: new Seconds(350), text: "Until next time..." }, { offset: new Duration(350), text: "Until next time..." },
], ],
}, },
]); ]);

View File

@ -1,6 +1,6 @@
import { eqProps, flatten, zip } from "ramda"; import { eqProps, flatten, zip } from "ramda";
import { Interval, Comment } from "./ast"; import { Interval, Comment } from "./ast";
import { Seconds } from "./Seconds"; import { Duration } from "./Duration";
export type RepeatedInterval = { export type RepeatedInterval = {
type: "repeat"; type: "repeat";
@ -32,7 +32,7 @@ const countRepetitions = (reference: Interval[], intervals: Interval[], startInd
return repeats; return repeats;
}; };
const offsetComments = (interval: Interval, baseOffset: Seconds): Comment[] => { const offsetComments = (interval: Interval, baseOffset: Duration): Comment[] => {
return interval.comments.map(({ offset, ...rest }) => ({ return interval.comments.map(({ offset, ...rest }) => ({
offset: baseOffset.add(offset), offset: baseOffset.add(offset),
...rest, ...rest,
@ -40,7 +40,7 @@ const offsetComments = (interval: Interval, baseOffset: Seconds): Comment[] => {
}; };
const collectComments = (intervals: Interval[]): Comment[] => { const collectComments = (intervals: Interval[]): Comment[] => {
let previousIntervalsDuration = new Seconds(0); let previousIntervalsDuration = new Duration(0);
return flatten( return flatten(
intervals.map((interval) => { intervals.map((interval) => {
const comments = offsetComments(interval, previousIntervalsDuration); const comments = offsetComments(interval, previousIntervalsDuration);

View File

@ -71,7 +71,7 @@ Rest: 5:00 45%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 300, "value": 300,
}, },
"intensity": Object { "intensity": Object {
@ -83,7 +83,7 @@ Rest: 5:00 45%
Object { Object {
"cadence": 90, "cadence": 90,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 600, "value": 600,
}, },
"intensity": Object { "intensity": Object {
@ -95,7 +95,7 @@ Rest: 5:00 45%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 300, "value": 300,
}, },
"intensity": Object { "intensity": Object {
@ -136,7 +136,7 @@ Interval: 5:00 50%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 300, "value": 300,
}, },
"intensity": Object { "intensity": Object {
@ -148,7 +148,7 @@ Interval: 5:00 50%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 600, "value": 600,
}, },
"intensity": Object { "intensity": Object {
@ -160,7 +160,7 @@ Interval: 5:00 50%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 300, "value": 300,
}, },
"intensity": Object { "intensity": Object {
@ -188,7 +188,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": 100, "cadence": 100,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 330, "value": 330,
}, },
"intensity": Object { "intensity": Object {
@ -200,7 +200,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 330, "value": 330,
}, },
"intensity": Object { "intensity": Object {
@ -232,7 +232,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": undefined, "cadence": undefined,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 10, "value": 10,
}, },
"intensity": Object { "intensity": Object {
@ -246,7 +246,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": 100, "cadence": 100,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 10, "value": 10,
}, },
"intensity": Object { "intensity": Object {
@ -260,7 +260,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": 100, "cadence": 100,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 10, "value": 10,
}, },
"intensity": Object { "intensity": Object {
@ -277,7 +277,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": 100, "cadence": 100,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 10, "value": 10,
}, },
"intensity": Object { "intensity": Object {
@ -291,7 +291,7 @@ Cooldown: 5:30 70%..45%
Object { Object {
"cadence": 100, "cadence": 100,
"comments": Array [], "comments": Array [],
"duration": Seconds { "duration": Duration {
"value": 10, "value": 10,
}, },
"intensity": Object { "intensity": Object {
@ -373,37 +373,37 @@ Rest: 5:00 50%
"cadence": undefined, "cadence": undefined,
"comments": Array [ "comments": Array [
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 0, "value": 0,
}, },
"text": "Find your rythm.", "text": "Find your rythm.",
}, },
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 60, "value": 60,
}, },
"text": "Try to settle in for the effort", "text": "Try to settle in for the effort",
}, },
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 300, "value": 300,
}, },
"text": "Half way through", "text": "Half way through",
}, },
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 540, "value": 540,
}, },
"text": "Almost there", "text": "Almost there",
}, },
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 570, "value": 570,
}, },
"text": "Final push. YOU GOT IT!", "text": "Final push. YOU GOT IT!",
}, },
], ],
"duration": Seconds { "duration": Duration {
"value": 600, "value": 600,
}, },
"intensity": Object { "intensity": Object {
@ -416,19 +416,19 @@ Rest: 5:00 50%
"cadence": undefined, "cadence": undefined,
"comments": Array [ "comments": Array [
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 0, "value": 0,
}, },
"text": "Great effort!", "text": "Great effort!",
}, },
Object { Object {
"offset": Seconds { "offset": Duration {
"value": 30, "value": 30,
}, },
"text": "Cool down well after all of this.", "text": "Cool down well after all of this.",
}, },
], ],
"duration": Seconds { "duration": Duration {
"value": 300, "value": 300,
}, },
"intensity": Object { "intensity": Object {

View File

@ -1,5 +1,5 @@
import { Interval, Workout, Comment } from "../ast"; import { Interval, Workout, Comment } from "../ast";
import { Seconds } from "../Seconds"; import { Duration } from "../Duration";
import { ParseError } from "./ParseError"; import { ParseError } from "./ParseError";
import { SourceLocation, Token } from "./tokenizer"; import { SourceLocation, Token } from "./tokenizer";
@ -66,7 +66,7 @@ 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 Seconds(offset.value), offset: new Duration(offset.value),
text: text.value, text: text.value,
}); });
tokens = rest; tokens = rest;
@ -85,7 +85,7 @@ const parseIntervalParams = (tokens: Token[], loc: SourceLocation): [IntervalDat
while (tokens[0]) { while (tokens[0]) {
const token = tokens[0]; const token = tokens[0];
if (token.type === "duration") { if (token.type === "duration") {
data.duration = new Seconds(token.value); data.duration = new Duration(token.value);
tokens.shift(); tokens.shift();
} else if (token.type === "cadence") { } else if (token.type === "cadence") {
data.cadence = token.value; data.cadence = token.value;

View File

@ -1,5 +1,5 @@
import { Interval } from "../ast"; import { Interval } from "../ast";
import { Seconds } from "../Seconds"; import { Duration } from "../Duration";
export const totalDuration = (intervals: Interval[]): Seconds => export const totalDuration = (intervals: Interval[]): Duration =>
intervals.reduce((total, interval) => total.add(interval.duration), new Seconds(0)); intervals.reduce((total, interval) => total.add(interval.duration), new Duration(0));

View File

@ -1,5 +1,5 @@
import { Interval } from "../ast"; import { Interval } from "../ast";
import { Seconds } from "../Seconds"; import { Duration } from "../Duration";
// Training Stress Score formula from Training and Racing with a Power Meter: // Training Stress Score formula from Training and Racing with a Power Meter:
// //
@ -9,13 +9,13 @@ import { Seconds } from "../Seconds";
// W - power in watts // W - power in watts
// IF - intensity factor (power / FTP) // IF - intensity factor (power / FTP)
const steadyTss = (duration: Seconds, intensity: number): number => { const steadyTss = (duration: Duration, intensity: number): number => {
return ((duration.value * intensity * intensity) / 3600) * 100; return ((duration.value * intensity * intensity) / 3600) * 100;
}; };
const rangeTss = (duration: Seconds, from: number, to: number): number => { const rangeTss = (duration: Duration, from: number, to: number): number => {
let score = 0; let score = 0;
const step = new Seconds(1); const step = new Duration(1);
for (let i = 0; i < duration.value; i += step.value) { for (let i = 0; i < duration.value; i += step.value) {
const intensity = from + (to - from) * (i / duration.value); const intensity = from + (to - from) * (i / duration.value);
score += steadyTss(step, intensity); score += steadyTss(step, intensity);

View File

@ -1,4 +1,4 @@
import { Seconds } from "../Seconds"; import { Duration } from "../Duration";
// Training Stress Score formula from Training and Racing with a Power Meter: // Training Stress Score formula from Training and Racing with a Power Meter:
// //
@ -13,6 +13,6 @@ import { Seconds } from "../Seconds";
// TSS = (s * (FTP * IF) * IF) / (FTP * 3600) * 100 // TSS = (s * (FTP * IF) * IF) / (FTP * 3600) * 100
// TSS = (s * IF * IF) / 3600 * 100 // TSS = (s * IF * IF) / 3600 * 100
export const tss2 = (duration: Seconds, intensity: number): number => { export const tss2 = (duration: Duration, intensity: number): number => {
return ((duration.value * intensity * intensity) / 3600) * 100; return ((duration.value * intensity * intensity) / 3600) * 100;
}; };