-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.js
96 lines (86 loc) · 3.36 KB
/
analyze.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const config = require('./config.json');
const fs = require('fs');
const XLSX = require('xlsx');
const path = require('path');
const adjusted = require(config.adjust.adjustedSubmissionPath[config.contest.currentType]);
const teamNames = new Set();
adjusted.forEach(({ team }) => teamNames.add(team.name));
const teamsMap = new Map();
teamNames.forEach(name => {
const data = {
name: name,
rank: 0,
uniqueCorrectSubmissionsCount: 0,
correctSubmissionsCount: 0,
wrongSubmissionsCount: 0,
submissionCount: 0,
time: 0,
correctSubmissionNumberSum: 0,
submissions: {
all: [],
correct: [],
wrong: []
}
};
teamsMap.set(name, data);
});
adjusted.forEach(sub => {
const data = teamsMap.get(sub.team.name);
if (sub.result === 'Accepted') {
data.correctSubmissionsCount++;
if (sub.status) {
data.uniqueCorrectSubmissionsCount++;
data.correctSubmissionNumberSum += sub.submissionNumber;
data.time += sub.time;
}
data.submissions.correct.push(sub);
} else {
data.wrongSubmissionsCount++;
data.submissions.wrong.push(sub);
}
data.submissionCount++;
data.submissions.all.push(sub);
});
const teamsArr = [...teamsMap].map(pair => pair[1])
.sort((a, b) => {
if (a.uniqueCorrectSubmissionsCount === b.uniqueCorrectSubmissionsCount) {
if (a.time === b.time) {
if (a.correctSubmissionNumberSum === b.correctSubmissionNumberSum) {
return a.submissionCount - b.submissionCount;
}
return a.correctSubmissionNumberSum - b.correctSubmissionNumberSum;
}
return a.time - b.time;
}
return b.uniqueCorrectSubmissionsCount - a.uniqueCorrectSubmissionsCount;
})
.map((teamData, index) => {
teamData.rank = index + 1;
return teamData;
});
const JSONFilepath = config.analyze.analyzedSubmissionPath.JSON[config.contest.currentType];
fs.mkdirSync(path.dirname(JSONFilepath), { recursive: true });
fs.writeFileSync(JSONFilepath, JSON.stringify(teamsArr, null, 4));
const wb = XLSX.utils.book_new();
if (!wb.Props)
wb.Props = {};
wb.Props.Title = 'Leaderboard';
const wsName = 'Leaderboard';
const problems = config.contest.problems[config.contest.currentType];
const wsData = [['Rank', 'Team', 'Solved', 'Time', 'Submission Number Sum', 'Total Submissions', ...problems]];
const problemIndex = new Map();
problems.forEach((name, index) => problemIndex.set(name, index));
teamsArr.forEach(team => {
const row = [team.rank, team.name, team.uniqueCorrectSubmissionsCount, team.time, team.correctSubmissionNumberSum, team.submissionCount];
const arr = Array(problemIndex.size);
team.submissions.correct.forEach(sub => arr[problemIndex.get(sub.problem.name)] = `${sub.time} + ${sub.submissionNumber}`);
row.push(...arr);
wsData.push(row);
});
const ws = XLSX.utils.aoa_to_sheet(wsData);
XLSX.utils.book_append_sheet(wb, ws, wsName);
const XLSXFilepath = config.analyze.analyzedSubmissionPath.XLSX[config.contest.currentType];
fs.mkdirSync(path.dirname(XLSXFilepath), { recursive: true });
XLSX.writeFile(wb, XLSXFilepath);
console.log(`done with ${teamsArr.length} team(s)`);
teamsArr.forEach(team => console.log(`rank ${team.rank}: ${team.name}`));