@aoi-js/aka 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/calc/acm.d.ts +11 -0
- package/lib/calc/acm.js +178 -0
- package/lib/calc/acm.js.map +1 -0
- package/lib/calc/base.d.ts +15 -0
- package/lib/calc/base.js +11 -0
- package/lib/calc/base.js.map +1 -0
- package/lib/calc/basic.d.ts +8 -0
- package/lib/calc/basic.js +103 -0
- package/lib/calc/basic.js.map +1 -0
- package/lib/calc/index.d.ts +13 -0
- package/lib/calc/index.js +15 -0
- package/lib/calc/index.js.map +1 -0
- package/lib/calc/plus.d.ts +39 -0
- package/lib/calc/plus.js +329 -0
- package/lib/calc/plus.js.map +1 -0
- package/lib/client.d.ts +115 -0
- package/lib/client.js +57 -0
- package/lib/client.js.map +1 -0
- package/lib/db.d.ts +17 -0
- package/lib/db.js +16 -0
- package/lib/db.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +123 -0
- package/lib/index.js.map +1 -0
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +4 -0
- package/lib/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRanklist } from '../client.js';
|
|
2
|
+
import { IRanklistSyncOptions, RanklistCalculator } from './base.js';
|
|
3
|
+
export declare class AcmCalculator extends RanklistCalculator {
|
|
4
|
+
topstars: number;
|
|
5
|
+
warnings: string;
|
|
6
|
+
startTime: number;
|
|
7
|
+
loadConfig(dict: Record<string, string>): Promise<IRanklistSyncOptions>;
|
|
8
|
+
private _renderParticipantItemColumn;
|
|
9
|
+
private _renderPenaltyColumn;
|
|
10
|
+
calculate(contestId: string, taskId: string, key: string): Promise<IRanklist>;
|
|
11
|
+
}
|
package/lib/calc/acm.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { RanklistCalculator } from './base.js';
|
|
2
|
+
export class AcmCalculator extends RanklistCalculator {
|
|
3
|
+
topstars = 0;
|
|
4
|
+
warnings = '';
|
|
5
|
+
startTime = 0;
|
|
6
|
+
async loadConfig(dict) {
|
|
7
|
+
const topstars = +dict.topstars;
|
|
8
|
+
if (!Number.isInteger(topstars) || topstars < 0 || topstars > 20) {
|
|
9
|
+
this.warnings += 'topstars must be an integer between 0 and 20\n';
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.topstars = topstars;
|
|
13
|
+
}
|
|
14
|
+
const startTime = Date.parse(dict.startTime);
|
|
15
|
+
if (Number.isNaN(startTime)) {
|
|
16
|
+
this.warnings += 'startTime is not a valid timestamp\n';
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.startTime = startTime;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
shouldSyncParticipants: true,
|
|
23
|
+
shouldSyncSolutions: true
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
_renderParticipantItemColumn(score, solutionCount, lastSubmission) {
|
|
27
|
+
let html = '<div align=center>';
|
|
28
|
+
if (score) {
|
|
29
|
+
html += `<font color=green>+`;
|
|
30
|
+
if (solutionCount > 1) {
|
|
31
|
+
html += `${solutionCount - 1}`;
|
|
32
|
+
}
|
|
33
|
+
html += `</font><br><code>`;
|
|
34
|
+
const delay = Math.floor(Math.max(0, lastSubmission - this.startTime) / 1000 / 60);
|
|
35
|
+
const hours = Math.floor(delay / 60);
|
|
36
|
+
const minutes = delay % 60;
|
|
37
|
+
if (hours) {
|
|
38
|
+
html += `${hours}h`;
|
|
39
|
+
}
|
|
40
|
+
html += `${minutes}m</code>`;
|
|
41
|
+
}
|
|
42
|
+
else if (solutionCount) {
|
|
43
|
+
html += `<font color=red>-${solutionCount}</font>`;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
html += `<font color=gray>-</font>`;
|
|
47
|
+
}
|
|
48
|
+
html += '</div>';
|
|
49
|
+
return { content: html };
|
|
50
|
+
}
|
|
51
|
+
_renderPenaltyColumn(penalty) {
|
|
52
|
+
const format = () => {
|
|
53
|
+
let str = (penalty % 1000) + 'ms';
|
|
54
|
+
if (!(penalty = Math.floor(penalty / 1000)))
|
|
55
|
+
return str;
|
|
56
|
+
str = (penalty % 60) + 's' + str;
|
|
57
|
+
if (!(penalty = Math.floor(penalty / 60)))
|
|
58
|
+
return str;
|
|
59
|
+
str = (penalty % 60) + 'm' + str;
|
|
60
|
+
if (!(penalty = Math.floor(penalty / 60)))
|
|
61
|
+
return str;
|
|
62
|
+
return penalty + 'h' + str;
|
|
63
|
+
};
|
|
64
|
+
return { content: `\`${format()}\`` };
|
|
65
|
+
}
|
|
66
|
+
async calculate(contestId, taskId, key) {
|
|
67
|
+
const problems = await this.client.problems(contestId, taskId);
|
|
68
|
+
problems.sort((a, b) => a.settings.slug.localeCompare(b.settings.slug));
|
|
69
|
+
const problemIdList = problems.map((p) => p._id);
|
|
70
|
+
const problemScoreList = problems.map((p) => p.settings.score);
|
|
71
|
+
const participants = await this.db.participants.find({ contestId }).toArray();
|
|
72
|
+
let participantRecords = participants
|
|
73
|
+
.map(({ userId, tags, results }) => ({
|
|
74
|
+
userId,
|
|
75
|
+
tags,
|
|
76
|
+
scores: problemIdList
|
|
77
|
+
.map((pid) => results[pid]?.lastSolution.score ?? 0)
|
|
78
|
+
// In ACM, you will get score only if you get full points XD
|
|
79
|
+
.map((score, i) => ((score === 100 ? 100 : 0) * problemScoreList[i]) / 100),
|
|
80
|
+
lastSubmitTimestamps: problemIdList.map(() => 0),
|
|
81
|
+
solutionCounts: problemIdList.map(() => 0),
|
|
82
|
+
penalty: 0,
|
|
83
|
+
rank: 0
|
|
84
|
+
}))
|
|
85
|
+
.map((record) => ({
|
|
86
|
+
...record,
|
|
87
|
+
totalScore: record.scores.reduce((a, b) => a + b, 0)
|
|
88
|
+
}));
|
|
89
|
+
// Iterate over all solutons to calculate submit timestamps
|
|
90
|
+
const info = new Map();
|
|
91
|
+
const cursor = this.db.solutions.find({ contestId });
|
|
92
|
+
for await (const { userId, problemId, submittedAt } of cursor) {
|
|
93
|
+
const [userTimestamps, userSolutionCounts] = info.get(userId) ??
|
|
94
|
+
info.set(userId, [Object.create(null), Object.create(null)]).get(userId);
|
|
95
|
+
userTimestamps[problemId] = Math.max(userTimestamps[problemId] ?? 0, submittedAt);
|
|
96
|
+
userSolutionCounts[problemId] = (userSolutionCounts[problemId] ?? 0) + 1;
|
|
97
|
+
}
|
|
98
|
+
for (const record of participantRecords) {
|
|
99
|
+
const pair = info.get(record.userId);
|
|
100
|
+
if (!pair)
|
|
101
|
+
continue;
|
|
102
|
+
const [timestamps, solutionCounts] = pair;
|
|
103
|
+
for (let i = 0; i < problemIdList.length; ++i) {
|
|
104
|
+
const problemId = problemIdList[i];
|
|
105
|
+
record.lastSubmitTimestamps[i] = timestamps[problemId] ?? 0;
|
|
106
|
+
record.solutionCounts[i] = solutionCounts[problemId] ?? 0;
|
|
107
|
+
if (record.scores[i]) {
|
|
108
|
+
record.penalty += Math.max(0, timestamps[problemId] - this.startTime);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
participantRecords = participantRecords
|
|
113
|
+
.sort((a, b) => b.totalScore === a.totalScore ? a.penalty - b.penalty : b.totalScore - a.totalScore)
|
|
114
|
+
.map((record, index) => ({
|
|
115
|
+
...record,
|
|
116
|
+
rank: index + 1
|
|
117
|
+
}));
|
|
118
|
+
// Since we calculate penalty in milliseconds, we do not need to consider same rank
|
|
119
|
+
let topstar;
|
|
120
|
+
if (this.topstars) {
|
|
121
|
+
const topstarUserIdList = participantRecords
|
|
122
|
+
.slice(0, this.topstars)
|
|
123
|
+
.filter((record) => record.totalScore > 0)
|
|
124
|
+
.map((p) => p.userId);
|
|
125
|
+
topstar = {
|
|
126
|
+
list: await Promise.all(topstarUserIdList.map(async (userId) => {
|
|
127
|
+
const solutions = await this.db.solutions
|
|
128
|
+
.find({ contestId, userId })
|
|
129
|
+
.sort({ completedAt: 1 })
|
|
130
|
+
.toArray();
|
|
131
|
+
const currentScores = Object.create(null);
|
|
132
|
+
const mutations = [];
|
|
133
|
+
for (const { problemId, score, submittedAt } of solutions) {
|
|
134
|
+
currentScores[problemId] = score;
|
|
135
|
+
mutations.push({
|
|
136
|
+
score: problemIdList
|
|
137
|
+
.map((pid, i) => ((currentScores[pid] ?? 0) * problemScoreList[i]) / 100)
|
|
138
|
+
.reduce((a, b) => a + b, 0),
|
|
139
|
+
ts: submittedAt
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return { userId, mutations };
|
|
143
|
+
}))
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (this.warnings) {
|
|
147
|
+
this.logger.warn({ contestId, taskId, key }, this.warnings);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
topstar,
|
|
151
|
+
participant: {
|
|
152
|
+
list: participantRecords.map(({ userId, rank, tags, scores, totalScore, solutionCounts, lastSubmitTimestamps, penalty }) => ({
|
|
153
|
+
userId,
|
|
154
|
+
rank,
|
|
155
|
+
tags,
|
|
156
|
+
columns: [
|
|
157
|
+
...scores.map((score, i) => this._renderParticipantItemColumn(score, solutionCounts[i], lastSubmitTimestamps[i])),
|
|
158
|
+
{ content: `${totalScore}` },
|
|
159
|
+
this._renderPenaltyColumn(penalty)
|
|
160
|
+
]
|
|
161
|
+
})),
|
|
162
|
+
columns: [
|
|
163
|
+
...problems.map(({ title, settings: { slug } }) => ({
|
|
164
|
+
name: slug,
|
|
165
|
+
description: title
|
|
166
|
+
})),
|
|
167
|
+
{ name: 'Total', description: 'Total Score' },
|
|
168
|
+
{ name: 'Penalty', description: 'Penalty Time' }
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
metadata: {
|
|
172
|
+
generatedAt: Date.now(),
|
|
173
|
+
description: 'ACM ranklist generated'
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=acm.js.map
|
|
@@ -0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qBACnB,CAAsC,CAC1C;oBACD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE;oBAC7C,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE;iBACjD;aACF;YACD,QAAQ,EAAE;gBACR,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;gBACvB,WAAW,EAAE,wBAAwB;aACtC;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { AkaClient, IRanklist } from '../client.js';
|
|
3
|
+
import { AkaDb } from '../db.js';
|
|
4
|
+
export interface IRanklistSyncOptions {
|
|
5
|
+
shouldSyncSolutions?: boolean;
|
|
6
|
+
shouldSyncParticipants?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class RanklistCalculator {
|
|
9
|
+
protected db: AkaDb;
|
|
10
|
+
protected client: AkaClient;
|
|
11
|
+
protected logger: Logger;
|
|
12
|
+
constructor(db: AkaDb, client: AkaClient, logger: Logger);
|
|
13
|
+
abstract loadConfig(dict: Record<string, string>): Promise<IRanklistSyncOptions>;
|
|
14
|
+
abstract calculate(contestId: string, taskId: string, key: string): Promise<IRanklist>;
|
|
15
|
+
}
|
package/lib/calc/base.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/calc/base.ts"],"names":[],"mappings":"AASA,MAAM,OAAgB,kBAAkB;IAE1B;IACA;IACA;IAHZ,YACY,EAAS,EACT,MAAiB,EACjB,MAAc;QAFd,OAAE,GAAF,EAAE,CAAO;QACT,WAAM,GAAN,MAAM,CAAW;QACjB,WAAM,GAAN,MAAM,CAAQ;IACvB,CAAC;CAIL"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IRanklist } from '../client.js';
|
|
2
|
+
import { IRanklistSyncOptions, RanklistCalculator } from './base.js';
|
|
3
|
+
export declare class BasicCalculator extends RanklistCalculator {
|
|
4
|
+
topstars: number;
|
|
5
|
+
warnings: string;
|
|
6
|
+
loadConfig(dict: Record<string, string>): Promise<IRanklistSyncOptions>;
|
|
7
|
+
calculate(contestId: string, taskId: string, key: string): Promise<IRanklist>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { RanklistCalculator } from './base.js';
|
|
2
|
+
export class BasicCalculator extends RanklistCalculator {
|
|
3
|
+
topstars = 0;
|
|
4
|
+
warnings = '';
|
|
5
|
+
async loadConfig(dict) {
|
|
6
|
+
const topstars = +dict.topstars;
|
|
7
|
+
if (!Number.isInteger(topstars) || topstars < 0 || topstars > 20) {
|
|
8
|
+
this.warnings += 'topstars must be an integer between 0 and 20\n';
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
this.topstars = topstars;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
shouldSyncParticipants: true,
|
|
15
|
+
shouldSyncSolutions: !!this.topstars
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async calculate(contestId, taskId, key) {
|
|
19
|
+
const problems = await this.client.problems(contestId, taskId);
|
|
20
|
+
problems.sort((a, b) => a.settings.slug.localeCompare(b.settings.slug));
|
|
21
|
+
const problemIdList = problems.map((p) => p._id);
|
|
22
|
+
const problemScoreList = problems.map((p) => p.settings.score);
|
|
23
|
+
const participants = await this.db.participants.find({ contestId }).toArray();
|
|
24
|
+
const participantRecords = participants
|
|
25
|
+
.map(({ userId, tags, results }) => ({
|
|
26
|
+
userId,
|
|
27
|
+
tags,
|
|
28
|
+
scores: problemIdList
|
|
29
|
+
.map((pid) => results[pid]?.lastSolution.score ?? 0)
|
|
30
|
+
.map((score, i) => (score * problemScoreList[i]) / 100)
|
|
31
|
+
}))
|
|
32
|
+
.map((record) => ({
|
|
33
|
+
...record,
|
|
34
|
+
totalScore: record.scores.reduce((a, b) => a + b, 0)
|
|
35
|
+
}))
|
|
36
|
+
.sort((a, b) => b.totalScore - a.totalScore)
|
|
37
|
+
.map((record, index) => ({
|
|
38
|
+
...record,
|
|
39
|
+
rank: index + 1
|
|
40
|
+
}));
|
|
41
|
+
participantRecords.forEach((record, index, arr) => {
|
|
42
|
+
if (index > 0 && record.totalScore === arr[index - 1].totalScore) {
|
|
43
|
+
record.rank = arr[index - 1].rank;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
let topstar;
|
|
47
|
+
if (this.topstars) {
|
|
48
|
+
const topstarUserIdList = participantRecords
|
|
49
|
+
.slice(0, this.topstars)
|
|
50
|
+
.filter((record) => record.totalScore > 0)
|
|
51
|
+
.map((p) => p.userId);
|
|
52
|
+
topstar = {
|
|
53
|
+
list: await Promise.all(topstarUserIdList.map(async (userId) => {
|
|
54
|
+
const solutions = await this.db.solutions
|
|
55
|
+
.find({ contestId, userId })
|
|
56
|
+
.sort({ completedAt: 1 })
|
|
57
|
+
.toArray();
|
|
58
|
+
const currentScores = Object.create(null);
|
|
59
|
+
const mutations = [];
|
|
60
|
+
for (const { problemId, score, submittedAt } of solutions) {
|
|
61
|
+
currentScores[problemId] = score;
|
|
62
|
+
mutations.push({
|
|
63
|
+
score: problemIdList
|
|
64
|
+
.map((pid, i) => ((currentScores[pid] ?? 0) * problemScoreList[i]) / 100)
|
|
65
|
+
.reduce((a, b) => a + b, 0),
|
|
66
|
+
ts: submittedAt
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { userId, mutations };
|
|
70
|
+
}))
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (this.warnings) {
|
|
74
|
+
this.logger.warn({ contestId, taskId, key }, this.warnings);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
topstar,
|
|
78
|
+
participant: {
|
|
79
|
+
list: participantRecords.map(({ userId, rank, tags, scores, totalScore }) => ({
|
|
80
|
+
userId,
|
|
81
|
+
rank,
|
|
82
|
+
tags,
|
|
83
|
+
columns: [
|
|
84
|
+
...scores.map((score) => ({ content: `${score}` })),
|
|
85
|
+
{ content: `${totalScore}` }
|
|
86
|
+
]
|
|
87
|
+
})),
|
|
88
|
+
columns: [
|
|
89
|
+
...problems.map(({ title, settings: { slug } }) => ({
|
|
90
|
+
name: slug,
|
|
91
|
+
description: title
|
|
92
|
+
})),
|
|
93
|
+
{ name: 'Total', description: 'Total Score' }
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
metadata: {
|
|
97
|
+
generatedAt: Date.now(),
|
|
98
|
+
description: 'Basic ranklist generated'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=basic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic.js","sourceRoot":"","sources":["../../src/calc/basic.ts"],"names":[],"mappings":"AAQA,OAAO,EAAwB,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEpE,MAAM,OAAO,eAAgB,SAAQ,kBAAkB;IACrD,QAAQ,GAAG,CAAC,CAAA;IACZ,QAAQ,GAAG,EAAE,CAAA;IAEJ,KAAK,CAAC,UAAU,CAAC,IAA4B;QACpD,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAA;QAC/B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;YACjE,IAAI,CAAC,QAAQ,IAAI,gDAAgD,CAAA;QACnE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC1B,CAAC;QAED,OAAO;YACL,sBAAsB,EAAE,IAAI;YAC5B,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;SACrC,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,SAAS,CAAC,SAAiB,EAAE,MAAc,EAAE,GAAW;QACrE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,M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KAAK,EAAE,EAAE,CAA0C,CAC9E;wBACD,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,EAAE;qBAC7B;iBACF,CAAoC,CACxC;gBACD,OAAO,EAAE;oBACP,GAAG,QAAQ,CAAC,GAAG,CACb,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;wBACC,IAAI,EAAE,IAAI;wBACV,WAAW,EAAE,KAAK;qBACnB,CAAsC,CAC1C;oBACD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE;iBAC9C;aACF;YACD,QAAQ,EAAE;gBACR,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;gBACvB,WAAW,EAAE,0BAA0B;aACxC;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { AkaClient } from '../client.js';
|
|
3
|
+
import { AkaDb } from '../db.js';
|
|
4
|
+
import { RanklistCalculator } from './base.js';
|
|
5
|
+
import { BasicCalculator } from './basic.js';
|
|
6
|
+
import { PlusCalculator } from './plus.js';
|
|
7
|
+
import { AcmCalculator } from './acm.js';
|
|
8
|
+
export declare const calculators: {
|
|
9
|
+
basic: typeof BasicCalculator;
|
|
10
|
+
plus: typeof PlusCalculator;
|
|
11
|
+
acm: typeof AcmCalculator;
|
|
12
|
+
};
|
|
13
|
+
export declare function getCalculator(db: AkaDb, client: AkaClient, logger: Logger, dict: Record<string, string>): RanklistCalculator | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BasicCalculator } from './basic.js';
|
|
2
|
+
import { PlusCalculator } from './plus.js';
|
|
3
|
+
import { AcmCalculator } from './acm.js';
|
|
4
|
+
export const calculators = {
|
|
5
|
+
basic: BasicCalculator,
|
|
6
|
+
plus: PlusCalculator,
|
|
7
|
+
acm: AcmCalculator
|
|
8
|
+
};
|
|
9
|
+
export function getCalculator(db, client, logger, dict) {
|
|
10
|
+
const type = dict.type ?? 'basic';
|
|
11
|
+
if (!Object.hasOwn(calculators, type))
|
|
12
|
+
return null;
|
|
13
|
+
return new calculators[type](db, client, logger);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calc/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,eAAe;IACtB,IAAI,EAAE,cAAc;IACpB,GAAG,EAAE,aAAa;CACnB,CAAA;AAED,MAAM,UAAU,aAAa,CAC3B,EAAS,EACT,MAAiB,EACjB,MAAc,EACd,IAA4B;IAE5B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAA;IACjC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAClD,OAAO,IAAI,WAAW,CAAC,IAAgC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAC9E,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IRanklist } from '../client.js';
|
|
2
|
+
import { IRanklistSyncOptions, RanklistCalculator } from './base.js';
|
|
3
|
+
declare const reduceMethods: readonly ["override", "max", "min"];
|
|
4
|
+
type ReduceMethod = (typeof reduceMethods)[number];
|
|
5
|
+
declare const totalReduceMethods: readonly ["sum", "max", "min"];
|
|
6
|
+
type TotalReduceMethod = (typeof totalReduceMethods)[number];
|
|
7
|
+
export declare class PlusCalculator extends RanklistCalculator {
|
|
8
|
+
topstars: number;
|
|
9
|
+
warnings: string;
|
|
10
|
+
participantTagWhitelist?: string[];
|
|
11
|
+
participantTagBlacklist?: string[];
|
|
12
|
+
problemTagWhitelist?: string[];
|
|
13
|
+
problemTagBlacklist?: string[];
|
|
14
|
+
problemSlugFilter?: RegExp;
|
|
15
|
+
problemTitleFilter?: RegExp;
|
|
16
|
+
scoreReduceMethod: ReduceMethod;
|
|
17
|
+
totalReduceMethod: TotalReduceMethod;
|
|
18
|
+
private _reduceScore;
|
|
19
|
+
private _reduceTotal;
|
|
20
|
+
showOriginalScore: boolean;
|
|
21
|
+
showProblemScore: boolean;
|
|
22
|
+
showLastSubmission: boolean;
|
|
23
|
+
sameRankForSameScore: boolean;
|
|
24
|
+
loadConfig(dict: Record<string, string>): Promise<IRanklistSyncOptions>;
|
|
25
|
+
private _loadRenderConfig;
|
|
26
|
+
private _loadTotalReduceConfig;
|
|
27
|
+
private _loadScoreReduceConfig;
|
|
28
|
+
private _loadFilterConfig;
|
|
29
|
+
private _getProblems;
|
|
30
|
+
private _getParticipants;
|
|
31
|
+
private _renderParticipantItemColumn;
|
|
32
|
+
private _formatDate;
|
|
33
|
+
private _renderDate;
|
|
34
|
+
calculate(contestId: string, taskId: string, key: string): Promise<IRanklist>;
|
|
35
|
+
private _calculateTopstars;
|
|
36
|
+
private _calculateScores;
|
|
37
|
+
private _calculateLastSubmission;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
package/lib/calc/plus.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { RanklistCalculator } from './base.js';
|
|
2
|
+
const reduceMethods = ['override', 'max', 'min'];
|
|
3
|
+
const totalReduceMethods = ['sum', 'max', 'min'];
|
|
4
|
+
export class PlusCalculator extends RanklistCalculator {
|
|
5
|
+
topstars = 0;
|
|
6
|
+
warnings = '';
|
|
7
|
+
participantTagWhitelist;
|
|
8
|
+
participantTagBlacklist;
|
|
9
|
+
problemTagWhitelist;
|
|
10
|
+
problemTagBlacklist;
|
|
11
|
+
problemSlugFilter;
|
|
12
|
+
problemTitleFilter;
|
|
13
|
+
scoreReduceMethod = 'override';
|
|
14
|
+
totalReduceMethod = 'sum';
|
|
15
|
+
_reduceScore = (a, b) => b;
|
|
16
|
+
_reduceTotal = (a, b) => a + b;
|
|
17
|
+
showOriginalScore = false;
|
|
18
|
+
showProblemScore = false;
|
|
19
|
+
showLastSubmission = false;
|
|
20
|
+
sameRankForSameScore = false;
|
|
21
|
+
async loadConfig(dict) {
|
|
22
|
+
const topstars = +dict.topstars;
|
|
23
|
+
if (!Number.isInteger(topstars) || topstars < 0 || topstars > 20) {
|
|
24
|
+
this.warnings += 'topstars must be an integer between 0 and 20\n';
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.topstars = topstars;
|
|
28
|
+
}
|
|
29
|
+
this._loadFilterConfig(dict);
|
|
30
|
+
this._loadScoreReduceConfig(dict);
|
|
31
|
+
this._loadTotalReduceConfig(dict);
|
|
32
|
+
this._loadRenderConfig(dict);
|
|
33
|
+
return {
|
|
34
|
+
shouldSyncParticipants: true,
|
|
35
|
+
shouldSyncSolutions: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
_loadRenderConfig(dict) {
|
|
39
|
+
if (dict.showOriginalScore) {
|
|
40
|
+
this.showOriginalScore = !!+dict.showOriginalScore;
|
|
41
|
+
}
|
|
42
|
+
if (dict.showProblemScore) {
|
|
43
|
+
this.showProblemScore = !!+dict.showProblemScore;
|
|
44
|
+
}
|
|
45
|
+
if (dict.showLastSubmission) {
|
|
46
|
+
this.showLastSubmission = !!+dict.showLastSubmission;
|
|
47
|
+
}
|
|
48
|
+
if (dict.sameRankForSameScore) {
|
|
49
|
+
this.sameRankForSameScore = !!+dict.sameRankForSameScore;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_loadTotalReduceConfig(dict) {
|
|
53
|
+
if (dict.totalReduceMethod) {
|
|
54
|
+
if (totalReduceMethods.includes(dict.totalReduceMethod)) {
|
|
55
|
+
this.totalReduceMethod = dict.totalReduceMethod;
|
|
56
|
+
switch (this.totalReduceMethod) {
|
|
57
|
+
case 'sum':
|
|
58
|
+
this._reduceTotal = (a, b) => a + b;
|
|
59
|
+
break;
|
|
60
|
+
case 'max':
|
|
61
|
+
this._reduceTotal = Math.max;
|
|
62
|
+
break;
|
|
63
|
+
case 'min':
|
|
64
|
+
this._reduceTotal = Math.min;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.warnings += `totalReduceMethod must be one of ${totalReduceMethods.join(', ')}\n`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
_loadScoreReduceConfig(dict) {
|
|
74
|
+
if (dict.scoreReduceMethod) {
|
|
75
|
+
if (reduceMethods.includes(dict.scoreReduceMethod)) {
|
|
76
|
+
this.scoreReduceMethod = dict.scoreReduceMethod;
|
|
77
|
+
switch (this.scoreReduceMethod) {
|
|
78
|
+
case 'override':
|
|
79
|
+
this._reduceScore = (a, b) => b;
|
|
80
|
+
break;
|
|
81
|
+
case 'max':
|
|
82
|
+
this._reduceScore = Math.max;
|
|
83
|
+
break;
|
|
84
|
+
case 'min':
|
|
85
|
+
this._reduceScore = Math.min;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.warnings += `scoreReduceMethod must be one of ${reduceMethods.join(', ')}\n`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_loadFilterConfig(dict) {
|
|
95
|
+
if (dict.participantTagWhitelist) {
|
|
96
|
+
this.participantTagWhitelist = dict.participantTagWhitelist.split(',');
|
|
97
|
+
}
|
|
98
|
+
if (dict.participantTagBlacklist) {
|
|
99
|
+
this.participantTagBlacklist = dict.participantTagBlacklist.split(',');
|
|
100
|
+
}
|
|
101
|
+
if (dict.problemTagWhitelist) {
|
|
102
|
+
this.problemTagWhitelist = dict.problemTagWhitelist.split(',');
|
|
103
|
+
}
|
|
104
|
+
if (dict.problemTagBlacklist) {
|
|
105
|
+
this.problemTagBlacklist = dict.problemTagBlacklist.split(',');
|
|
106
|
+
}
|
|
107
|
+
if (dict.problemSlugFilter) {
|
|
108
|
+
this.problemSlugFilter = new RegExp(dict.problemSlugFilter);
|
|
109
|
+
}
|
|
110
|
+
if (dict.problemTitleFilter) {
|
|
111
|
+
this.problemTitleFilter = new RegExp(dict.problemTitleFilter);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async _getProblems(contestId, taskId) {
|
|
115
|
+
let problems = await this.client.problems(contestId, taskId);
|
|
116
|
+
const { problemTagWhitelist, problemTagBlacklist, problemSlugFilter, problemTitleFilter } = this;
|
|
117
|
+
if (problemTagWhitelist) {
|
|
118
|
+
problems = problems.filter((p) => p.tags.some((t) => problemTagWhitelist.includes(t)));
|
|
119
|
+
}
|
|
120
|
+
if (problemTagBlacklist) {
|
|
121
|
+
problems = problems.filter((p) => !p.tags.some((t) => problemTagBlacklist.includes(t)));
|
|
122
|
+
}
|
|
123
|
+
if (problemSlugFilter) {
|
|
124
|
+
problems = problems.filter((p) => problemSlugFilter.test(p.settings.slug));
|
|
125
|
+
}
|
|
126
|
+
if (problemTitleFilter) {
|
|
127
|
+
problems = problems.filter((p) => problemTitleFilter.test(p.title));
|
|
128
|
+
}
|
|
129
|
+
return problems;
|
|
130
|
+
}
|
|
131
|
+
async _getParticipants(contestId) {
|
|
132
|
+
let participants = await this.db.participants.find({ contestId }).toArray();
|
|
133
|
+
const { participantTagWhitelist, participantTagBlacklist } = this;
|
|
134
|
+
if (participantTagWhitelist) {
|
|
135
|
+
participants = participants.filter((p) => p.tags && p.tags.some((t) => participantTagWhitelist.includes(t)));
|
|
136
|
+
}
|
|
137
|
+
if (participantTagBlacklist) {
|
|
138
|
+
participants = participants.filter((p) => !p.tags || !p.tags.some((t) => participantTagBlacklist.includes(t)));
|
|
139
|
+
}
|
|
140
|
+
return participants;
|
|
141
|
+
}
|
|
142
|
+
_renderParticipantItemColumn(score, problemScore) {
|
|
143
|
+
if (this.showProblemScore)
|
|
144
|
+
return { content: `\`${score}/${problemScore}\`` };
|
|
145
|
+
return { content: `${score}` };
|
|
146
|
+
}
|
|
147
|
+
_formatDate(ts) {
|
|
148
|
+
const date = new Date(ts);
|
|
149
|
+
const iso = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString();
|
|
150
|
+
return iso.replace(/-/g, '').replace('T', ' ').slice(0, -1);
|
|
151
|
+
}
|
|
152
|
+
_renderDate(ts) {
|
|
153
|
+
return `\`${this._formatDate(ts)}\``;
|
|
154
|
+
}
|
|
155
|
+
async calculate(contestId, taskId, key) {
|
|
156
|
+
const logger = this.logger.child({ contestId, taskId, key });
|
|
157
|
+
logger.info('Start to calculate ranklist');
|
|
158
|
+
const problems = await this._getProblems(contestId, taskId);
|
|
159
|
+
problems.sort((a, b) => a.settings.slug.localeCompare(b.settings.slug));
|
|
160
|
+
const problemIdList = problems.map((p) => p._id);
|
|
161
|
+
const problemScoreList = problems.map((p) => p.settings.score);
|
|
162
|
+
const participants = await this._getParticipants(contestId);
|
|
163
|
+
const participantsWithScores = participants.map(({ userId, tags, results }) => ({
|
|
164
|
+
userId,
|
|
165
|
+
tags,
|
|
166
|
+
scores: problemIdList.map((pid) => results[pid]?.lastSolution.score ?? 0),
|
|
167
|
+
lastSubmission: 0
|
|
168
|
+
}));
|
|
169
|
+
logger.info(`Loaded ${problems.length} problems and ${participants.length} participants`);
|
|
170
|
+
if (this.topstars || !this.sameRankForSameScore || this.showLastSubmission) {
|
|
171
|
+
// Calculate lastSubmission
|
|
172
|
+
await this._calculateLastSubmission(logger, contestId, problemIdList, participantsWithScores);
|
|
173
|
+
}
|
|
174
|
+
if (this.scoreReduceMethod !== 'override') {
|
|
175
|
+
// We need to manually calculate the scores
|
|
176
|
+
await this._calculateScores(logger, contestId, problemIdList, participantsWithScores);
|
|
177
|
+
}
|
|
178
|
+
if (!this.showOriginalScore) {
|
|
179
|
+
for (const participant of participantsWithScores) {
|
|
180
|
+
participant.scores = participant.scores.map((score, i) => (score * problemScoreList[i]) / 100);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const participantRecords = participantsWithScores
|
|
184
|
+
.map((record) => ({
|
|
185
|
+
...record,
|
|
186
|
+
totalScore: (this.showOriginalScore
|
|
187
|
+
? record.scores.map((score, i) => (score * problemScoreList[i]) / 100)
|
|
188
|
+
: record.scores).reduce((a, b) => this._reduceTotal(a, b), 0)
|
|
189
|
+
}))
|
|
190
|
+
.sort((a, b) =>
|
|
191
|
+
// First sort by totalScore DESC, then by updatedAt ASC
|
|
192
|
+
b.totalScore === a.totalScore
|
|
193
|
+
? a.lastSubmission - b.lastSubmission
|
|
194
|
+
: b.totalScore - a.totalScore)
|
|
195
|
+
.map((record, index) => ({
|
|
196
|
+
...record,
|
|
197
|
+
rank: index + 1
|
|
198
|
+
}));
|
|
199
|
+
if (this.sameRankForSameScore) {
|
|
200
|
+
participantRecords.forEach((record, index, arr) => {
|
|
201
|
+
if (index > 0 && record.totalScore === arr[index - 1].totalScore) {
|
|
202
|
+
record.rank = arr[index - 1].rank;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
let topstar;
|
|
207
|
+
if (this.topstars) {
|
|
208
|
+
topstar = await this._calculateTopstars(logger, participantRecords, contestId, problemIdList, problemScoreList);
|
|
209
|
+
}
|
|
210
|
+
const now = performance.now();
|
|
211
|
+
logger.info(`Start to generate ranklist object`);
|
|
212
|
+
let description = 'Ranklist generated with type `plus`\n';
|
|
213
|
+
if (this.warnings) {
|
|
214
|
+
this.logger.warn({ contestId, taskId, key }, `Generated with warnings:\n${this.warnings}`);
|
|
215
|
+
description += `Warnings:\n\`\`\`\n${this.warnings}\`\`\``;
|
|
216
|
+
}
|
|
217
|
+
const problemTotalScore = problemScoreList.reduce((a, b) => this._reduceTotal(a, b), 0);
|
|
218
|
+
const ranklist = {
|
|
219
|
+
topstar,
|
|
220
|
+
participant: {
|
|
221
|
+
list: participantRecords.map(({ userId, rank, tags, scores, totalScore, lastSubmission }) => ({
|
|
222
|
+
userId,
|
|
223
|
+
rank,
|
|
224
|
+
tags,
|
|
225
|
+
columns: [
|
|
226
|
+
...scores.map((score, i) => this._renderParticipantItemColumn(score, this.showOriginalScore ? 100 : problemScoreList[i])),
|
|
227
|
+
this._renderParticipantItemColumn(totalScore, problemTotalScore),
|
|
228
|
+
...(this.showLastSubmission ? [{ content: this._renderDate(lastSubmission) }] : [])
|
|
229
|
+
]
|
|
230
|
+
})),
|
|
231
|
+
columns: [
|
|
232
|
+
...problems.map(({ title, settings: { slug } }) => ({
|
|
233
|
+
name: slug,
|
|
234
|
+
description: title
|
|
235
|
+
})),
|
|
236
|
+
{ name: 'Total', description: 'Total Score' },
|
|
237
|
+
...(this.showLastSubmission
|
|
238
|
+
? [{ name: 'Last Submit', description: 'Last Submission Time' }]
|
|
239
|
+
: [])
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
metadata: {
|
|
243
|
+
generatedAt: Date.now(),
|
|
244
|
+
description
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
logger.info(`Generated ranklist object in ${performance.now() - now}ms`);
|
|
248
|
+
return ranklist;
|
|
249
|
+
}
|
|
250
|
+
async _calculateTopstars(logger, participantRecords, contestId, problemIdList, problemScoreList) {
|
|
251
|
+
const now = Date.now();
|
|
252
|
+
logger.info('Calculating topstars');
|
|
253
|
+
const topstarUserIdList = participantRecords
|
|
254
|
+
.slice(0, this.topstars)
|
|
255
|
+
.filter((record) => record.totalScore > 0)
|
|
256
|
+
.map((p) => p.userId);
|
|
257
|
+
const topstar = {
|
|
258
|
+
list: await Promise.all(topstarUserIdList.map(async (userId) => {
|
|
259
|
+
const solutions = await this.db.solutions
|
|
260
|
+
.find({ contestId, userId, problemId: { $in: problemIdList } })
|
|
261
|
+
.sort({ completedAt: 1 })
|
|
262
|
+
.toArray();
|
|
263
|
+
const currentScores = Object.create(null);
|
|
264
|
+
const mutations = [];
|
|
265
|
+
for (const { problemId, score, submittedAt } of solutions) {
|
|
266
|
+
if (Object.hasOwn(currentScores, problemId)) {
|
|
267
|
+
currentScores[problemId] = this._reduceScore(currentScores[problemId], score);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
currentScores[problemId] = score;
|
|
271
|
+
}
|
|
272
|
+
mutations.push({
|
|
273
|
+
score: problemIdList
|
|
274
|
+
.map((pid, i) => ((currentScores[pid] ?? 0) * problemScoreList[i]) / 100)
|
|
275
|
+
.reduce((a, b) => this._reduceTotal(a, b), 0),
|
|
276
|
+
ts: submittedAt
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return { userId, mutations };
|
|
280
|
+
}))
|
|
281
|
+
};
|
|
282
|
+
logger.info(`Calculated topstars in ${Date.now() - now}ms`);
|
|
283
|
+
return topstar;
|
|
284
|
+
}
|
|
285
|
+
async _calculateScores(logger, contestId, problemIdList, participantsWithScores) {
|
|
286
|
+
logger.info('Calculating scores');
|
|
287
|
+
const start = performance.now();
|
|
288
|
+
const scores = new Map();
|
|
289
|
+
const cursor = this.db.solutions.find({ contestId, problemId: { $in: problemIdList } });
|
|
290
|
+
for await (const solution of cursor) {
|
|
291
|
+
const { userId, problemId, score } = solution;
|
|
292
|
+
if (!scores.has(userId)) {
|
|
293
|
+
scores.set(userId, Object.create(null));
|
|
294
|
+
}
|
|
295
|
+
const userScores = scores.get(userId);
|
|
296
|
+
if (Object.hasOwn(userScores, problemId)) {
|
|
297
|
+
userScores[problemId] = this._reduceScore(userScores[problemId], score);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
userScores[problemId] = score;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
for (const participant of participantsWithScores) {
|
|
304
|
+
const userScores = scores.get(participant.userId) ?? Object.create(null);
|
|
305
|
+
participant.scores = problemIdList.map((pid) => userScores[pid] ?? 0);
|
|
306
|
+
}
|
|
307
|
+
logger.info(`Calculated scores in ${performance.now() - start}ms`);
|
|
308
|
+
}
|
|
309
|
+
async _calculateLastSubmission(logger, contestId, problemIdList, participantsWithScores) {
|
|
310
|
+
logger.info('Calculating lastSubmission');
|
|
311
|
+
const start = performance.now();
|
|
312
|
+
const lastSubmissions = new Map();
|
|
313
|
+
const cursor = this.db.solutions.find({ contestId, problemId: { $in: problemIdList } });
|
|
314
|
+
for await (const solution of cursor) {
|
|
315
|
+
const { userId, submittedAt } = solution;
|
|
316
|
+
if (lastSubmissions.has(userId)) {
|
|
317
|
+
lastSubmissions.set(userId, Math.max(lastSubmissions.get(userId), submittedAt));
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
lastSubmissions.set(userId, submittedAt);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
for (const participant of participantsWithScores) {
|
|
324
|
+
participant.lastSubmission = lastSubmissions.get(participant.userId) ?? 0;
|
|
325
|
+
}
|
|
326
|
+
logger.info(`Calculated lastSubmission in ${performance.now() - start}ms`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=plus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plus.js","sourceRoot":"","sources":["../../src/calc/plus.ts"],"names":[],"mappings":"AASA,OAAO,EAAwB,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEpE,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAGzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAGzD,MAAM,OAAO,cAAe,SAAQ,kBAAkB;IACpD,QAAQ,GAAG,CAAC,CAAA;IACZ,QAAQ,GAAG,EAAE,CAAA;IACb,uBAAuB,CAAW;IAClC,uBAAuB,CAAW;IAClC,mBAAmB,CAAW;IAC9B,mBAAmB,CAAW;IAC9B,iBAAiB,CAAS;IAC1B,kBAAkB,CAAS;IAC3B,iBAAiB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C;gBACN,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC;QACD,KAAK,MAAM,WAAW,IAAI,sBAAsB,EAAE,CAAC;YACjD,WAAW,CAAC,cAAc,GAAG,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3E,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,gCAAgC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,CAAA;IAC5E,CAAC;CACF"}
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type KyInstance } from 'ky';
|
|
2
|
+
export interface IAkaClientConfig {
|
|
3
|
+
server: string;
|
|
4
|
+
runnerId: string;
|
|
5
|
+
runnerKey: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IParticipant {
|
|
8
|
+
_id: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
contestId: string;
|
|
11
|
+
tags?: string[];
|
|
12
|
+
results: Record<string, {
|
|
13
|
+
solutionCount: number;
|
|
14
|
+
lastSolutionId: string;
|
|
15
|
+
lastSolution: {
|
|
16
|
+
score: number;
|
|
17
|
+
status: string;
|
|
18
|
+
completedAt: number;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
updatedAt: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ISolution {
|
|
24
|
+
_id: string;
|
|
25
|
+
problemId: string;
|
|
26
|
+
userId: string;
|
|
27
|
+
label: string;
|
|
28
|
+
problemDataHash: string;
|
|
29
|
+
state: number;
|
|
30
|
+
solutionDataHash: string;
|
|
31
|
+
score: number;
|
|
32
|
+
metrics: Record<string, number>;
|
|
33
|
+
status: string;
|
|
34
|
+
message: string;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
submittedAt: number;
|
|
37
|
+
completedAt: number;
|
|
38
|
+
}
|
|
39
|
+
export interface IRanklistTopstarItemMutation {
|
|
40
|
+
score: number;
|
|
41
|
+
ts: number;
|
|
42
|
+
}
|
|
43
|
+
export interface IRanklistTopstarItem {
|
|
44
|
+
userId: string;
|
|
45
|
+
mutations: IRanklistTopstarItemMutation[];
|
|
46
|
+
}
|
|
47
|
+
export interface IRanklistTopstar {
|
|
48
|
+
list: IRanklistTopstarItem[];
|
|
49
|
+
}
|
|
50
|
+
export interface IRanklistParticipantColumn {
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
}
|
|
54
|
+
export interface IRanklistParticipantItemColumn {
|
|
55
|
+
content: string;
|
|
56
|
+
}
|
|
57
|
+
export interface IRanklistParticipantItem {
|
|
58
|
+
rank: number;
|
|
59
|
+
userId: string;
|
|
60
|
+
tags?: string[];
|
|
61
|
+
columns: IRanklistParticipantItemColumn[];
|
|
62
|
+
}
|
|
63
|
+
export interface IRanklistParticipant {
|
|
64
|
+
columns: IRanklistParticipantColumn[];
|
|
65
|
+
list: IRanklistParticipantItem[];
|
|
66
|
+
}
|
|
67
|
+
export interface IRanklistMetadata {
|
|
68
|
+
generatedAt: number;
|
|
69
|
+
description: string;
|
|
70
|
+
}
|
|
71
|
+
export interface IRanklist {
|
|
72
|
+
topstar?: IRanklistTopstar;
|
|
73
|
+
participant: IRanklistParticipant;
|
|
74
|
+
metadata: IRanklistMetadata;
|
|
75
|
+
}
|
|
76
|
+
export declare class AkaClient {
|
|
77
|
+
private config;
|
|
78
|
+
http: KyInstance;
|
|
79
|
+
constructor(config: IAkaClientConfig);
|
|
80
|
+
poll(): Promise<{
|
|
81
|
+
taskId: string;
|
|
82
|
+
contestId: string;
|
|
83
|
+
ranklists: Array<{
|
|
84
|
+
key: string;
|
|
85
|
+
name: string;
|
|
86
|
+
settings: {
|
|
87
|
+
showAfter?: number;
|
|
88
|
+
showBefore?: number;
|
|
89
|
+
config?: string;
|
|
90
|
+
};
|
|
91
|
+
}>;
|
|
92
|
+
ranklistUpdatedAt: number;
|
|
93
|
+
}>;
|
|
94
|
+
complete(contestId: string, taskId: string, payload: {
|
|
95
|
+
ranklistUpdatedAt: number;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
problems(contestId: string, taskId: string): Promise<{
|
|
98
|
+
_id: string;
|
|
99
|
+
title: string;
|
|
100
|
+
tags: string[];
|
|
101
|
+
settings: {
|
|
102
|
+
score: number;
|
|
103
|
+
slug: string;
|
|
104
|
+
solutionCountLimit: number;
|
|
105
|
+
showAfter?: number;
|
|
106
|
+
};
|
|
107
|
+
}[]>;
|
|
108
|
+
participants(contestId: string, taskId: string, since: number, lastId: string): Promise<IParticipant[]>;
|
|
109
|
+
solutions(contestId: string, taskId: string, since: number, lastId: string): Promise<ISolution[]>;
|
|
110
|
+
uploadUrls(contestId: string, taskId: string): Promise<{
|
|
111
|
+
key: string;
|
|
112
|
+
url: string;
|
|
113
|
+
}[]>;
|
|
114
|
+
uploadRanklist(url: string, ranklist: IRanklist): Promise<import("ky").KyResponse>;
|
|
115
|
+
}
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import ky from 'ky';
|
|
2
|
+
import metadata from '../package.json' assert { type: 'json' };
|
|
3
|
+
export class AkaClient {
|
|
4
|
+
config;
|
|
5
|
+
http;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.http = ky.create({
|
|
9
|
+
prefixUrl: config.server,
|
|
10
|
+
headers: {
|
|
11
|
+
'X-AOI-Runner-Id': config.runnerId,
|
|
12
|
+
'X-AOI-Runner-Key': config.runnerKey,
|
|
13
|
+
'User-Agent': `Aka/${metadata.version}`
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async poll() {
|
|
18
|
+
return this.http.post('api/runner/ranklist/poll').json();
|
|
19
|
+
}
|
|
20
|
+
async complete(contestId, taskId, payload) {
|
|
21
|
+
return this.http
|
|
22
|
+
.post(`api/runner/ranklist/task/${contestId}/${taskId}/complete`, { json: payload })
|
|
23
|
+
.json();
|
|
24
|
+
}
|
|
25
|
+
async problems(contestId, taskId) {
|
|
26
|
+
return this.http.get(`api/runner/ranklist/task/${contestId}/${taskId}/problems`).json();
|
|
27
|
+
}
|
|
28
|
+
async participants(contestId, taskId, since, lastId) {
|
|
29
|
+
return this.http
|
|
30
|
+
.get(`api/runner/ranklist/task/${contestId}/${taskId}/participants`, {
|
|
31
|
+
searchParams: {
|
|
32
|
+
since,
|
|
33
|
+
lastId
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.json();
|
|
37
|
+
}
|
|
38
|
+
async solutions(contestId, taskId, since, lastId) {
|
|
39
|
+
return this.http
|
|
40
|
+
.get(`api/runner/ranklist/task/${contestId}/${taskId}/solutions`, {
|
|
41
|
+
searchParams: {
|
|
42
|
+
since,
|
|
43
|
+
lastId
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
.json();
|
|
47
|
+
}
|
|
48
|
+
async uploadUrls(contestId, taskId) {
|
|
49
|
+
return this.http.get(`api/runner/ranklist/task/${contestId}/${taskId}/uploadUrls`).json();
|
|
50
|
+
}
|
|
51
|
+
async uploadRanklist(url, ranklist) {
|
|
52
|
+
return ky.put(url, {
|
|
53
|
+
json: ranklist
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,IAAI,CAAA;AACxC,OAAO,QAAQ,MAAM,iBAAiB,CAAC,SAAS,IAAI,EAAE,MAAM,EAAE,CAAA;AA2F9D,MAAM,OAAO,SAAS;IAEA;IADpB,IAAI,CAAY;IAChB,YAAoB,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QAC1C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC;YACpB,SAAS,EAAE,MAAM,CAAC,MAAM;YACx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iB,EAAE,MAAc;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,4BAA4B,SAAS,IAAI,MAAM,aAAa,CAAC,CAAC,IAAI,EAKpF,CAAA;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,QAAmB;QACnD,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE;YACjB,IAAI,EAAE,QAAQ;SACf,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/lib/db.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
import { IParticipant, ISolution } from './client.js';
|
|
3
|
+
export interface IAkaDbConfig {
|
|
4
|
+
mongoUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class AkaDb {
|
|
7
|
+
private config;
|
|
8
|
+
mongo: MongoClient;
|
|
9
|
+
db: import("mongodb").Db;
|
|
10
|
+
participants: import("mongodb").Collection<IParticipant & {
|
|
11
|
+
contestId: string;
|
|
12
|
+
}>;
|
|
13
|
+
solutions: import("mongodb").Collection<ISolution & {
|
|
14
|
+
contestId: string;
|
|
15
|
+
}>;
|
|
16
|
+
constructor(config: IAkaDbConfig);
|
|
17
|
+
}
|
package/lib/db.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
export class AkaDb {
|
|
3
|
+
config;
|
|
4
|
+
mongo;
|
|
5
|
+
db;
|
|
6
|
+
participants;
|
|
7
|
+
solutions;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.mongo = new MongoClient(config.mongoUrl);
|
|
11
|
+
this.db = this.mongo.db('aka');
|
|
12
|
+
this.participants = this.db.collection('participants');
|
|
13
|
+
this.solutions = this.db.collection('solutions');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=db.js.map
|
package/lib/db.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAOrC,MAAM,OAAO,KAAK;IAMI;IALpB,KAAK,CAAA;IACL,EAAE,CAAA;IACF,YAAY,CAAA;IACZ,SAAS,CAAA;IAET,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC7C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAuC,cAAc,CAAC,CAAA;QAC5F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAoC,WAAW,CAAC,CAAA;IACrF,CAAC;CACF"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AkaClient, IAkaClientConfig } from './client.js';
|
|
2
|
+
import { AkaDb, IAkaDbConfig } from './db.js';
|
|
3
|
+
export interface IAkaConfig {
|
|
4
|
+
client: IAkaClientConfig;
|
|
5
|
+
db: IAkaDbConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare class Aka {
|
|
8
|
+
private config;
|
|
9
|
+
client: AkaClient;
|
|
10
|
+
db: AkaDb;
|
|
11
|
+
logger: import("pino").Logger<never>;
|
|
12
|
+
constructor(config: IAkaConfig);
|
|
13
|
+
syncSolutions(contestId: string, taskId: string, limit: number): Promise<number>;
|
|
14
|
+
syncParticipants(contestId: string, taskId: string, limit: number): Promise<number>;
|
|
15
|
+
poll(): Promise<boolean>;
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { AkaClient } from './client.js';
|
|
3
|
+
import { getCalculator } from './calc/index.js';
|
|
4
|
+
import { AkaDb } from './db.js';
|
|
5
|
+
import { pino } from 'pino';
|
|
6
|
+
import { wait } from './utils.js';
|
|
7
|
+
export class Aka {
|
|
8
|
+
config;
|
|
9
|
+
client;
|
|
10
|
+
db;
|
|
11
|
+
logger;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.client = new AkaClient(config.client);
|
|
15
|
+
this.db = new AkaDb(config.db);
|
|
16
|
+
this.logger = pino();
|
|
17
|
+
}
|
|
18
|
+
async syncSolutions(contestId, taskId, limit) {
|
|
19
|
+
this.logger.info({ contestId, taskId }, `Start to sync solutions with limit=${limit}`);
|
|
20
|
+
const last = await this.db.solutions.findOne({ contestId }, { sort: { completedAt: -1, _id: -1 } });
|
|
21
|
+
let since = 0, lastId = '00000000-0000-0000-0000-000000000000';
|
|
22
|
+
if (last) {
|
|
23
|
+
since = last.completedAt;
|
|
24
|
+
lastId = last._id;
|
|
25
|
+
}
|
|
26
|
+
for (;;) {
|
|
27
|
+
this.logger.info({ contestId, taskId }, `Sync solutions from since=${since} lastId=${lastId}`);
|
|
28
|
+
const solutions = await this.client.solutions(contestId, taskId, since, lastId);
|
|
29
|
+
for (const solution of solutions) {
|
|
30
|
+
await this.db.solutions.updateOne({ _id: solution._id }, { $set: { ...solution, contestId } }, { upsert: true });
|
|
31
|
+
}
|
|
32
|
+
if (!solutions.length) {
|
|
33
|
+
this.logger.info({ contestId, taskId }, `No more solutions`);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
since = solutions[solutions.length - 1].completedAt;
|
|
37
|
+
lastId = solutions[solutions.length - 1]._id;
|
|
38
|
+
if (since >= limit) {
|
|
39
|
+
this.logger.info({ contestId, taskId }, `Reach limit=${limit}`);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Math.max(since, limit);
|
|
44
|
+
}
|
|
45
|
+
async syncParticipants(contestId, taskId, limit) {
|
|
46
|
+
this.logger.info({ contestId, taskId }, `Start to sync participants with limit=${limit}`);
|
|
47
|
+
const last = await this.db.participants.findOne({ contestId }, { sort: { updatedAt: -1, _id: -1 } });
|
|
48
|
+
let since = 0, lastId = '00000000-0000-0000-0000-000000000000';
|
|
49
|
+
if (last) {
|
|
50
|
+
since = last.updatedAt;
|
|
51
|
+
lastId = last._id;
|
|
52
|
+
}
|
|
53
|
+
for (;;) {
|
|
54
|
+
this.logger.info({ contestId, taskId }, `Sync participants from since=${since} lastId=${lastId}`);
|
|
55
|
+
const participants = await this.client.participants(contestId, taskId, since, lastId);
|
|
56
|
+
for (const participant of participants) {
|
|
57
|
+
await this.db.participants.updateOne({ _id: participant._id }, { $set: { ...participant, contestId } }, { upsert: true });
|
|
58
|
+
}
|
|
59
|
+
if (!participants.length) {
|
|
60
|
+
this.logger.info({ contestId, taskId }, `No more participants`);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
since = participants[participants.length - 1].updatedAt;
|
|
64
|
+
lastId = participants[participants.length - 1]._id;
|
|
65
|
+
if (since >= limit) {
|
|
66
|
+
this.logger.info({ contestId, taskId }, `Reach limit=${limit}`);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return Math.max(since, limit);
|
|
71
|
+
}
|
|
72
|
+
async poll() {
|
|
73
|
+
const { contestId, taskId, ranklistUpdatedAt, ranklists } = await this.client.poll();
|
|
74
|
+
if (!contestId)
|
|
75
|
+
return false;
|
|
76
|
+
this.logger.info({ contestId, taskId }, `Poll ${ranklists.length} ranklists at ${ranklistUpdatedAt}`);
|
|
77
|
+
let limit = ranklistUpdatedAt;
|
|
78
|
+
const configDicts = ranklists.map((r) => dotenv.parse(r.settings.config ?? ''));
|
|
79
|
+
const calculators = configDicts.map((dict) => getCalculator(this.db, this.client, this.logger, dict));
|
|
80
|
+
const syncOptions = await Promise.all(calculators.map(async (calc, i) => calc && (await calc.loadConfig(configDicts[i])))).then((list) => list.filter((opt) => !!opt));
|
|
81
|
+
const shouldSyncParticipants = syncOptions.some((opt) => opt.shouldSyncParticipants);
|
|
82
|
+
const shouldSyncSolutions = syncOptions.some((opt) => opt.shouldSyncSolutions);
|
|
83
|
+
if (shouldSyncParticipants) {
|
|
84
|
+
limit = await this.syncParticipants(contestId, taskId, limit);
|
|
85
|
+
}
|
|
86
|
+
if (shouldSyncSolutions) {
|
|
87
|
+
limit = await this.syncSolutions(contestId, taskId, limit);
|
|
88
|
+
}
|
|
89
|
+
this.logger.info({ contestId, taskId }, `Sync done, calculate ${ranklists.length} ranklists`);
|
|
90
|
+
const urls = await this.client.uploadUrls(contestId, taskId);
|
|
91
|
+
const urlDict = Object.fromEntries(urls.map(({ key, url }) => [key, url]));
|
|
92
|
+
await Promise.all(ranklists.map(async (ranklist, index) => {
|
|
93
|
+
const calculator = calculators[index];
|
|
94
|
+
const url = urlDict[ranklist.key];
|
|
95
|
+
if (!calculator || !url) {
|
|
96
|
+
this.logger.warn({ contestId, taskId, key: ranklist.key }, `No calculator or url`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const now = performance.now();
|
|
100
|
+
const result = await calculator.calculate(contestId, taskId, ranklist.key);
|
|
101
|
+
this.logger.info({ contestId, taskId, key: ranklist.key }, `Ranklist ${ranklist.key} calculated in ${performance.now() - now}ms`);
|
|
102
|
+
await this.client.uploadRanklist(url, result);
|
|
103
|
+
}));
|
|
104
|
+
await this.client.complete(contestId, taskId, { ranklistUpdatedAt: limit });
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
async start() {
|
|
108
|
+
this.logger.info(`Start to poll`);
|
|
109
|
+
for (;;) {
|
|
110
|
+
try {
|
|
111
|
+
const success = await this.poll();
|
|
112
|
+
if (!success) {
|
|
113
|
+
await wait(1000);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
this.logger.error(err);
|
|
118
|
+
await wait(1000);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAoB,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAgB,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAOjC,MAAM,OAAO,GAAG;IAKM;IAJpB,MAAM,CAAA;IACN,EAAE,CAAA;IACF,MAAM,CAAA;IAEN,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,MAAc,EAAE,KAAa;QAClE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,sCAAsC,KAAK,EAAE,CAAC,CAAA;QACtF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAC1C,EAAE,SAAS,EAAE,EACb,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE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,CAAC,eAAe,CAAC,CAAA;QACjC,SAAS,CAAC;YACR,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;gBACjC,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;gBAClB,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACtB,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wait(ms: number): Promise<unknown>;
|
package/lib/utils.js
ADDED
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI,CAAC,EAAU;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC"}
|