diff --git a/src/stats/zoneDistribution.test.ts b/src/stats/zoneDistribution.test.ts index 9660d0a..837a092 100644 --- a/src/stats/zoneDistribution.test.ts +++ b/src/stats/zoneDistribution.test.ts @@ -1,6 +1,6 @@ import { Interval } from "../ast"; import { Duration } from "../Duration"; -import { ConstantIntensity, RangeIntensity } from "../Intensity"; +import { ConstantIntensity, FreeIntensity, RangeIntensity } from "../Intensity"; import { zoneDistribution } from "./zoneDistribution"; const testZoneDistribution = (intervals: Interval[]) => @@ -102,4 +102,24 @@ describe("zoneDistribution()", () => { ["Freeride", 0], ]); }); + + it("places free-intensity duration to special free-zone", () => { + const intervals: Interval[] = [ + { + type: "Interval", + duration: new Duration(60), + intensity: new FreeIntensity(), + comments: [], + }, + ]; + expect(testZoneDistribution(intervals)).toEqual([ + ["Z1: Recovery", 0], + ["Z2: Endurance", 0], + ["Z3: Tempo", 0], + ["Z4: Threshold", 0], + ["Z5: VO2 Max", 0], + ["Z6: Anaerobic", 0], + ["Freeride", 60], + ]); + }); }); diff --git a/src/stats/zoneDistribution.ts b/src/stats/zoneDistribution.ts index 5e68741..53a15bd 100644 --- a/src/stats/zoneDistribution.ts +++ b/src/stats/zoneDistribution.ts @@ -1,5 +1,6 @@ import { Interval } from "../ast"; import { Duration } from "../Duration"; +import { RangeIntensity } from "../Intensity"; import { intensityValueToZoneType, ZoneType } from "../ZoneType"; import { intervalsToIntensityNumbers } from "./intervalsToIntensityNumbers"; @@ -19,8 +20,14 @@ const emptyZones = (): Record => ({ export const zoneDistribution = (intervals: Interval[]): ZoneDuration[] => { const zones = emptyZones(); - intervalsToIntensityNumbers(intervals).forEach((intensity) => { - zones[intensityValueToZoneType(intensity)].duration++; + intervals.forEach((interval) => { + if (interval.intensity instanceof RangeIntensity) { + intervalsToIntensityNumbers([interval]).forEach((intensityValue) => { + zones[intensityValueToZoneType(intensityValue)].duration++; + }); + } else { + zones[interval.intensity.zone].duration += interval.duration.seconds; + } }); return Object.values(zones).map(({ duration, ...rest }) => ({ duration: new Duration(duration), ...rest })); diff --git a/test/__snapshots__/cli.test.ts.snap b/test/__snapshots__/cli.test.ts.snap index 211ddd1..6284895 100644 --- a/test/__snapshots__/cli.test.ts.snap +++ b/test/__snapshots__/cli.test.ts.snap @@ -288,13 +288,13 @@ Normalized intensity: 71% TSS: 37 Zone Distribution: - 35 min - Z1: Recovery + 15 min - Z1: Recovery 4 min - Z2: Endurance 0 min - Z3: Tempo 0 min - Z4: Threshold 3 min - Z5: VO2 Max 2 min - Z6: Anaerobic - 0 min - Freeride + 20 min - Freeride " `;