def games_get_post(): #all_players = db.get_all_players() all_players = db.get_visible_players() if request.method == 'POST': left_defense_player_name = request.form['left_defense_player_name'] left_attack_player_name = request.form['left_attack_player_name'] right_defense_player_name = request.form['right_defense_player_name'] right_attack_player_name = request.form['right_attack_player_name'] timestamp = tools.get_timestamp_for_now() left_team = db.create_team( defense_player=db.get_player_by_name(left_defense_player_name), attack_player=db.get_player_by_name(left_attack_player_name)) right_team = db.create_team( defense_player=db.get_player_by_name(right_defense_player_name), attack_player=db.get_player_by_name(right_attack_player_name)) game = db.create_update_game(timestamp=timestamp, left_team=left_team, right_team=right_team) return redirect(url_for('games_get', timestamp=game.timestamp)) else: all_games = db.get_all_games() return render_template('games.html', players=all_players, games=all_games)
def add_first_stats(self, player_id=None, attack_player_id=None, defense_player_id=None, team_id=None, timestamp=tools.get_timestamp_for_now()): return self.increment_stats(player_id=player_id, attack_player_id=attack_player_id, defense_player_id=defense_player_id, team_id=team_id, timestamp=timestamp)
def update(self, i_wins=0, i_draws=0, i_losses=0, i_goals_pro=0, i_goals_against=0, i_elo_rating=0, timestamp=tools.get_timestamp_for_now()): self.wins += i_wins self.draws += i_draws self.losses += i_losses self.goals_pro += i_goals_pro self.goals_against += i_goals_against self.elo_rating += i_elo_rating self.timestamp = timestamp
def increment_stats(self, player_id=None, attack_player_id=None, defense_player_id=None, team_id=None, i_wins=0, i_draws=0, i_losses=0, i_goals_pro=0, i_goals_against=0, i_elo_rating=0, timestamp=tools.get_timestamp_for_now()): """ Increment the stats of a player, attacker, defender, or team based by certain values """ cur = self.con.cursor() stats = self.get_all_stats(player_id=player_id, attack_player_id=attack_player_id, defense_player_id=defense_player_id, team_id=team_id, limit=1)[0] stats.update(i_wins=i_wins, i_draws=i_draws, i_losses=i_losses, i_goals_pro=i_goals_pro, i_goals_against=i_goals_against, i_elo_rating=i_elo_rating, timestamp=timestamp) s = """ INSERT INTO stats(player_id, attack_player_id, defense_player_id, team_id, wins, draws, losses, goals_pro, goals_against, elo_rating, timestamp) VALUES(:player_id, :attack_player_id, :defense_player_id, :team_id, :wins, :draws, :losses, :goals_pro, :goals_against, :elo_rating, :timestamp) """ cur.execute(s, stats.__dict__) self.con.commit() stats.stats_id = cur.lastrowid return stats
def games_get_post(): #all_players = db.get_all_players() all_players = db.get_visible_players() if request.method == 'POST': left_defense_player_name = request.form['left_defense_player_name'] left_attack_player_name = request.form['left_attack_player_name'] right_defense_player_name = request.form['right_defense_player_name'] right_attack_player_name = request.form['right_attack_player_name'] timestamp = tools.get_timestamp_for_now() left_team = db.create_team(defense_player=db.get_player_by_name(left_defense_player_name), attack_player=db.get_player_by_name(left_attack_player_name)) right_team = db.create_team(defense_player=db.get_player_by_name(right_defense_player_name), attack_player=db.get_player_by_name(right_attack_player_name)) game = db.create_update_game(timestamp=timestamp, left_team=left_team, right_team=right_team) return redirect(url_for('games_get', timestamp=game.timestamp)) else: all_games = db.get_all_games() return render_template('games.html', players=all_players, games=all_games)
def __init__(self, stats_id=None, player_id=None, attack_player_id=None, defense_player_id=None, team_id=None, wins=0, draws=0, losses=0, goals_pro=0, goals_against=0, elo_rating=elo.INITIAL_RATING, timestamp=tools.get_timestamp_for_now()): self.stats_id = stats_id assert 1 == (player_id is not None) + ( attack_player_id is not None ) + (defense_player_id is not None) + ( team_id is not None ), "Use only one of these (player_id, attacker_id, defender_id, team_id)" self.player_id = player_id self.attack_player_id = attack_player_id self.defense_player_id = defense_player_id self.team_id = team_id self.wins = wins self.draws = draws self.losses = losses self.goals_pro = goals_pro self.goals_against = goals_against self.elo_rating = elo_rating self.timestamp = timestamp