forked from Project-LemonLime/Project_LemonLime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontestant.cpp
More file actions
283 lines (226 loc) · 7.5 KB
/
contestant.cpp
File metadata and controls
283 lines (226 loc) · 7.5 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
* SPDX-FileCopyrightText: 2011-2018 Project Lemon, Zhipeng Jia
* SPDX-FileCopyrightText: 2018-2019 Project LemonPlus, Dust1404
* SPDX-FileCopyrightText: 2019-2022 Project LemonLime
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "contestant.h"
#include "base/LemonUtils.hpp"
#include "core/contest.h"
#include <QTimeZone>
#include <utility>
Contestant::Contestant(QObject *parent) : QObject(parent) {}
auto Contestant::getContestantName() const -> const QString & { return contestantName; }
auto Contestant::getCheckJudged(int index) const -> bool { return checkJudged[index]; }
auto Contestant::getCompileState(int index) const -> CompileState { return compileState[index]; }
auto Contestant::getSourceFile(int index) const -> const QString & { return sourceFile[index]; }
auto Contestant::getCompileMessage(int index) const -> const QString & { return compileMesaage[index]; }
auto Contestant::getInputFiles(int index) const -> const QList<QStringList> & { return inputFiles[index]; }
auto Contestant::getResult(int index) const -> const QList<QList<ResultState>> & { return result[index]; }
auto Contestant::getMessage(int index) const -> const QList<QStringList> & { return message[index]; }
auto Contestant::getScore(int index) const -> const QList<QList<int>> & { return score[index]; }
auto Contestant::getTimeUsed(int index) const -> const QList<QList<int>> & { return timeUsed[index]; }
auto Contestant::getMemoryUsed(int index) const -> const QList<QList<long long>> & {
return memoryUsed[index];
}
auto Contestant::getJudingTime() const -> QDateTime { return judgingTime; }
void Contestant::setContestantName(const QString &name) { contestantName = name; }
void Contestant::setCheckJudged(int index, bool check) { checkJudged[index] = check; }
void Contestant::setCompileState(int index, CompileState state) { compileState[index] = state; }
void Contestant::setSourceFile(int index, const QString &fileName) { sourceFile[index] = fileName; }
void Contestant::setCompileMessage(int index, const QString &text) { compileMesaage[index] = text; }
void Contestant::setInputFiles(int index, const QList<QStringList> &files) { inputFiles[index] = files; }
void Contestant::setResult(int index, const QList<QList<ResultState>> &_result) { result[index] = _result; }
void Contestant::setMessage(int index, const QList<QStringList> &_message) { message[index] = _message; }
void Contestant::setScore(int index, const QList<QList<int>> &_score) { score[index] = _score; }
void Contestant::setTimeUsed(int index, const QList<QList<int>> &_timeUsed) { timeUsed[index] = _timeUsed; }
void Contestant::setMemoryUsed(int index, const QList<QList<long long>> &_memoryUsed) {
memoryUsed[index] = _memoryUsed;
}
void Contestant::setJudgingTime(QDateTime time) { judgingTime = std::move(time); }
void Contestant::addTask() {
checkJudged.append(false);
compileState.append(NoValidSourceFile);
sourceFile.append("");
compileMesaage.append("");
inputFiles.append(QList<QStringList>());
result.append(QList<QList<ResultState>>());
message.append(QList<QStringList>());
score.append(QList<QList<int>>());
timeUsed.append(QList<QList<int>>());
memoryUsed.append(QList<QList<long long>>());
}
void Contestant::deleteTask(int index) {
checkJudged.removeAt(index);
compileState.removeAt(index);
sourceFile.removeAt(index);
compileMesaage.removeAt(index);
inputFiles.removeAt(index);
result.removeAt(index);
message.removeAt(index);
score.removeAt(index);
timeUsed.removeAt(index);
memoryUsed.removeAt(index);
}
void Contestant::swapTask(int a, int b) {
if (a < 0 || a >= checkJudged.size())
return;
if (b < 0 || b >= checkJudged.size())
return;
checkJudged.swapItemsAt(a, b);
compileState.swapItemsAt(a, b);
sourceFile.swapItemsAt(a, b);
compileMesaage.swapItemsAt(a, b);
inputFiles.swapItemsAt(a, b);
result.swapItemsAt(a, b);
message.swapItemsAt(a, b);
score.swapItemsAt(a, b);
timeUsed.swapItemsAt(a, b);
memoryUsed.swapItemsAt(a, b);
}
auto Contestant::getTaskScore(int index) const -> int {
if (0 > index || index >= checkJudged.size())
return -1;
if (! checkJudged[index])
return -1;
int total = 0;
for (const auto &i : score[index]) {
int minv = 1000000000;
for (int j : i) {
if (j < minv && j >= 0)
minv = j;
}
if (minv == 1000000000)
minv = 0;
total += minv;
}
return total;
}
auto Contestant::getTotalScore() const -> int {
if (checkJudged.empty())
return -1;
for (bool i : checkJudged) {
if (! i)
return -1;
}
int total = 0;
for (int i = 0; i < score.size(); i++) {
total += getTaskScore(i);
}
return total;
}
auto Contestant::getTotalUsedTime() const -> int {
if (checkJudged.empty())
return -1;
for (bool i : checkJudged) {
if (! i)
return -1;
}
int total = 0;
for (const auto &i : timeUsed) {
for (const auto &j : i) {
for (int k : j) {
if (k >= 0)
total += k;
}
}
}
return total;
}
int Contestant::writeToJson(QJsonObject &out) {
WRITE_JSON(out, contestantName);
WRITE_JSON(out, checkJudged);
WRITE_JSON(out, sourceFile);
WRITE_JSON(out, compileMesaage);
WRITE_JSON(out, inputFiles);
WRITE_JSON(out, message);
WRITE_JSON(out, score);
WRITE_JSON(out, timeUsed);
WRITE_JSON(out, memoryUsed);
int judgingTime_date = judgingTime.date().toJulianDay();
int judgingTime_time = judgingTime.time().msecsSinceStartOfDay();
int judgingTime_timespec = judgingTime.timeSpec();
WRITE_JSON(out, judgingTime_date);
WRITE_JSON(out, judgingTime_time);
WRITE_JSON(out, judgingTime_timespec);
WRITE_JSON(out, compileState);
WRITE_JSON(out, result);
return 0;
}
int Contestant::readFromJson(const QJsonObject &in) {
READ_JSON(in, contestantName);
READ_JSON(in, checkJudged);
READ_JSON(in, sourceFile);
READ_JSON(in, compileMesaage);
READ_JSON(in, inputFiles);
READ_JSON(in, message);
READ_JSON(in, score);
READ_JSON(in, timeUsed);
READ_JSON(in, memoryUsed);
int judgingTime_date = 0;
int judgingTime_time = 0;
int judgingTime_timespec = 0;
READ_JSON(in, judgingTime_date);
READ_JSON(in, judgingTime_time);
READ_JSON(in, judgingTime_timespec);
auto dt =
QDateTime(QDate::fromJulianDay(judgingTime_date), QTime::fromMSecsSinceStartOfDay(judgingTime_time));
if (judgingTime_timespec == Qt::UTC) {
dt.setTimeZone(QTimeZone::utc());
} else {
dt.setTimeZone(QTimeZone::systemTimeZone());
}
judgingTime = dt;
READ_JSON(in, compileState);
READ_JSON(in, result);
return 0;
}
void Contestant::readFromStream(QDataStream &in) {
in >> contestantName;
in >> checkJudged;
in >> sourceFile;
in >> compileMesaage;
in >> inputFiles;
in >> message;
in >> score;
in >> timeUsed;
in >> memoryUsed;
quint32 judgingTime_date = 0;
quint32 judgingTime_time = 0;
quint8 judgingTime_timespec = 0;
in >> judgingTime_date;
in >> judgingTime_time;
in >> judgingTime_timespec;
auto dt = QDateTime(QDate::fromJulianDay(judgingTime_date),
QTime::fromMSecsSinceStartOfDay(static_cast<int>(judgingTime_time)));
if (judgingTime_timespec == Qt::UTC) {
dt.setTimeZone(QTimeZone::utc());
} else {
dt.setTimeZone(QTimeZone::systemTimeZone());
}
judgingTime = dt;
int count = 0;
int _count = 0;
int __count = 0;
int tmp = 0;
in >> count;
for (int i = 0; i < count; i++) {
in >> tmp;
compileState.append(CompileState(tmp));
}
in >> count;
for (int i = 0; i < count; i++) {
result.append(QList<QList<ResultState>>());
in >> _count;
for (int j = 0; j < _count; j++) {
result[i].append(QList<ResultState>());
in >> __count;
for (int k = 0; k < __count; k++) {
in >> tmp;
result[i][j].append(ResultState(tmp));
}
}
}
}