From 61a4837afe4220b80a4df64cea65b115288e6d57 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 20 Nov 2020 17:39:01 +0200 Subject: [PATCH] More precise repeated interval XP calculations --- src/stats/xp.test.ts | 28 ++++++++++++++++++---------- src/stats/xp.ts | 4 ++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/stats/xp.test.ts b/src/stats/xp.test.ts index 8aff3c5..1e32d6d 100644 --- a/src/stats/xp.test.ts +++ b/src/stats/xp.test.ts @@ -67,19 +67,19 @@ describe("xp()", () => { }); describe("Repeated interval", () => { - const createTestInterval = (seconds: number): RepeatedInterval => ({ + const createTestInterval = (times: number, [onSeconds, offSeconds]: number[]): RepeatedInterval => ({ type: "repeat", - times: 2, + times, intervals: [ { type: "Interval", - duration: new Duration(seconds / 4), + duration: new Duration(onSeconds), intensity: new ConstantIntensity(80), comments: [], }, { type: "Interval", - duration: new Duration(seconds / 4), + duration: new Duration(offSeconds), intensity: new ConstantIntensity(70), comments: [], }, @@ -88,12 +88,20 @@ describe("xp()", () => { }); [ - [4 * 15, 11], // 1 minute - [4 * 30, 23], // 2 minutes - [4 * 60, 47], // 4 minutes - ].forEach(([seconds, expectedXp]) => { - it(`${seconds}s produces ${expectedXp} XP`, () => { - expect(xp([createTestInterval(seconds)])).toEqual(expectedXp); + { times: 2, intervals: [1, 1], expectedXp: 0 }, // 0:04 + { times: 3, intervals: [1, 1], expectedXp: 1 }, // 0:06 + { times: 2, intervals: [14, 14], expectedXp: 11 }, // 0:56 + { times: 2, intervals: [14, 15], expectedXp: 11 }, // 0:58 + { times: 2, intervals: [15, 15], expectedXp: 11 }, // 1:00 + { times: 2, intervals: [15, 16], expectedXp: 12 }, // 1:02 + { times: 2, intervals: [16, 16], expectedXp: 12 }, // 1:04 + { times: 3, intervals: [14, 15], expectedXp: 17 }, // 1:27 + { times: 3, intervals: [15, 16], expectedXp: 18 }, // 1:33 + { times: 2, intervals: [30, 30], expectedXp: 23 }, // 2:00 + { times: 2, intervals: [60, 60], expectedXp: 47 }, // 4:00 + ].forEach(({ times, intervals, expectedXp }) => { + it(`${times} x (${intervals[0]}s on & ${intervals[1]}s off) produces ${expectedXp} XP`, () => { + expect(xp([createTestInterval(times, intervals)])).toEqual(expectedXp); }); }); }); diff --git a/src/stats/xp.ts b/src/stats/xp.ts index e70dd16..75763fb 100644 --- a/src/stats/xp.ts +++ b/src/stats/xp.ts @@ -6,9 +6,9 @@ import { totalDuration } from "./totalDuration"; const intervalXp = (interval: Interval | RepeatedInterval): number => { if (interval.type === "repeat") { - // 11 XP per minute (1 XP for every 5.1 seconds) + // 11 XP per minute (1 XP for every 5.05 seconds) const duration = totalDuration(interval.intervals).seconds * interval.times; - return Math.floor(duration / 5.1); + return Math.floor(duration / 5.05); // Suitable numbers are: 5.01 .. 5.09 } else { if (interval.intensity instanceof RangeIntensity) { // 6 XP per minute (1XP for every 10 seconds)