def update_statistic(): current_game = CurrentGame.query.all() for game in current_game: statistic_entry = Statistic(user_id=game.user_id) statistic_entry.game_type = game.game_type statistic_entry.total_rounds = game.total_rounds statistic_entry.correct_answers = game.correct_answers db.session.add(statistic_entry) db.session.delete(game) db.session.commit() return {'result': 'success'}
def game_statistic(): revision_game_entry = CurrentGame.query.filter_by( user_id=current_user.id, game_completed=True).first() total_rounds = revision_game_entry.total_rounds correct_answers = revision_game_entry.correct_answers # Update statistic table statistic_entry = Statistic(user_id=current_user.id) statistic_entry.game_type = revision_game_entry.game_type statistic_entry.total_rounds = total_rounds statistic_entry.correct_answers = correct_answers db.session.add(statistic_entry) db.session.delete(revision_game_entry) db.session.commit() return render_template('games/game_statistic.html', total_rounds=total_rounds, correct_answers=correct_answers)
def statistic(): """ Return statistic for current game. Add entry to Statistic Delete current game """ db_user = User.check_request(request) revision_game_entry = CurrentGame.query.\ filter_by(user_id=db_user.id).first() if revision_game_entry is None: revision_game_entry = CurrentGame.query.\ filter_by(user_id=db_user.id).first() if revision_game_entry is None: return {'redirect': '/games'} else: return {'redirect': '/play'} total_rounds = revision_game_entry.total_rounds correct_answers = revision_game_entry.correct_answers # Update statistic table statistic_entry = Statistic(user_id=db_user.id) statistic_entry.game_type = revision_game_entry.game_type statistic_entry.total_rounds = total_rounds statistic_entry.correct_answers = correct_answers if db_user and db_user.is_authenticated(): db.session.add(statistic_entry) db.session.delete(revision_game_entry) db.session.commit() return { 'total_rounds': total_rounds, 'correct_answers': correct_answers, 'game_type': GameType[revision_game_entry.game_type].value }