Skip to content

Commit

Permalink
Start working on howgud (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
krofna committed Jul 31, 2019
1 parent 2e7885c commit 300af29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion tle/cogs/codeforces.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ async def gotgud(self, ctx):
@commands.command(brief='Skip challenge')
@cf_common.user_guard(group='gitgud')
async def nogud(self, ctx):
await cf_common.resolve_handles(ctx, self.converter, ('!' + str(ctx.author),))
user_id = ctx.message.author.id
active = cf_common.user_db.check_challenge(user_id)
if not active:
Expand Down
20 changes: 20 additions & 0 deletions tle/cogs/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,26 @@ def vert_line(x):
discord_common.set_author_footer(embed, ctx.author)
await ctx.send(embed=embed, file=discord_file)

@plot.command(brief='Plot histogram of gudgiting')
async def howgud(self, ctx, *members: discord.Member):
hist_bins = list(range(-300 + 50, 300 + 50 + 1, 100))
deltas = [[x[0] for x in cf_common.user_db.howgud(member.id)] for member in members]
labels = [f'\N{ZERO WIDTH SPACE}{member.display_name}: {len(delta)}'
for member, delta in zip(members, deltas)]

plt.clf()
plt.margins(x=0)
plt.hist(deltas, bins=hist_bins, label=labels, rwidth=1)
plt.xlabel('Problem delta')
plt.ylabel('Number solved')
plt.legend()

discord_file = _get_current_figure_as_file()
embed = discord_common.cf_color_embed(title='Histogram of gudgitting')
discord_common.attach_image(embed, discord_file)
discord_common.set_author_footer(embed, ctx.author)
await ctx.send(embed=embed, file=discord_file)

async def cog_command_error(self, ctx, error):
if isinstance(error, GraphCogError):
await ctx.send(embed=discord_common.embed_alert(error))
Expand Down
6 changes: 6 additions & 0 deletions tle/util/db/user_db_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def get_gudgitters(self):
'''
return self.conn.execute(query).fetchall()

def howgud(self, user_id):
query = '''
SELECT rating_delta FROM challenge WHERE user_id = ? AND finish_time IS NOT NULL
'''
return self.conn.execute(query, (user_id,)).fetchall()

def complete_challenge(self, user_id, challenge_id, finish_time, delta):
query1 = '''
UPDATE challenge SET finish_time = ?, status = 0
Expand Down

0 comments on commit 300af29

Please sign in to comment.