Export intensityToZoneIndex

This commit is contained in:
Rene Saarsoo 2020-10-02 12:04:15 +03:00
parent 53344b22ce
commit f20976b00b
2 changed files with 6 additions and 1 deletions

View File

@ -10,3 +10,4 @@ export { Intensity, ConstantIntensity, RangeIntensity, FreeIntensity } from "./I
// stats utils // stats utils
export { totalDuration } from "./stats/totalDuration"; export { totalDuration } from "./stats/totalDuration";
export { intensityToZoneIndex, ZoneIndex } from "./stats/zoneDistribution";

View File

@ -1,10 +1,11 @@
import { Interval } from "../ast"; import { Interval } from "../ast";
import { Duration } from "../Duration"; import { Duration } from "../Duration";
import { Intensity } from "../Intensity";
import { intervalsToIntensityNumbers } from "./intervalsToIntensityNumbers"; import { intervalsToIntensityNumbers } from "./intervalsToIntensityNumbers";
type NumericZoneDuration = { name: string; duration: number }; type NumericZoneDuration = { name: string; duration: number };
type ZoneDuration = { name: string; duration: Duration }; type ZoneDuration = { name: string; duration: Duration };
type ZoneIndex = 0 | 1 | 2 | 3 | 4 | 5; export type ZoneIndex = 0 | 1 | 2 | 3 | 4 | 5;
const emptyZones = (): NumericZoneDuration[] => [ const emptyZones = (): NumericZoneDuration[] => [
{ name: "Z1: Recovery", duration: 0 }, { name: "Z1: Recovery", duration: 0 },
@ -35,6 +36,9 @@ const zoneIndex = (intensity: number): ZoneIndex => {
return 0; return 0;
}; };
// For external use (consumes Intensity interface instead of plain number)
export const intensityToZoneIndex = (intensity: Intensity): ZoneIndex => zoneIndex(intensity.value);
export const zoneDistribution = (intervals: Interval[]): ZoneDuration[] => { export const zoneDistribution = (intervals: Interval[]): ZoneDuration[] => {
const zones = emptyZones(); const zones = emptyZones();