def draft_player(): """Draft player to a team""" if request.method == 'POST': player = Player.get(Player.id == request.form['player_id']) team = Team.get(Team.id == request.form['team_id']) _draft_player(player, team) return '', 204
def setUp(self): db.init(':memory:') classes = [Team, League, Season, Person, Player, PlayerStats] db.create_tables(classes) for class_ in classes: if class_.__name__ not in PMDataObject.deferred_relations: PMDataObject.deferred_relations[class_.__name__] = class_ self.league = League.create(name="Band Battle") self.season = Season.create(league=self.league, start_year=2016, end_year=2017, is_current=True) self.team = Team.create(name="Sex Bob-omb", city="Toronto", skill=90, abbreviation="TOR", league=self.league) self.person = Person.create(forename="Scott", surname="Pilgrim") self.player = Player.create(person=self.person, team=self.team, position="F", scoring_rate=12.0, shot_rate=12.0, ) self.stats = PlayerStats.create(player=self.player, season=self.season, team=self.team)
def index(): """the main screen for the game""" ranked_teams = sorted(app.league.teams, key=lambda x: x.current_season_stats().wins * 2 + x.current_season_stats().ties, reverse=True) top_scorers = list(PlayerStats.select().join(Season).where(Season.is_current == True, Season.league == app.league)) top_scorers = sorted(top_scorers, key=lambda x: x.goals + x.assists, reverse=True)[:10] goalies = Player.select().where(Player.position == 'G') goalie_stats = list(PlayerStats.select().join(Season).where(Season.is_current == True, Season.league == app.league, PlayerStats.player << goalies)) return render_template("index.html", teams=ranked_teams, top_scorers=top_scorers, top_goalies=goalie_stats)
def generate(self): name = self.name_generator.generate() position = self.position_generator.generate() person = Person.create_from_name(name) person.save() scoring_rate = normal(loc=0.085, scale=0.02) if scoring_rate < 0.0: scoring_rate = 0.0 shot_rate = normal(loc=6.0, scale=2.5) if shot_rate < 0.0: shot_rate = 0.0 return Player.create(person=person, position=position, scoring_rate=scoring_rate, shot_rate=shot_rate)
def draft(): """Assign players to teams via draft""" teams = list(app.league.teams) players = list(Player.select().where(Player.team >> None)) if not players: app.drafting_team = None return redirect(url_for('index')) if app.drafting_team is None: random.shuffle(teams) app.drafting_team = cycle(teams) current_team = next(app.drafting_team) while current_team.name != 'Icee' and players: drafted_player = random.choice(players) players.remove(drafted_player) _draft_player(drafted_player, current_team) current_team = next(app.drafting_team) return render_template("draft.html", players=players, team=current_team, draft_name="Fantasy Draft")
def setUp(self): db.init(':memory:') classes = [Team, League, Season, PlayerStats, Person, Player] db.create_tables(classes) for class_ in classes: if class_.__name__ not in PMDataObject.deferred_relations: PMDataObject.deferred_relations[class_.__name__] = class_ self.league = League.create(name="NHL") self.team = Team.create(name="Canucks", city="Vancouver", skill=100, abbreviation="VAN", league=self.league) self.person = Person.create_from_name(name=Name(forename = "Cliff", surname = "Ronning")) self.player = Player.create(person=self.person, team = self.team, position = "C", scoring_rate=0.07, shot_rate=6) self.season = Season.create(league=self.league, start_year=2016, end_year=2017, is_current=True)
def show_player_card(player_id): """Shows player card for a player""" player = Player.get(Player.id == player_id) return render_template("player_card.html", player=player)
def list_players(): """Lists all players in the league universe""" return render_template("player_view.html", players = Player.select())