Separate formatting of stats
This commit is contained in:
parent
c1a435e4d0
commit
77c6a721d4
|
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { generateZwo, parse, stats, parseCliOptions } = require("../dist/index");
|
const { generateZwo, parse, stats, formatStats, parseCliOptions } = require("../dist/index");
|
||||||
|
|
||||||
const opts = parseCliOptions();
|
const opts = parseCliOptions();
|
||||||
|
|
||||||
const workout = parse(fs.readFileSync(opts.file, "utf8"));
|
const workout = parse(fs.readFileSync(opts.file, "utf8"));
|
||||||
|
|
||||||
if (opts.stats) {
|
if (opts.stats) {
|
||||||
console.log(stats(workout));
|
console.log(formatStats(stats(workout)));
|
||||||
} else {
|
} else {
|
||||||
console.log(generateZwo(workout));
|
console.log(generateZwo(workout));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export { generateZwo } from "./generateZwo";
|
export { generateZwo } from "./generateZwo";
|
||||||
export { parse } from "./parser";
|
export { parse } from "./parser";
|
||||||
export { stats } from "./stats";
|
export { stats, formatStats } from "./stats";
|
||||||
export { parseCliOptions } from "./parseCliOptions";
|
export { parseCliOptions } from "./parseCliOptions";
|
||||||
|
|
||||||
// types
|
// types
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,41 @@
|
||||||
import { Workout } from "../ast";
|
import { Workout } from "../ast";
|
||||||
|
import { Duration } from "../Duration";
|
||||||
|
import { Intensity } from "../Intensity";
|
||||||
import { averageIntensity } from "./averageIntensity";
|
import { averageIntensity } from "./averageIntensity";
|
||||||
import { normalizedIntensity } from "./normalizedIntensity";
|
import { normalizedIntensity } from "./normalizedIntensity";
|
||||||
import { totalDuration } from "./totalDuration";
|
import { totalDuration } from "./totalDuration";
|
||||||
import { tss } from "./tss";
|
import { tss } from "./tss";
|
||||||
import { zoneDistribution } from "./zoneDistribution";
|
import { zoneDistribution, ZoneDuration } from "./zoneDistribution";
|
||||||
|
|
||||||
|
export type Stats = {
|
||||||
|
totalDuration: Duration;
|
||||||
|
averageIntensity: Intensity;
|
||||||
|
normalizedIntensity: Intensity;
|
||||||
|
tss: number;
|
||||||
|
zones: ZoneDuration[];
|
||||||
|
};
|
||||||
|
|
||||||
// Generates statistics
|
// Generates statistics
|
||||||
export const stats = ({ intervals }: Workout): string => {
|
export const stats = ({ intervals }: Workout): Stats => {
|
||||||
const duration = totalDuration(intervals);
|
const duration = totalDuration(intervals);
|
||||||
const avgIntensity = averageIntensity(intervals);
|
|
||||||
const normIntensity = normalizedIntensity(intervals);
|
const normIntensity = normalizedIntensity(intervals);
|
||||||
const zones = zoneDistribution(intervals);
|
return {
|
||||||
|
totalDuration: totalDuration(intervals),
|
||||||
|
averageIntensity: averageIntensity(intervals),
|
||||||
|
normalizedIntensity: normalizedIntensity(intervals),
|
||||||
|
tss: tss(duration, normIntensity),
|
||||||
|
zones: zoneDistribution(intervals),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const formatStats = ({ totalDuration, averageIntensity, normalizedIntensity, tss, zones }: Stats) => {
|
||||||
return `
|
return `
|
||||||
Total duration: ${(duration.seconds / 60).toFixed()} minutes
|
Total duration: ${(totalDuration.seconds / 60).toFixed()} minutes
|
||||||
|
|
||||||
Average intensity: ${(avgIntensity.value * 100).toFixed()}%
|
Average intensity: ${(averageIntensity.value * 100).toFixed()}%
|
||||||
Normalized intensity: ${(normIntensity.value * 100).toFixed()}%
|
Normalized intensity: ${(normalizedIntensity.value * 100).toFixed()}%
|
||||||
|
|
||||||
TSS: ${tss(duration, normIntensity).toFixed()}
|
TSS: ${tss.toFixed()}
|
||||||
|
|
||||||
Zone Distribution:
|
Zone Distribution:
|
||||||
${zones.map(({ name, duration }) => `${(duration.seconds / 60).toFixed().padStart(3)} min - ${name}`).join("\n")}
|
${zones.map(({ name, duration }) => `${(duration.seconds / 60).toFixed().padStart(3)} min - ${name}`).join("\n")}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { intensityValueToZoneType, ZoneType } from "../ZoneType";
|
||||||
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 };
|
export type ZoneDuration = { name: string; duration: Duration };
|
||||||
|
|
||||||
const emptyZones = (): Record<ZoneType, NumericZoneDuration> => ({
|
const emptyZones = (): Record<ZoneType, NumericZoneDuration> => ({
|
||||||
Z1: { name: "Z1: Recovery", duration: 0 },
|
Z1: { name: "Z1: Recovery", duration: 0 },
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { generateZwo } from "../src/generateZwo";
|
import { generateZwo } from "../src/generateZwo";
|
||||||
import { parse } from "../src/parser";
|
import { parse } from "../src/parser";
|
||||||
import { stats } from "../src/stats";
|
import { formatStats, stats } from "../src/stats";
|
||||||
|
|
||||||
const createStats = (filename: string) => stats(parse(fs.readFileSync(filename, "utf8")));
|
const createStats = (filename: string) => formatStats(stats(parse(fs.readFileSync(filename, "utf8"))));
|
||||||
const createZwo = (filename: string) => generateZwo(parse(fs.readFileSync(filename, "utf8")));
|
const createZwo = (filename: string) => generateZwo(parse(fs.readFileSync(filename, "utf8")));
|
||||||
|
|
||||||
const filenames = [
|
const filenames = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue