def set_points_to_winner(username): """Award points to the winner of the game""" win_player = User.get(User.username == username) scores = Score.select().where(Score.id_user == win_player.id_user).order_by(Score.score.asc()) best_score = scores[0] puntuation = best_score.score + 100 score = Score(score = puntuation, date = date.today(), id_user = win_player.id_user) score.save()
def post_score(): """ Adds a score and returns the new score """ try: name = request.json['name'] score = request.json['score'] score = Score(name=name, score=score) key = score.put() score = Score.get(key) return json.dumps(dict(score=score.score, name=score.name)) except Exception as e: logging.exception(e)
def post_to_scores(): """ Adds a score and returns the top ten """ try: name = request.json['name'] score = request.json['score'] if isinstance(score, int): score = float(score) score_ = Score(name=name, score=score) key = score_.put() query = Score.all().order("-score") return json.dumps(dict(scores=[dict(name=result.name, score=result.score) for result in query.run(limit=10)])) except Exception as e: logging.exception(e)
def get_scores(): try: query = Score.all().order("-score") return json.dumps(dict(scores=[dict(name=result.name, score=result.score) for result in query.run(limit=10)])) except Exception as e: logging.exception(e)
def map_score_query_result(self, query_result): scores = [] for row in query_result: score = Score() score.id = int(row[0]) score.beatmap_hash = row[1] score.player_name = row[2] score.number_300s = int(row[3]) score.number_100s = int(row[4]) score.number_50s = int(row[5]) score.gekis = int(row[6]) score.katus = int(row[7]) score.misses = int(row[8]) score.score = int(row[9]) score.max_combo = int(row[10]) score.is_perfect_combo = bool(row[11]) score.no_fail = bool(row[12]) score.easy = bool(row[13]) score.hidden = bool(row[14]) score.hard_rock = bool(row[15]) score.sudden_death = bool(row[16]) score.double_time = bool(row[17]) score.relax = bool(row[18]) score.half_time = bool(row[19]) score.flashlight = bool(row[20]) score.spun_out = bool(row[21]) score.auto_pilot = bool(row[22]) score.perfect = bool(row[23]) score.pp = float(row[24]) score.beatmap_id = int(row[25]) score.profile_id = int(row[26]) score.accuracy = float(row[27]) scores.append(score) return scores
def map_score_model(self, replay): score_model = Score() score_model.beatmap_hash = replay.beatmap_hash score_model.player_name = replay.player_name score_model.number_300s = replay.number_300s score_model.number_100s = replay.number_100s score_model.number_50s = replay.number_50s score_model.gekis = replay.gekis score_model.katus = replay.katus score_model.misses = replay.misses score_model.score = replay.score score_model.max_combo = replay.max_combo score_model.is_perfect_combo = replay.is_perfect_combo score_model.no_fail = Mod.NoFail in replay.mod_combination score_model.easy = Mod.Easy in replay.mod_combination score_model.hidden = Mod.Hidden in replay.mod_combination score_model.hard_rock = Mod.HardRock in replay.mod_combination score_model.sudden_death = Mod.SuddenDeath in replay.mod_combination score_model.double_time = Mod.DoubleTime in replay.mod_combination or Mod.Nightcore in replay.mod_combination score_model.relax = Mod.Relax in replay.mod_combination score_model.half_time = Mod.HalfTime in replay.mod_combination score_model.flashlight = Mod.Flashlight in replay.mod_combination score_model.spun_out = Mod.SpunOut in replay.mod_combination score_model.auto_pilot = Mod.Autopilot in replay.mod_combination score_model.perfect = Mod.Perfect in replay.mod_combination return score_model