async def myresults(context: commands.Context) -> None: """Shows you your results on the latest vote.""" week = compo.get_week(False) if week["votingOpen"]: await context.send( "You can't really get results while they're still coming " "in, despite what election coverage would lead you to believe; sorry." ) return user_entry = None for entry in week["entries"]: if entry["discordID"] == context.author.id: user_entry = entry break if not user_entry: await context.send("You didn't submit anything for this week!") return compo.verify_votes(week) scores = compo.fetch_votes_for_entry(week["votes"], entry["uuid"]) if len(scores) == 0: await context.send( "Well this is awkward, no one voted on your entry...") return message = [] message.append( "Please keep in mind that music is subjective, and that " "these scores shouldn't be taken to represent the quality of" " your entry-- your artistic work is valuable, regardless of" " what results it was awarded, so don't worry too much about it") message.append("And with that out of the way...") message.append("*drumroll please*") for category in week["voteParams"]: category_scores = [ s['rating'] for s in scores if s['voteParam'] == category ] if len(category_scores) == 0: # The user received votes, but not in this category category_scores = [0] text = "%s: You got an average score of %1.2f" \ % (category, statistics.mean(category_scores)) message.append(text) message.append("Your total average was: %1.2f!" % statistics.mean(s['rating'] for s in scores)) await context.send("\n".join(message))
def test_cant_vote_too_low(self): week = compo.blank_week() votes = [{ "userID": 1234, "ratings": [{ "voteParam": "overall", "entryUUID": "123", "rating": -5 }] }] week["votes"] = votes.copy() compo.verify_votes(week) assert week["votes"][0]["ratings"] == []
def test_a_single_vote_is_ok(self): week = compo.blank_week() votes = [{ "userID": 1234, "ratings": [{ "voteParam": "overall", "entryUUID": "123", "rating": 3 }] }] week["votes"] = votes.copy() compo.verify_votes(week) assert week["votes"] == votes
def test_duped_votes_are_discarded(self): week = compo.blank_week() rating1 = { "voteParam": "overall", "entryUUID": "123", "rating": 3 } rating2 = { "voteParam": "overall", "entryUUID": "123", "rating": 4 } votes = [{ "userID": 1234, "ratings": [rating1, rating2] }] week["votes"] = votes.copy() compo.verify_votes(week) assert week["votes"][0]["ratings"] == [rating1]
def test_all_is_good_by_default(self): week = compo.blank_week() compo.verify_votes(week) assert week["votes"] == []