Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit 6af5f90

Browse files
authored
Prevent waiting for diagnositcs (#21)
* Add VerdictStatus data. * Remove VerdictPE. See https://codeforces.com/blog/entry/1028 for details. * Minor code cleanups.
1 parent 72abd1e commit 6af5f90

File tree

2 files changed

+110
-66
lines changed

2 files changed

+110
-66
lines changed

codeforces/submissions.go

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package codeforces
22

33
import (
44
"fmt"
5+
"strings"
56
"time"
67

78
"github.com/PuerkitoBio/goquery"
@@ -11,19 +12,37 @@ import (
1112
type (
1213
// Submission holds submission data.
1314
Submission struct {
14-
ID string
15-
When time.Time
16-
Who string
17-
Problem string
18-
Language string
19-
Verdict string
20-
Time string
21-
Memory string
22-
IsJudging bool
23-
Arg Args
15+
ID string
16+
When time.Time
17+
Who string
18+
Problem string
19+
Language string
20+
Verdict string
21+
VerdictStatus int
22+
Time string
23+
Memory string
24+
IsJudging bool
25+
Arg Args
2426
}
2527
)
2628

29+
// Submissions verdict status.
30+
const (
31+
VerdictAC = 1 // Accepted
32+
33+
VerdictWA = 2 // Wrong Answer
34+
VerdictRTE = 4 // Run Time Error
35+
36+
VerdictCE = 5 // Compilation Error
37+
VerdictTLE = 6 // Time Limit Exceeded
38+
VerdictMLE = 7 // Memory Limit Exceeded
39+
VerdictILE = 8 // Idleness Limit Exceeded
40+
41+
VerdictDOJ = 9 // Denial Of Judgement
42+
VerdictSkip = 10 // Skipped
43+
VerdictHack = 11 // Hacked
44+
)
45+
2746
// SubmissionsPage returns link to user submissions page.
2847
func (arg Args) SubmissionsPage(handle string) (link string, err error) {
2948
// Contest not specified.
@@ -214,14 +233,34 @@ func (arg Args) parseSubmissions(page *rod.Page) ([]Submission, bool) {
214233
submissionRow.Language = language
215234

216235
case 5:
217-
isJudging := cell.AttrOr("waiting", "") == "true"
218-
submissionRow.IsJudging = isJudging
219-
if isJudging == true {
220-
isDone = false
221-
}
222-
223236
verdict := clean(cell.Text())
224237
submissionRow.Verdict = verdict
238+
submissionRow.IsJudging = true
239+
240+
verdictMap := map[string]int{
241+
"Accepted": VerdictAC,
242+
"Wrong answer": VerdictWA,
243+
"Runtime error": VerdictRTE,
244+
"Compilation error": VerdictCE,
245+
"Time limit exceeded": VerdictTLE,
246+
"Memory limit exceeded": VerdictMLE,
247+
"Idleness limit exceeded": VerdictILE,
248+
"Denial of judgement": VerdictDOJ,
249+
"Skipped": VerdictSkip,
250+
"Hacked": VerdictHack,
251+
}
252+
253+
for k, v := range verdictMap {
254+
if strings.Contains(verdict, k) {
255+
submissionRow.VerdictStatus = v
256+
submissionRow.IsJudging = false
257+
break
258+
}
259+
}
260+
261+
if submissionRow.IsJudging == true {
262+
isDone = false
263+
}
225264

226265
case 6:
227266
time := clean(cell.Text())

codeforces/submissions_test.go

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -160,52 +160,56 @@ func TestArgs_GetSubmissions(t *testing.T) {
160160
args: args{"cp-tools", 1},
161161
want: []Submission{
162162
{
163-
ID: "81327550",
164-
When: time.Date(2020, time.May, 24, 19, 14, 0, 0, time.UTC),
165-
Who: "cp-tools",
166-
Problem: "A - Watermelon",
167-
Language: "GNU C++17",
168-
Verdict: "Compilation error",
169-
Time: "0 ms",
170-
Memory: "0 KB",
171-
IsJudging: false,
172-
Arg: Args{"4", "a", "contest", ""},
163+
ID: "81327550",
164+
When: time.Date(2020, time.May, 24, 19, 14, 0, 0, time.UTC),
165+
Who: "cp-tools",
166+
Problem: "A - Watermelon",
167+
Language: "GNU C++17",
168+
Verdict: "Compilation error",
169+
VerdictStatus: VerdictCE,
170+
Time: "0 ms",
171+
Memory: "0 KB",
172+
IsJudging: false,
173+
Arg: Args{"4", "a", "contest", ""},
173174
},
174175
{
175-
ID: "81327395",
176-
When: time.Date(2020, time.May, 24, 19, 12, 0, 0, time.UTC),
177-
Who: "cp-tools",
178-
Problem: "A - Watermelon",
179-
Language: "GNU C++17",
180-
Verdict: "Compilation error",
181-
Time: "0 ms",
182-
Memory: "0 KB",
183-
IsJudging: false,
184-
Arg: Args{"4", "a", "contest", ""},
176+
ID: "81327395",
177+
When: time.Date(2020, time.May, 24, 19, 12, 0, 0, time.UTC),
178+
Who: "cp-tools",
179+
Problem: "A - Watermelon",
180+
Language: "GNU C++17",
181+
Verdict: "Compilation error",
182+
VerdictStatus: VerdictCE,
183+
Time: "0 ms",
184+
Memory: "0 KB",
185+
IsJudging: false,
186+
Arg: Args{"4", "a", "contest", ""},
185187
},
186188
{
187-
ID: "81012854",
188-
When: time.Date(2020, time.May, 23, 12, 10, 0, 0, time.UTC),
189-
Who: "cp-tools",
190-
Problem: "B - Before an Exam",
191-
Language: "Ruby",
192-
Verdict: "Runtime error on test 2",
193-
Time: "46 ms",
194-
Memory: "0 KB",
195-
IsJudging: false,
196-
Arg: Args{"4", "b", "contest", ""},
189+
ID: "81012854",
190+
When: time.Date(2020, time.May, 23, 12, 10, 0, 0, time.UTC),
191+
Who: "cp-tools",
192+
Problem: "B - Before an Exam",
193+
Language: "Ruby",
194+
Verdict: "Runtime error on test 2",
195+
VerdictStatus: VerdictRTE,
196+
Time: "46 ms",
197+
Memory: "0 KB",
198+
IsJudging: false,
199+
Arg: Args{"4", "b", "contest", ""},
197200
},
198201
{
199-
ID: "81011111",
200-
When: time.Date(2020, time.May, 23, 11, 45, 0, 0, time.UTC),
201-
Who: "cp-tools",
202-
Problem: "A - Watermelon",
203-
Language: "GNU C++17",
204-
Verdict: "Accepted",
205-
Time: "62 ms",
206-
Memory: "0 KB",
207-
IsJudging: false,
208-
Arg: Args{"4", "a", "contest", ""},
202+
ID: "81011111",
203+
When: time.Date(2020, time.May, 23, 11, 45, 0, 0, time.UTC),
204+
Who: "cp-tools",
205+
Problem: "A - Watermelon",
206+
Language: "GNU C++17",
207+
Verdict: "Accepted",
208+
VerdictStatus: VerdictAC,
209+
Time: "62 ms",
210+
Memory: "0 KB",
211+
IsJudging: false,
212+
Arg: Args{"4", "a", "contest", ""},
209213
},
210214
},
211215
wantErr: false,
@@ -216,16 +220,17 @@ func TestArgs_GetSubmissions(t *testing.T) {
216220
args: args{"cp-tools", 1e9},
217221
want: []Submission{
218222
{
219-
ID: "81012854",
220-
When: time.Date(2020, time.May, 23, 12, 10, 0, 0, time.UTC),
221-
Who: "cp-tools",
222-
Problem: "B - Before an Exam",
223-
Language: "Ruby",
224-
Verdict: "Runtime error on test 2",
225-
Time: "46 ms",
226-
Memory: "0 KB",
227-
IsJudging: false,
228-
Arg: Args{"4", "b", "contest", ""},
223+
ID: "81012854",
224+
When: time.Date(2020, time.May, 23, 12, 10, 0, 0, time.UTC),
225+
Who: "cp-tools",
226+
Problem: "B - Before an Exam",
227+
Language: "Ruby",
228+
Verdict: "Runtime error on test 2",
229+
VerdictStatus: VerdictRTE,
230+
Time: "46 ms",
231+
Memory: "0 KB",
232+
IsJudging: false,
233+
Arg: Args{"4", "b", "contest", ""},
229234
},
230235
},
231236
wantErr: false,

0 commit comments

Comments
 (0)