@@ -193,31 +193,49 @@ def get_pos(id):
193
193
194
194
if config .args .order_from_ccs :
195
195
# Sort by increasing difficulty, extracted from the CCS api.
196
- # Get active contest.
196
+ class ProblemStat :
197
+ def __init__ (self ):
198
+ self .solved = 0
199
+ self .submissions = 0
200
+ self .pending = 0
201
+ self .teams_submitted = 0
202
+ self .teams_pending = 0
203
+
204
+ def update (self , team_stats : dict [str , Any ]):
205
+ if team_stats ["solved" ]:
206
+ self .solved += 1
207
+ if team_stats ["num_judged" ]:
208
+ self .submissions += team_stats ["num_judged" ]
209
+ self .teams_submitted += 1
210
+ if team_stats ["num_pending" ]:
211
+ self .pending += team_stats ["num_pending" ]
212
+ self .teams_pending += 1
213
+
214
+ def key (self ) -> tuple [int , int ]:
215
+ # self.solved more AC => easier
216
+ # possible tie breakers:
217
+ # self.submissions more needed to get the same number of AC => Harder
218
+ # self.teams_pending more teams tried => appeared easier
219
+ # TODO: consider more stats?
220
+ return (- self .solved , self .submissions )
197
221
222
+ # Get active contest.
198
223
cid = get_contest_id ()
199
- solves = dict ()
200
224
201
225
# Read set of problems
202
226
contest_problems = call_api_get_json (f"/contests/{ cid } /problems?public=true" )
203
227
assert isinstance (problems , list )
204
- for path in contest_problems :
205
- solves [ path [ "id" ]] = 0
228
+
229
+ problem_stats = { problem [ "id" ]: ProblemStat () for problem in contest_problems }
206
230
207
231
scoreboard = call_api_get_json (f"/contests/{ cid } /scoreboard?public=true" )
208
232
209
233
for team in scoreboard ["rows" ]:
210
- for path in team ["problems" ]:
211
- if path ["solved" ]:
212
- solves [path ["problem_id" ]] += 1
213
-
214
- # Convert away from defaultdict, so any non matching keys below raise an error.
215
- solves = dict (solves )
216
- verbose ("solves: " + str (solves ))
234
+ for team_stats in team ["problems" ]:
235
+ problem_stats [team_stats ["problem_id" ]].update (team_stats )
217
236
218
237
# Sort the problems
219
- # Use negative solves instead of reversed, to preserver stable order.
220
- problems .sort (key = lambda p : (- solves [p .name ], p .label ))
238
+ problems .sort (key = lambda p : (problem_stats [p .name ].key (), p .label ))
221
239
verbose (f"order: { ', ' .join (map (lambda p : str (p .label ), problems ))} " )
222
240
223
241
if ask_variable_bool ("Update order in contest.yaml" ):
0 commit comments