def submit_guesses(): data = json.loads(request.forms.get("data")) answers = data['answers'] quiz_type = data['type'] num_correct = 0 total = len(answers) for guess in answers: UserGuess.create(guess=int(guess['answer']), comment=guess['comment_id'], quiz_type=quiz_type) actual_count = Comment.select().where(Comment.c_id == guess['comment_id'])[0].upvotes num_correct += 1 if detect_group(actual_count) == int(guess['answer']) else 0 return json.dumps({"num_correct": num_correct, "total": total})
def x_as_y(g): correct_group = detect_group(g.comment.upvotes - g.comment.downvotes) return g.guess == y and correct_group == x
def is_correct(g): return detect_group(g.comment.upvotes - g.comment.downvotes) == g.guess
def is_group(x): return lambda g: detect_group(g.comment.upvotes - g.comment.downvotes) == x