mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
moved key stats up,
moved hash check down
This commit is contained in:
parent
9f99e1ee37
commit
1205b5cfd4
1 changed files with 45 additions and 45 deletions
|
@ -174,32 +174,28 @@ export async function addResult(
|
|||
}
|
||||
}
|
||||
|
||||
if (req.ctx.configuration.users.lastHashesCheck.enabled) {
|
||||
let lastHashes = user.lastReultHashes ?? [];
|
||||
if (lastHashes.includes(resulthash)) {
|
||||
Logger.logToDb(
|
||||
"duplicate_result",
|
||||
{
|
||||
lastHashes,
|
||||
resulthash,
|
||||
result,
|
||||
},
|
||||
uid
|
||||
);
|
||||
const status = MonkeyStatusCodes.DUPLICATE_RESULT;
|
||||
throw new MonkeyError(status.code, "Duplicate result");
|
||||
} else {
|
||||
lastHashes.unshift(resulthash);
|
||||
const maxHashes = req.ctx.configuration.users.lastHashesCheck.maxHashes;
|
||||
if (lastHashes.length > maxHashes) {
|
||||
lastHashes = lastHashes.slice(0, maxHashes);
|
||||
}
|
||||
await UserDAL.updateLastHashes(uid, lastHashes);
|
||||
try {
|
||||
result.keySpacingStats = {
|
||||
average:
|
||||
result.keySpacing.reduce((previous, current) => (current += previous)) /
|
||||
result.keySpacing.length,
|
||||
sd: stdDev(result.keySpacing),
|
||||
};
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
try {
|
||||
result.keyDurationStats = {
|
||||
average:
|
||||
result.keyDuration.reduce(
|
||||
(previous, current) => (current += previous)
|
||||
) / result.keyDuration.length,
|
||||
sd: stdDev(result.keyDuration),
|
||||
};
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
|
||||
result.name = user.name;
|
||||
|
||||
if (anticheatImplemented()) {
|
||||
if (!validateResult(result)) {
|
||||
const status = MonkeyStatusCodes.RESULT_DATA_INVALID;
|
||||
|
@ -266,28 +262,6 @@ export async function addResult(
|
|||
throw new MonkeyError(status.code, "Invalid result spacing");
|
||||
}
|
||||
|
||||
try {
|
||||
result.keySpacingStats = {
|
||||
average:
|
||||
result.keySpacing.reduce((previous, current) => (current += previous)) /
|
||||
result.keySpacing.length,
|
||||
sd: stdDev(result.keySpacing),
|
||||
};
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
try {
|
||||
result.keyDurationStats = {
|
||||
average:
|
||||
result.keyDuration.reduce(
|
||||
(previous, current) => (current += previous)
|
||||
) / result.keyDuration.length,
|
||||
sd: stdDev(result.keyDuration),
|
||||
};
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
|
||||
//check keyspacing and duration here for bots
|
||||
if (
|
||||
result.mode === "time" &&
|
||||
|
@ -336,6 +310,32 @@ export async function addResult(
|
|||
delete result.smoothConsistency;
|
||||
delete result.wpmConsistency;
|
||||
|
||||
if (req.ctx.configuration.users.lastHashesCheck.enabled) {
|
||||
let lastHashes = user.lastReultHashes ?? [];
|
||||
if (lastHashes.includes(resulthash)) {
|
||||
Logger.logToDb(
|
||||
"duplicate_result",
|
||||
{
|
||||
lastHashes,
|
||||
resulthash,
|
||||
result,
|
||||
},
|
||||
uid
|
||||
);
|
||||
const status = MonkeyStatusCodes.DUPLICATE_RESULT;
|
||||
throw new MonkeyError(status.code, "Duplicate result");
|
||||
} else {
|
||||
lastHashes.unshift(resulthash);
|
||||
const maxHashes = req.ctx.configuration.users.lastHashesCheck.maxHashes;
|
||||
if (lastHashes.length > maxHashes) {
|
||||
lastHashes = lastHashes.slice(0, maxHashes);
|
||||
}
|
||||
await UserDAL.updateLastHashes(uid, lastHashes);
|
||||
}
|
||||
}
|
||||
|
||||
result.name = user.name;
|
||||
|
||||
try {
|
||||
result.keyDurationStats.average = roundTo2(result.keyDurationStats.average);
|
||||
result.keyDurationStats.sd = roundTo2(result.keyDurationStats.sd);
|
||||
|
|
Loading…
Reference in a new issue