mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
Fix daily leaderboard score (#3031)
* Fix daily leaderboard score * Remove comment
This commit is contained in:
parent
cd767bff1c
commit
efbfffaa75
|
@ -38,60 +38,31 @@ describe("Misc Utils", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("tensComplement", () => {
|
||||
const testCases = [
|
||||
{
|
||||
input: 123,
|
||||
expected: 877,
|
||||
},
|
||||
{
|
||||
input: 877,
|
||||
expected: 123,
|
||||
},
|
||||
{
|
||||
input: 0,
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
input: 86423,
|
||||
expected: 13577,
|
||||
},
|
||||
{
|
||||
input: 10998739999,
|
||||
expected: 89001260001,
|
||||
},
|
||||
];
|
||||
|
||||
_.each(testCases, ({ input, expected }) => {
|
||||
expect(misc.tensComplement(input)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it("kogascore", () => {
|
||||
const testCases = [
|
||||
{
|
||||
wpm: 214.8,
|
||||
acc: 93.04,
|
||||
timestamp: 1653586489000,
|
||||
expectedScore: 1214800930436711,
|
||||
expectedScore: 1214800930423111,
|
||||
},
|
||||
{
|
||||
wpm: 214.8,
|
||||
acc: 93.04,
|
||||
timestamp: 1653601763000,
|
||||
expectedScore: 1214800930421437,
|
||||
expectedScore: 1214800930407837,
|
||||
},
|
||||
{
|
||||
wpm: 199.37,
|
||||
acc: 97.69,
|
||||
timestamp: 1653588809000,
|
||||
expectedScore: 1199370976934391,
|
||||
expectedScore: 1199370976920791,
|
||||
},
|
||||
{
|
||||
wpm: 196.2,
|
||||
acc: 96.07,
|
||||
timestamp: 1653591901000,
|
||||
expectedScore: 1196200960731299,
|
||||
expectedScore: 1196200960717699,
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -91,33 +91,21 @@ export function matchesAPattern(text: string, pattern: string): boolean {
|
|||
return regex.test(text);
|
||||
}
|
||||
|
||||
export function tensComplement(num: number): number {
|
||||
if (num === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let i = 0;
|
||||
let temp = num;
|
||||
|
||||
while (temp !== 0) {
|
||||
++i;
|
||||
temp = Math.floor(temp / 10);
|
||||
}
|
||||
|
||||
return Math.pow(10, i) - num;
|
||||
}
|
||||
export const MILLISECONDS_IN_DAY = 86400000;
|
||||
|
||||
export function kogascore(wpm: number, acc: number, timestamp: number): number {
|
||||
const normalizedWpm = Math.floor(wpm * 100);
|
||||
const normalizedAcc = Math.floor(acc * 100);
|
||||
|
||||
const firstPart = (100000 + normalizedWpm) * 100000;
|
||||
const secondPart = (firstPart + normalizedAcc) * 100000;
|
||||
const padAmount = 100000;
|
||||
const firstPart = (padAmount + normalizedWpm) * padAmount;
|
||||
const secondPart = (firstPart + normalizedAcc) * padAmount;
|
||||
|
||||
const currentDayTimeMilliseconds = timestamp - (timestamp % 86400000);
|
||||
const todaySeconds = Math.floor(
|
||||
(timestamp - currentDayTimeMilliseconds) / 1000
|
||||
const currentDayTimeMilliseconds =
|
||||
timestamp - (timestamp % MILLISECONDS_IN_DAY);
|
||||
const todayMilliseconds = timestamp - currentDayTimeMilliseconds;
|
||||
|
||||
return (
|
||||
secondPart + Math.floor((MILLISECONDS_IN_DAY - todayMilliseconds) / 1000)
|
||||
);
|
||||
|
||||
return secondPart + tensComplement(todaySeconds);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue