Skip to content

Commit

Permalink
Start working on howgud (#46) (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
krofna authored Aug 31, 2019
1 parent cf5b3df commit 0e0455c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tle/cogs/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,27 @@ 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):
# shift the [-300, 300] gitgud range to center the test
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 0e0455c

Please sign in to comment.