@@ -39,25 +39,43 @@ def nice_sub_type(types):
39
39
'PRACTICE' :'Practice: {}' }
40
40
return [nice_map [t ] for t in types ]
41
41
42
- def _plot_rating (resp , mark = 'o' ):
43
-
44
- for rating_changes in resp :
45
- ratings , times = [], []
46
- for rating_change in rating_changes :
47
- ratings .append (rating_change .newRating )
48
- times .append (dt .datetime .fromtimestamp (rating_change .ratingUpdateTimeSeconds ))
49
-
50
- plt .plot (times ,
42
+ def _plot_rating (plot_data , mark ):
43
+ for ratings , when in plot_data :
44
+ plt .plot (when ,
51
45
ratings ,
52
46
linestyle = '-' ,
53
47
marker = mark ,
54
48
markersize = 3 ,
55
49
markerfacecolor = 'white' ,
56
50
markeredgewidth = 0.5 )
57
-
58
51
gc .plot_rating_bg (cf .RATED_RANKS )
52
+
53
+ def _plot_rating_by_date (resp , mark = 'o' ):
54
+ def gen_plot_data ():
55
+ for rating_changes in resp :
56
+ ratings , times = [], []
57
+ for rating_change in rating_changes :
58
+ ratings .append (rating_change .newRating )
59
+ times .append (dt .datetime .fromtimestamp (rating_change .ratingUpdateTimeSeconds ))
60
+ yield (ratings , times )
61
+
62
+ _plot_rating (gen_plot_data (), mark )
59
63
plt .gcf ().autofmt_xdate ()
60
64
65
+ def _plot_rating_by_contest (resp , mark = 'o' ):
66
+ def gen_plot_data ():
67
+ for rating_changes in resp :
68
+ ratings , indices = [], []
69
+ index = 1
70
+ for rating_change in rating_changes :
71
+ ratings .append (rating_change .newRating )
72
+ indices .append (index )
73
+ index += 1
74
+ yield (ratings , indices )
75
+
76
+ _plot_rating (gen_plot_data (), mark )
77
+
78
+
61
79
def _classify_submissions (submissions ):
62
80
solved_by_type = {sub_type : [] for sub_type in cf .Party .PARTICIPANT_TYPES }
63
81
for submission in submissions :
@@ -208,11 +226,11 @@ async def plot(self, ctx):
208
226
for name with spaces use "!name with spaces" (with quotes)."""
209
227
await ctx .send_help ('plot' )
210
228
211
- @plot .command (brief = 'Plot Codeforces rating graph' , usage = '[+zoom] [+peak] [handles...] [d>=[[dd]mm]yyyy] [d<[[dd]mm]yyyy]' )
229
+ @plot .command (brief = 'Plot Codeforces rating graph' , usage = '[+zoom] [+number] [+ peak] [handles...] [d>=[[dd]mm]yyyy] [d<[[dd]mm]yyyy]' )
212
230
async def rating (self , ctx , * args : str ):
213
231
"""Plots Codeforces rating graph for the handles provided."""
214
232
215
- (zoom , peak ), args = cf_common .filter_flags (args , ['+zoom' , '+peak' ])
233
+ (zoom , number , peak ), args = cf_common .filter_flags (args , ['+zoom' , '+number' , '+peak' ])
216
234
filt = cf_common .SubFilter ()
217
235
args = filt .parse (args )
218
236
handles = args or ('!' + str (ctx .author ),)
@@ -245,7 +263,10 @@ def max_prefix(user):
245
263
246
264
plt .clf ()
247
265
plt .axes ().set_prop_cycle (gc .rating_color_cycler )
248
- _plot_rating (resp )
266
+ if number :
267
+ _plot_rating_by_contest (resp )
268
+ else :
269
+ _plot_rating_by_date (resp )
249
270
current_ratings = [rating_changes [- 1 ].newRating if rating_changes else 'Unrated' for rating_changes in resp ]
250
271
labels = [gc .StrWrap (f'{ handle } ({ rating } )' ) for handle , rating in zip (handles , current_ratings )]
251
272
plt .legend (labels , loc = 'upper left' )
0 commit comments