Add separate --stats option
This commit is contained in:
parent
5c34c7c167
commit
0f2d6c592c
|
|
@ -6,6 +6,8 @@
|
||||||
"lint:ts": "tsc --noEmit",
|
"lint:ts": "tsc --noEmit",
|
||||||
"test": "ts-node src/index.ts examples/threshold-pushing.txt",
|
"test": "ts-node src/index.ts examples/threshold-pushing.txt",
|
||||||
"test:2": "ts-node src/index.ts examples/darth-vader.txt",
|
"test:2": "ts-node src/index.ts examples/darth-vader.txt",
|
||||||
|
"test:stats": "ts-node src/index.ts --stats examples/threshold-pushing.txt",
|
||||||
|
"test:stats:2": "ts-node src/index.ts --stats examples/darth-vader.txt",
|
||||||
"format:js": "prettier --write src/"
|
"format:js": "prettier --write src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
43
src/index.ts
43
src/index.ts
|
|
@ -1,36 +1,21 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { averageIntensity } from "./averageIntensity";
|
|
||||||
import { generateZwo } from "./generateZwo";
|
import { generateZwo } from "./generateZwo";
|
||||||
import { normalizedIntensity } from "./normalizedIntensity";
|
|
||||||
import { parse } from "./parser";
|
import { parse } from "./parser";
|
||||||
|
import { stats } from "./stats";
|
||||||
import { tokenize } from "./tokenizer";
|
import { tokenize } from "./tokenizer";
|
||||||
import { totalDuration } from "./totalDuration";
|
|
||||||
import { tss } from "./tss";
|
|
||||||
import { tss2 } from "./tss2";
|
|
||||||
|
|
||||||
const filename = process.argv[2];
|
const opts = { stats: false, filename: "" };
|
||||||
|
if (process.argv[2] === "--stats") {
|
||||||
|
opts.stats = true;
|
||||||
|
opts.filename = process.argv[3];
|
||||||
|
} else {
|
||||||
|
opts.filename = process.argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Parsing: ${filename}`);
|
const workout = parse(tokenize(fs.readFileSync(opts.filename, "utf8")));
|
||||||
|
|
||||||
const file = fs.readFileSync(filename, "utf8");
|
if (opts.stats) {
|
||||||
|
console.log(stats(workout));
|
||||||
const workout = parse(tokenize(file));
|
} else {
|
||||||
const { intervals } = workout;
|
console.log(generateZwo(workout));
|
||||||
|
}
|
||||||
const duration = totalDuration(intervals);
|
|
||||||
const avgIntensity = averageIntensity(intervals);
|
|
||||||
const normIntensity = normalizedIntensity(intervals);
|
|
||||||
|
|
||||||
console.log(intervals);
|
|
||||||
|
|
||||||
console.log(`
|
|
||||||
Total duration: ${(duration / 60).toFixed()} minutes
|
|
||||||
|
|
||||||
Average intensity: ${(avgIntensity * 100).toFixed()}%
|
|
||||||
Normalized intensity: ${(normIntensity * 100).toFixed()}%
|
|
||||||
|
|
||||||
TSS #1: ${tss(intervals).toFixed()}
|
|
||||||
TSS #2: ${tss2(duration, normIntensity).toFixed()}
|
|
||||||
`);
|
|
||||||
|
|
||||||
console.log(generateZwo(workout));
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { pipe } from "ramda";
|
import { pipe } from "ramda";
|
||||||
import { Interval } from "./ast";
|
import { Interval } from "../ast";
|
||||||
import { average } from "./average";
|
import { average } from "./average";
|
||||||
import { intervalsToIntensities } from "./intervalsToIntensities";
|
import { intervalsToIntensities } from "./intervalsToIntensities";
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Workout } from "../ast";
|
||||||
|
import { averageIntensity } from "./averageIntensity";
|
||||||
|
import { normalizedIntensity } from "./normalizedIntensity";
|
||||||
|
import { totalDuration } from "./totalDuration";
|
||||||
|
import { tss } from "./tss";
|
||||||
|
import { tss2 } from "./tss2";
|
||||||
|
|
||||||
|
// Generates statistics
|
||||||
|
export const stats = ({ intervals }: Workout): string => {
|
||||||
|
const duration = totalDuration(intervals);
|
||||||
|
const avgIntensity = averageIntensity(intervals);
|
||||||
|
const normIntensity = normalizedIntensity(intervals);
|
||||||
|
|
||||||
|
return `
|
||||||
|
Total duration: ${(duration / 60).toFixed()} minutes
|
||||||
|
|
||||||
|
Average intensity: ${(avgIntensity * 100).toFixed()}%
|
||||||
|
Normalized intensity: ${(normIntensity * 100).toFixed()}%
|
||||||
|
|
||||||
|
TSS #1: ${tss(intervals).toFixed()}
|
||||||
|
TSS #2: ${tss2(duration, normIntensity).toFixed()}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { chain } from "ramda";
|
import { chain } from "ramda";
|
||||||
import { Interval } from "./ast";
|
import { Interval } from "../ast";
|
||||||
|
|
||||||
// Converts interval to array of intensity values for each second
|
// Converts interval to array of intensity values for each second
|
||||||
const intervalToIntensities = ({ duration, intensity }: Interval): number[] => {
|
const intervalToIntensities = ({ duration, intensity }: Interval): number[] => {
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { pipe, sum } from "ramda";
|
import { pipe, sum } from "ramda";
|
||||||
import { Interval } from "./ast";
|
import { Interval } from "../ast";
|
||||||
import { average } from "./average";
|
import { average } from "./average";
|
||||||
import { intervalsToIntensities } from "./intervalsToIntensities";
|
import { intervalsToIntensities } from "./intervalsToIntensities";
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { pluck, sum } from "ramda";
|
import { pluck, sum } from "ramda";
|
||||||
import { Interval } from "./ast";
|
import { Interval } from "../ast";
|
||||||
|
|
||||||
export const totalDuration = (intervals: Interval[]) =>
|
export const totalDuration = (intervals: Interval[]) =>
|
||||||
sum(pluck("duration", intervals));
|
sum(pluck("duration", intervals));
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Interval } from "./ast";
|
import { Interval } from "../ast";
|
||||||
|
|
||||||
// Training Stress Score formula from Training and Racing with a Power Meter:
|
// Training Stress Score formula from Training and Racing with a Power Meter:
|
||||||
//
|
//
|
||||||
Loading…
Reference in New Issue