Rename Duration.value -> Duration.seconds
This commit is contained in:
parent
61ea726187
commit
c516b80aff
|
|
@ -1,7 +1,7 @@
|
|||
export class Duration {
|
||||
constructor(readonly value: number) {}
|
||||
constructor(readonly seconds: number) {}
|
||||
|
||||
add(other: Duration): Duration {
|
||||
return new Duration(this.value + other.value);
|
||||
return new Duration(this.seconds + other.seconds);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { detectRepeats, RepeatedInterval } from "./detectRepeats";
|
|||
|
||||
const generateTextEvents = (comments: Comment[]): xml.XmlObject[] => {
|
||||
return comments.map(({ offset, text }) => ({
|
||||
textevent: [{ _attr: { timeoffset: offset.value, message: text } }],
|
||||
textevent: [{ _attr: { timeoffset: offset.seconds, message: text } }],
|
||||
}));
|
||||
};
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ const generateRangeInterval = (
|
|||
[tagName]: [
|
||||
{
|
||||
_attr: {
|
||||
Duration: duration.value,
|
||||
Duration: duration.seconds,
|
||||
PowerLow: intensity.from,
|
||||
PowerHigh: intensity.to,
|
||||
...(cadence ? { Cadence: cadence } : {}),
|
||||
|
|
@ -34,7 +34,7 @@ const generateSteadyStateInterval = ({ duration, intensity, cadence, comments }:
|
|||
SteadyState: [
|
||||
{
|
||||
_attr: {
|
||||
Duration: duration.value,
|
||||
Duration: duration.seconds,
|
||||
Power: intensity.from,
|
||||
...(cadence ? { Cadence: cadence } : {}),
|
||||
},
|
||||
|
|
@ -52,11 +52,11 @@ const generateRepeatInterval = (repInterval: RepeatedInterval): xml.XmlObject =>
|
|||
_attr: {
|
||||
Repeat: repInterval.times,
|
||||
|
||||
OnDuration: on.duration.value,
|
||||
OnDuration: on.duration.seconds,
|
||||
OnPower: on.intensity.from,
|
||||
...(on.cadence ? { Cadence: on.cadence } : {}),
|
||||
|
||||
OffDuration: off.duration.value,
|
||||
OffDuration: off.duration.seconds,
|
||||
OffPower: off.intensity.from,
|
||||
...(off.cadence ? { CadenceResting: off.cadence } : {}),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ Rest: 5:00 45%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -84,7 +84,7 @@ Rest: 5:00 45%
|
|||
"cadence": 90,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 600,
|
||||
"seconds": 600,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.8,
|
||||
|
|
@ -96,7 +96,7 @@ Rest: 5:00 45%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.45,
|
||||
|
|
@ -137,7 +137,7 @@ Interval: 5:00 50%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -149,7 +149,7 @@ Interval: 5:00 50%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 600,
|
||||
"seconds": 600,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 1,
|
||||
|
|
@ -161,7 +161,7 @@ Interval: 5:00 50%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -189,7 +189,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": 100,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 330,
|
||||
"seconds": 330,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -201,7 +201,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 330,
|
||||
"seconds": 330,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.7,
|
||||
|
|
@ -233,7 +233,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": undefined,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 10,
|
||||
"seconds": 10,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -247,7 +247,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": 100,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 10,
|
||||
"seconds": 10,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -261,7 +261,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": 100,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 10,
|
||||
"seconds": 10,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -278,7 +278,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": 100,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 10,
|
||||
"seconds": 10,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -292,7 +292,7 @@ Cooldown: 5:30 70%..45%
|
|||
"cadence": 100,
|
||||
"comments": Array [],
|
||||
"duration": Duration {
|
||||
"value": 10,
|
||||
"seconds": 10,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
@ -304,14 +304,14 @@ Cooldown: 5:30 70%..45%
|
|||
});
|
||||
|
||||
it("parses correct duration formats", () => {
|
||||
expect(parseInterval("Interval: 0:10 50%").duration.value).toEqual(10);
|
||||
expect(parseInterval("Interval: 00:10 50%").duration.value).toEqual(10);
|
||||
expect(parseInterval("Interval: 0:00:10 50%").duration.value).toEqual(10);
|
||||
expect(parseInterval("Interval: 0:02:05 50%").duration.value).toEqual(125);
|
||||
expect(parseInterval("Interval: 1:00:00 50%").duration.value).toEqual(3600);
|
||||
expect(parseInterval("Interval: 1:00:0 50%").duration.value).toEqual(3600);
|
||||
expect(parseInterval("Interval: 1:0:0 50%").duration.value).toEqual(3600);
|
||||
expect(parseInterval("Interval: 10:00:00 50%").duration.value).toEqual(36000);
|
||||
expect(parseInterval("Interval: 0:10 50%").duration.seconds).toEqual(10);
|
||||
expect(parseInterval("Interval: 00:10 50%").duration.seconds).toEqual(10);
|
||||
expect(parseInterval("Interval: 0:00:10 50%").duration.seconds).toEqual(10);
|
||||
expect(parseInterval("Interval: 0:02:05 50%").duration.seconds).toEqual(125);
|
||||
expect(parseInterval("Interval: 1:00:00 50%").duration.seconds).toEqual(3600);
|
||||
expect(parseInterval("Interval: 1:00:0 50%").duration.seconds).toEqual(3600);
|
||||
expect(parseInterval("Interval: 1:0:0 50%").duration.seconds).toEqual(3600);
|
||||
expect(parseInterval("Interval: 10:00:00 50%").duration.seconds).toEqual(36000);
|
||||
});
|
||||
|
||||
it("throws error for incorrect duration formats", () => {
|
||||
|
|
@ -374,37 +374,37 @@ Rest: 5:00 50%
|
|||
"comments": Array [
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 0,
|
||||
"seconds": 0,
|
||||
},
|
||||
"text": "Find your rythm.",
|
||||
},
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 60,
|
||||
"seconds": 60,
|
||||
},
|
||||
"text": "Try to settle in for the effort",
|
||||
},
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"text": "Half way through",
|
||||
},
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 540,
|
||||
"seconds": 540,
|
||||
},
|
||||
"text": "Almost there",
|
||||
},
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 570,
|
||||
"seconds": 570,
|
||||
},
|
||||
"text": "Final push. YOU GOT IT!",
|
||||
},
|
||||
],
|
||||
"duration": Duration {
|
||||
"value": 600,
|
||||
"seconds": 600,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.9,
|
||||
|
|
@ -417,19 +417,19 @@ Rest: 5:00 50%
|
|||
"comments": Array [
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 0,
|
||||
"seconds": 0,
|
||||
},
|
||||
"text": "Great effort!",
|
||||
},
|
||||
Object {
|
||||
"offset": Duration {
|
||||
"value": 30,
|
||||
"seconds": 30,
|
||||
},
|
||||
"text": "Cool down well after all of this.",
|
||||
},
|
||||
],
|
||||
"duration": Duration {
|
||||
"value": 300,
|
||||
"seconds": 300,
|
||||
},
|
||||
"intensity": Object {
|
||||
"from": 0.5,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export const stats = ({ intervals }: Workout): string => {
|
|||
const normIntensity = normalizedIntensity(intervals);
|
||||
|
||||
return `
|
||||
Total duration: ${(duration.value / 60).toFixed()} minutes
|
||||
Total duration: ${(duration.seconds / 60).toFixed()} minutes
|
||||
|
||||
Average intensity: ${(avgIntensity * 100).toFixed()}%
|
||||
Normalized intensity: ${(normIntensity * 100).toFixed()}%
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { Interval } from "../ast";
|
|||
const intervalToIntensities = ({ duration, intensity }: Interval): number[] => {
|
||||
const seconds = [];
|
||||
const { from, to } = intensity;
|
||||
for (let i = 0; i < duration.value; i++) {
|
||||
for (let i = 0; i < duration.seconds; i++) {
|
||||
// Intensity in a single second
|
||||
seconds.push(from + (to - from) * (i / duration.value));
|
||||
seconds.push(from + (to - from) * (i / duration.seconds));
|
||||
}
|
||||
return seconds;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ import { Duration } from "../Duration";
|
|||
// IF - intensity factor (power / FTP)
|
||||
|
||||
const steadyTss = (duration: Duration, intensity: number): number => {
|
||||
return ((duration.value * intensity * intensity) / 3600) * 100;
|
||||
return ((duration.seconds * intensity * intensity) / 3600) * 100;
|
||||
};
|
||||
|
||||
const rangeTss = (duration: Duration, from: number, to: number): number => {
|
||||
let score = 0;
|
||||
const step = new Duration(1);
|
||||
for (let i = 0; i < duration.value; i += step.value) {
|
||||
const intensity = from + (to - from) * (i / duration.value);
|
||||
for (let i = 0; i < duration.seconds; i += step.seconds) {
|
||||
const intensity = from + (to - from) * (i / duration.seconds);
|
||||
score += steadyTss(step, intensity);
|
||||
}
|
||||
return score;
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@ import { Duration } from "../Duration";
|
|||
// TSS = (s * IF * IF) / 3600 * 100
|
||||
|
||||
export const tss2 = (duration: Duration, intensity: number): number => {
|
||||
return ((duration.value * intensity * intensity) / 3600) * 100;
|
||||
return ((duration.seconds * intensity * intensity) / 3600) * 100;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue