diff --git a/src/stats/index.ts b/src/stats/index.ts index dc6a250..9065d79 100644 --- a/src/stats/index.ts +++ b/src/stats/index.ts @@ -1,10 +1,12 @@ import { Workout } from "../ast"; +import { detectRepeats } from "../detectRepeats"; import { Duration } from "../Duration"; import { Intensity } from "../Intensity"; import { averageIntensity } from "./averageIntensity"; import { normalizedIntensity } from "./normalizedIntensity"; import { totalDuration } from "./totalDuration"; import { tss } from "./tss"; +import { xp } from "./xp"; import { zoneDistribution, ZoneDuration } from "./zoneDistribution"; export type Stats = { @@ -12,6 +14,7 @@ export type Stats = { averageIntensity: Intensity; normalizedIntensity: Intensity; tss: number; + xp: number; zones: ZoneDuration[]; }; @@ -24,11 +27,12 @@ export const stats = ({ intervals }: Workout): Stats => { averageIntensity: averageIntensity(intervals), normalizedIntensity: normalizedIntensity(intervals), tss: tss(duration, normIntensity), + xp: xp(detectRepeats(intervals)), zones: zoneDistribution(intervals), }; }; -export const formatStats = ({ totalDuration, averageIntensity, normalizedIntensity, tss, zones }: Stats) => { +export const formatStats = ({ totalDuration, averageIntensity, normalizedIntensity, tss, xp, zones }: Stats) => { return ` Total duration: ${(totalDuration.seconds / 60).toFixed()} minutes @@ -36,6 +40,7 @@ Average intensity: ${(averageIntensity.value * 100).toFixed()}% Normalized intensity: ${(normalizedIntensity.value * 100).toFixed()}% TSS: ${tss.toFixed()} +XP: ${xp} Zone Distribution: ${zones.map(({ name, duration }) => `${(duration.seconds / 60).toFixed().padStart(3)} min - ${name}`).join("\n")} diff --git a/test/__snapshots__/cli.test.ts.snap b/test/__snapshots__/cli.test.ts.snap index 298b782..fe4ac29 100644 --- a/test/__snapshots__/cli.test.ts.snap +++ b/test/__snapshots__/cli.test.ts.snap @@ -262,6 +262,7 @@ Average intensity: 60% Normalized intensity: 74% TSS: 22 +XP: 173 Zone Distribution: 15 min - Z1: Recovery @@ -282,6 +283,7 @@ Average intensity: 79% Normalized intensity: 84% TSS: 51 +XP: 502 Zone Distribution: 10 min - Z1: Recovery @@ -302,6 +304,7 @@ Average intensity: 36% Normalized intensity: 71% TSS: 37 +XP: 336 Zone Distribution: 15 min - Z1: Recovery @@ -322,6 +325,7 @@ Average intensity: 74% Normalized intensity: 81% TSS: 68 +XP: 628 Zone Distribution: 22 min - Z1: Recovery @@ -342,6 +346,7 @@ Average intensity: 69% Normalized intensity: 78% TSS: 81 +XP: 755 Zone Distribution: 42 min - Z1: Recovery