mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-29 18:37:58 +03:00
add the concept of userIntent
This commit is contained in:
@@ -82,7 +82,7 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
let importDocument = await ScoreImportMain(userDoc, importType, inputParser);
|
||||
let importDocument = await ScoreImportMain(userDoc, true, importType, inputParser);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -8,8 +8,93 @@ import { ImportInputParser, ScorePlaytypeMap } from "../../types";
|
||||
import { InsertQueue } from "./core/insert-score";
|
||||
import { ImportAllIterableData } from "./importing/score-importing";
|
||||
import { CreateImportLoggerAndID } from "./core/import-logger";
|
||||
import { Logger } from "winston";
|
||||
import { CreateSessions } from "./core/sessions/sessions";
|
||||
import { GetMilisecondsSince } from "../../core/hrtime-core";
|
||||
|
||||
export default async function ScoreImportMain<D, C>(
|
||||
user: PublicUserDocument,
|
||||
userIntent: boolean,
|
||||
importType: ImportTypes,
|
||||
InputParser: ImportInputParser<D, C>
|
||||
) {
|
||||
const timeStarted = Date.now();
|
||||
const { importID, logger } = CreateImportLoggerAndID(user, importType);
|
||||
logger.verbose("Received import request.");
|
||||
|
||||
const parseTimeStart = process.hrtime.bigint();
|
||||
const { iterable, ConverterFunction, context, idStrings, game } = await InputParser(logger);
|
||||
|
||||
const parseTime = GetMilisecondsSince(parseTimeStart);
|
||||
|
||||
logger.verbose(`Parsing took ${parseTime} miliseconds.`);
|
||||
|
||||
const importTimeStart = process.hrtime.bigint();
|
||||
|
||||
let importInfo = await ImportAllIterableData(
|
||||
user.id,
|
||||
iterable,
|
||||
ConverterFunction,
|
||||
context,
|
||||
logger
|
||||
);
|
||||
|
||||
// Flush the score queue out after importing.
|
||||
let emptied = await InsertQueue();
|
||||
|
||||
if (emptied) {
|
||||
logger.verbose(`Emptied ${emptied} documents from score queue.`);
|
||||
}
|
||||
|
||||
const importTime = GetMilisecondsSince(importTimeStart);
|
||||
|
||||
logger.verbose(
|
||||
`Importing took ${importTime} miliseconds. (${importTime / importInfo.length}ms/doc)`
|
||||
);
|
||||
|
||||
let { scorePlaytypeMap, errors, scoreIDs } = ParseImportInfo(importInfo);
|
||||
|
||||
// Update user's rating information
|
||||
// @todo
|
||||
|
||||
const sessionTimeStart = process.hrtime.bigint();
|
||||
|
||||
let sessionInfo = await CreateSessions(user.id, importType, game, scorePlaytypeMap, logger);
|
||||
|
||||
const sessionTime = GetMilisecondsSince(sessionTimeStart);
|
||||
|
||||
logger.verbose(
|
||||
`Session Processing took ${sessionTime} miliseconds (${
|
||||
sessionTime / sessionInfo.length
|
||||
}ms/doc).`
|
||||
);
|
||||
|
||||
// Create import document
|
||||
const ImportDocument: KTBlackImportDocument = {
|
||||
importType,
|
||||
idStrings: idStrings,
|
||||
scoreIDs,
|
||||
errors,
|
||||
importID,
|
||||
timeFinished: Date.now(),
|
||||
timeStarted,
|
||||
createdSessions: sessionInfo,
|
||||
userID: user.id,
|
||||
userIntent,
|
||||
};
|
||||
|
||||
logger.info(
|
||||
`Import took: ${ImportDocument.timeFinished - timeStarted}ms, with ${
|
||||
importInfo.length
|
||||
} documents (Fails: ${errors.length}, Successes: ${scoreIDs.length}, Sessions: ${
|
||||
sessionInfo.length
|
||||
}). Aprx ${(ImportDocument.timeFinished - timeStarted) / importInfo.length}ms/doc`
|
||||
);
|
||||
|
||||
// Add this to the imports database
|
||||
// @todo
|
||||
|
||||
return ImportDocument;
|
||||
}
|
||||
|
||||
function ParseImportInfo(importInfo: ImportProcessingInfo[]) {
|
||||
let scorePlaytypeMap: ScorePlaytypeMap = Object.create(null);
|
||||
@@ -33,65 +118,3 @@ function ParseImportInfo(importInfo: ImportProcessingInfo[]) {
|
||||
|
||||
return { scoreIDs, errors, scorePlaytypeMap };
|
||||
}
|
||||
|
||||
export default async function ScoreImportMain<D, C>(
|
||||
user: PublicUserDocument,
|
||||
importType: ImportTypes,
|
||||
InputParser: ImportInputParser<D, C>
|
||||
) {
|
||||
const timeStarted = Date.now();
|
||||
const { importID, logger } = CreateImportLoggerAndID(user, importType);
|
||||
|
||||
const { iterable, ConverterFunction, context, idStrings, game } = await InputParser(logger);
|
||||
|
||||
// @todo: scope logger properly
|
||||
logger.verbose("Received import request.");
|
||||
|
||||
let importInfo = await ImportAllIterableData(
|
||||
user.id,
|
||||
iterable,
|
||||
ConverterFunction,
|
||||
context,
|
||||
logger
|
||||
);
|
||||
|
||||
// Empty anything in the score queue
|
||||
let emptied = await InsertQueue();
|
||||
|
||||
if (emptied) {
|
||||
logger.verbose(`Emptied ${emptied} documents from score queue.`);
|
||||
}
|
||||
|
||||
let { scorePlaytypeMap, errors, scoreIDs } = ParseImportInfo(importInfo);
|
||||
|
||||
// Update user's rating information
|
||||
// @todo
|
||||
|
||||
let sessionInfo = await CreateSessions(user.id, importType, game, scorePlaytypeMap, logger);
|
||||
|
||||
// Create import document
|
||||
const ImportDocument: KTBlackImportDocument = {
|
||||
importType,
|
||||
idStrings: idStrings,
|
||||
scoreIDs,
|
||||
errors,
|
||||
importID,
|
||||
timeFinished: Date.now(),
|
||||
timeStarted,
|
||||
createdSessions: [], // @todo, see session ctor
|
||||
userID: user.id,
|
||||
};
|
||||
|
||||
logger.info(
|
||||
`Import took: ${ImportDocument.timeFinished - timeStarted}ms, with ${
|
||||
importInfo.length
|
||||
} documents (Fails: ${errors.length}, Successes: ${scoreIDs.length}). Aprx ${
|
||||
(ImportDocument.timeFinished - timeStarted) / importInfo.length
|
||||
}ms/doc`
|
||||
);
|
||||
|
||||
// Add this to the imports database
|
||||
// @todo
|
||||
|
||||
return ImportDocument;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user