Skip to content

Commit d7674b1

Browse files
kish1nAshwin Kishin Banwari
andauthored
Added ;plot progress (cheran-senthil#482)
* Added ;plot progress * Made +number a flag for ;plot rating Co-authored-by: Ashwin Kishin Banwari <ashwin@4d-printer.localdomain>
1 parent 567e19c commit d7674b1

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

tle/cogs/graphs.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,43 @@ def nice_sub_type(types):
3939
'PRACTICE':'Practice: {}'}
4040
return [nice_map[t] for t in types]
4141

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,
5145
ratings,
5246
linestyle='-',
5347
marker=mark,
5448
markersize=3,
5549
markerfacecolor='white',
5650
markeredgewidth=0.5)
57-
5851
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)
5963
plt.gcf().autofmt_xdate()
6064

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+
6179
def _classify_submissions(submissions):
6280
solved_by_type = {sub_type: [] for sub_type in cf.Party.PARTICIPANT_TYPES}
6381
for submission in submissions:
@@ -208,11 +226,11 @@ async def plot(self, ctx):
208226
for name with spaces use "!name with spaces" (with quotes)."""
209227
await ctx.send_help('plot')
210228

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]')
212230
async def rating(self, ctx, *args: str):
213231
"""Plots Codeforces rating graph for the handles provided."""
214232

215-
(zoom, peak), args = cf_common.filter_flags(args, ['+zoom' , '+peak'])
233+
(zoom, number, peak), args = cf_common.filter_flags(args, ['+zoom' , '+number', '+peak'])
216234
filt = cf_common.SubFilter()
217235
args = filt.parse(args)
218236
handles = args or ('!' + str(ctx.author),)
@@ -245,7 +263,10 @@ def max_prefix(user):
245263

246264
plt.clf()
247265
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)
249270
current_ratings = [rating_changes[-1].newRating if rating_changes else 'Unrated' for rating_changes in resp]
250271
labels = [gc.StrWrap(f'{handle} ({rating})') for handle, rating in zip(handles, current_ratings)]
251272
plt.legend(labels, loc='upper left')

0 commit comments

Comments
 (0)