From c516b80aff75362b9349a7b61d412fc8e18f5143 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 25 Sep 2020 13:51:01 +0300 Subject: [PATCH] Rename Duration.value -> Duration.seconds --- src/Duration.ts | 4 +- src/generateZwo.ts | 10 ++--- src/parser/parser.test.ts | 60 ++++++++++++++--------------- src/stats/index.ts | 2 +- src/stats/intervalsToIntensities.ts | 4 +- src/stats/tss.ts | 6 +-- src/stats/tss2.ts | 2 +- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Duration.ts b/src/Duration.ts index 117d501..806d18e 100644 --- a/src/Duration.ts +++ b/src/Duration.ts @@ -1,7 +1,7 @@ export class Duration { - constructor(readonly value: number) {} + constructor(readonly seconds: number) {} add(other: Duration): Duration { - return new Duration(this.value + other.value); + return new Duration(this.seconds + other.seconds); } } diff --git a/src/generateZwo.ts b/src/generateZwo.ts index 37715b4..aaf3dca 100644 --- a/src/generateZwo.ts +++ b/src/generateZwo.ts @@ -6,7 +6,7 @@ import { detectRepeats, RepeatedInterval } from "./detectRepeats"; const generateTextEvents = (comments: Comment[]): xml.XmlObject[] => { return comments.map(({ offset, text }) => ({ - textevent: [{ _attr: { timeoffset: offset.value, message: text } }], + textevent: [{ _attr: { timeoffset: offset.seconds, message: text } }], })); }; @@ -18,7 +18,7 @@ const generateRangeInterval = ( [tagName]: [ { _attr: { - Duration: duration.value, + Duration: duration.seconds, PowerLow: intensity.from, PowerHigh: intensity.to, ...(cadence ? { Cadence: cadence } : {}), @@ -34,7 +34,7 @@ const generateSteadyStateInterval = ({ duration, intensity, cadence, comments }: SteadyState: [ { _attr: { - Duration: duration.value, + Duration: duration.seconds, Power: intensity.from, ...(cadence ? { Cadence: cadence } : {}), }, @@ -52,11 +52,11 @@ const generateRepeatInterval = (repInterval: RepeatedInterval): xml.XmlObject => _attr: { Repeat: repInterval.times, - OnDuration: on.duration.value, + OnDuration: on.duration.seconds, OnPower: on.intensity.from, ...(on.cadence ? { Cadence: on.cadence } : {}), - OffDuration: off.duration.value, + OffDuration: off.duration.seconds, OffPower: off.intensity.from, ...(off.cadence ? { CadenceResting: off.cadence } : {}), }, diff --git a/src/parser/parser.test.ts b/src/parser/parser.test.ts index 51c939e..652131f 100644 --- a/src/parser/parser.test.ts +++ b/src/parser/parser.test.ts @@ -72,7 +72,7 @@ Rest: 5:00 45% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 300, + "seconds": 300, }, "intensity": Object { "from": 0.5, @@ -84,7 +84,7 @@ Rest: 5:00 45% "cadence": 90, "comments": Array [], "duration": Duration { - "value": 600, + "seconds": 600, }, "intensity": Object { "from": 0.8, @@ -96,7 +96,7 @@ Rest: 5:00 45% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 300, + "seconds": 300, }, "intensity": Object { "from": 0.45, @@ -137,7 +137,7 @@ Interval: 5:00 50% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 300, + "seconds": 300, }, "intensity": Object { "from": 0.5, @@ -149,7 +149,7 @@ Interval: 5:00 50% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 600, + "seconds": 600, }, "intensity": Object { "from": 1, @@ -161,7 +161,7 @@ Interval: 5:00 50% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 300, + "seconds": 300, }, "intensity": Object { "from": 0.5, @@ -189,7 +189,7 @@ Cooldown: 5:30 70%..45% "cadence": 100, "comments": Array [], "duration": Duration { - "value": 330, + "seconds": 330, }, "intensity": Object { "from": 0.5, @@ -201,7 +201,7 @@ Cooldown: 5:30 70%..45% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 330, + "seconds": 330, }, "intensity": Object { "from": 0.7, @@ -233,7 +233,7 @@ Cooldown: 5:30 70%..45% "cadence": undefined, "comments": Array [], "duration": Duration { - "value": 10, + "seconds": 10, }, "intensity": Object { "from": 0.5, @@ -247,7 +247,7 @@ Cooldown: 5:30 70%..45% "cadence": 100, "comments": Array [], "duration": Duration { - "value": 10, + "seconds": 10, }, "intensity": Object { "from": 0.5, @@ -261,7 +261,7 @@ Cooldown: 5:30 70%..45% "cadence": 100, "comments": Array [], "duration": Duration { - "value": 10, + "seconds": 10, }, "intensity": Object { "from": 0.5, @@ -278,7 +278,7 @@ Cooldown: 5:30 70%..45% "cadence": 100, "comments": Array [], "duration": Duration { - "value": 10, + "seconds": 10, }, "intensity": Object { "from": 0.5, @@ -292,7 +292,7 @@ Cooldown: 5:30 70%..45% "cadence": 100, "comments": Array [], "duration": Duration { - "value": 10, + "seconds": 10, }, "intensity": Object { "from": 0.5, @@ -304,14 +304,14 @@ Cooldown: 5:30 70%..45% }); it("parses correct duration formats", () => { - expect(parseInterval("Interval: 0:10 50%").duration.value).toEqual(10); - expect(parseInterval("Interval: 00:10 50%").duration.value).toEqual(10); - expect(parseInterval("Interval: 0:00:10 50%").duration.value).toEqual(10); - expect(parseInterval("Interval: 0:02:05 50%").duration.value).toEqual(125); - expect(parseInterval("Interval: 1:00:00 50%").duration.value).toEqual(3600); - expect(parseInterval("Interval: 1:00:0 50%").duration.value).toEqual(3600); - expect(parseInterval("Interval: 1:0:0 50%").duration.value).toEqual(3600); - expect(parseInterval("Interval: 10:00:00 50%").duration.value).toEqual(36000); + expect(parseInterval("Interval: 0:10 50%").duration.seconds).toEqual(10); + expect(parseInterval("Interval: 00:10 50%").duration.seconds).toEqual(10); + expect(parseInterval("Interval: 0:00:10 50%").duration.seconds).toEqual(10); + expect(parseInterval("Interval: 0:02:05 50%").duration.seconds).toEqual(125); + expect(parseInterval("Interval: 1:00:00 50%").duration.seconds).toEqual(3600); + expect(parseInterval("Interval: 1:00:0 50%").duration.seconds).toEqual(3600); + expect(parseInterval("Interval: 1:0:0 50%").duration.seconds).toEqual(3600); + expect(parseInterval("Interval: 10:00:00 50%").duration.seconds).toEqual(36000); }); it("throws error for incorrect duration formats", () => { @@ -374,37 +374,37 @@ Rest: 5:00 50% "comments": Array [ Object { "offset": Duration { - "value": 0, + "seconds": 0, }, "text": "Find your rythm.", }, Object { "offset": Duration { - "value": 60, + "seconds": 60, }, "text": "Try to settle in for the effort", }, Object { "offset": Duration { - "value": 300, + "seconds": 300, }, "text": "Half way through", }, Object { "offset": Duration { - "value": 540, + "seconds": 540, }, "text": "Almost there", }, Object { "offset": Duration { - "value": 570, + "seconds": 570, }, "text": "Final push. YOU GOT IT!", }, ], "duration": Duration { - "value": 600, + "seconds": 600, }, "intensity": Object { "from": 0.9, @@ -417,19 +417,19 @@ Rest: 5:00 50% "comments": Array [ Object { "offset": Duration { - "value": 0, + "seconds": 0, }, "text": "Great effort!", }, Object { "offset": Duration { - "value": 30, + "seconds": 30, }, "text": "Cool down well after all of this.", }, ], "duration": Duration { - "value": 300, + "seconds": 300, }, "intensity": Object { "from": 0.5, diff --git a/src/stats/index.ts b/src/stats/index.ts index 1d6909c..ca65caa 100644 --- a/src/stats/index.ts +++ b/src/stats/index.ts @@ -12,7 +12,7 @@ export const stats = ({ intervals }: Workout): string => { const normIntensity = normalizedIntensity(intervals); return ` -Total duration: ${(duration.value / 60).toFixed()} minutes +Total duration: ${(duration.seconds / 60).toFixed()} minutes Average intensity: ${(avgIntensity * 100).toFixed()}% Normalized intensity: ${(normIntensity * 100).toFixed()}% diff --git a/src/stats/intervalsToIntensities.ts b/src/stats/intervalsToIntensities.ts index ae6527c..6ae3dc4 100644 --- a/src/stats/intervalsToIntensities.ts +++ b/src/stats/intervalsToIntensities.ts @@ -5,9 +5,9 @@ import { Interval } from "../ast"; const intervalToIntensities = ({ duration, intensity }: Interval): number[] => { const seconds = []; const { from, to } = intensity; - for (let i = 0; i < duration.value; i++) { + for (let i = 0; i < duration.seconds; i++) { // Intensity in a single second - seconds.push(from + (to - from) * (i / duration.value)); + seconds.push(from + (to - from) * (i / duration.seconds)); } return seconds; }; diff --git a/src/stats/tss.ts b/src/stats/tss.ts index 6cc5a76..be7b4d5 100644 --- a/src/stats/tss.ts +++ b/src/stats/tss.ts @@ -10,14 +10,14 @@ import { Duration } from "../Duration"; // IF - intensity factor (power / FTP) const steadyTss = (duration: Duration, intensity: number): number => { - return ((duration.value * intensity * intensity) / 3600) * 100; + return ((duration.seconds * intensity * intensity) / 3600) * 100; }; const rangeTss = (duration: Duration, from: number, to: number): number => { let score = 0; const step = new Duration(1); - for (let i = 0; i < duration.value; i += step.value) { - const intensity = from + (to - from) * (i / duration.value); + for (let i = 0; i < duration.seconds; i += step.seconds) { + const intensity = from + (to - from) * (i / duration.seconds); score += steadyTss(step, intensity); } return score; diff --git a/src/stats/tss2.ts b/src/stats/tss2.ts index 9d3c7b6..7073ae4 100644 --- a/src/stats/tss2.ts +++ b/src/stats/tss2.ts @@ -14,5 +14,5 @@ import { Duration } from "../Duration"; // TSS = (s * IF * IF) / 3600 * 100 export const tss2 = (duration: Duration, intensity: number): number => { - return ((duration.value * intensity * intensity) / 3600) * 100; + return ((duration.seconds * intensity * intensity) / 3600) * 100; };