More precise repeated interval XP calculations
This commit is contained in:
parent
e3ed1a2e0d
commit
61a4837afe
|
|
@ -67,19 +67,19 @@ describe("xp()", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Repeated interval", () => {
|
describe("Repeated interval", () => {
|
||||||
const createTestInterval = (seconds: number): RepeatedInterval => ({
|
const createTestInterval = (times: number, [onSeconds, offSeconds]: number[]): RepeatedInterval => ({
|
||||||
type: "repeat",
|
type: "repeat",
|
||||||
times: 2,
|
times,
|
||||||
intervals: [
|
intervals: [
|
||||||
{
|
{
|
||||||
type: "Interval",
|
type: "Interval",
|
||||||
duration: new Duration(seconds / 4),
|
duration: new Duration(onSeconds),
|
||||||
intensity: new ConstantIntensity(80),
|
intensity: new ConstantIntensity(80),
|
||||||
comments: [],
|
comments: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "Interval",
|
type: "Interval",
|
||||||
duration: new Duration(seconds / 4),
|
duration: new Duration(offSeconds),
|
||||||
intensity: new ConstantIntensity(70),
|
intensity: new ConstantIntensity(70),
|
||||||
comments: [],
|
comments: [],
|
||||||
},
|
},
|
||||||
|
|
@ -88,12 +88,20 @@ describe("xp()", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
[4 * 15, 11], // 1 minute
|
{ times: 2, intervals: [1, 1], expectedXp: 0 }, // 0:04
|
||||||
[4 * 30, 23], // 2 minutes
|
{ times: 3, intervals: [1, 1], expectedXp: 1 }, // 0:06
|
||||||
[4 * 60, 47], // 4 minutes
|
{ times: 2, intervals: [14, 14], expectedXp: 11 }, // 0:56
|
||||||
].forEach(([seconds, expectedXp]) => {
|
{ times: 2, intervals: [14, 15], expectedXp: 11 }, // 0:58
|
||||||
it(`${seconds}s produces ${expectedXp} XP`, () => {
|
{ times: 2, intervals: [15, 15], expectedXp: 11 }, // 1:00
|
||||||
expect(xp([createTestInterval(seconds)])).toEqual(expectedXp);
|
{ 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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ import { totalDuration } from "./totalDuration";
|
||||||
|
|
||||||
const intervalXp = (interval: Interval | RepeatedInterval): number => {
|
const intervalXp = (interval: Interval | RepeatedInterval): number => {
|
||||||
if (interval.type === "repeat") {
|
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;
|
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 {
|
} else {
|
||||||
if (interval.intensity instanceof RangeIntensity) {
|
if (interval.intensity instanceof RangeIntensity) {
|
||||||
// 6 XP per minute (1XP for every 10 seconds)
|
// 6 XP per minute (1XP for every 10 seconds)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue