Exemplo n.º 1
0
 def __init__(self, data, parent):
     super().__init__(data, parent)
     self.teams = {team['id']: Team(team) for team in data.get('teams', {})}
     self.subleagues = {
         sl['id']: Subleague(sl)
         for sl in data.get('subleagues', {})
     }
     self.divisions = {
         d['id']: Division(d)
         for d in data.get('divisions', {})
     }
     self.leagues = {l['id']: League(l) for l in data.get('leagues', {})}
Exemplo n.º 2
0
 def league_current(self):
     return League.load()
Exemplo n.º 3
0
 def test_load_by_id_bad_id(self):
     with pytest.raises(ValueError):
         bad_id = League.load_by_id("00000000-0000-0000-0000-000000000000")
Exemplo n.º 4
0
 def test_load_by_id(self):
     league = League.load_by_id("d8545021-e9fc-48a3-af74-48685950a183")
     assert isinstance(league, League)
Exemplo n.º 5
0
def league_teams():
    """
    Get list of all league teams
    """
    return League.load().teams
Exemplo n.º 6
0
def generate_file(filename, inactive, archive, include_items, unscattered):
    sim = SimulationData.load()
    if archive and os.path.isfile(filename):
        os.rename(
            filename,
            filename.replace(".csv",
                             "S{}preD{}.csv".format(sim.season, sim.day + 1)),
        )
    output = []
    positions = (("lineup", "rotation", "shadows") if inactive else
                 ("lineup", "rotation"))
    league = League.load()
    players = Player.load_all()
    for subleague in league.subleagues.values():
        for division in subleague.divisions.values():
            for team in division.teams.values():
                for position in positions:
                    for turn_order, player_id in enumerate(
                            getattr(team, "_{}_ids".format(position))):
                        player = players[player_id]
                        if include_items:
                            player = adjust_stlats_for_items(player)
                        player_row = [
                            team.full_name,
                            subleague.name,
                            division.name,
                            player.name if not unscattered
                            or "unscatteredName" not in player.state else
                            player.state["unscatteredName"],
                            position,
                            turn_order + 1,
                            player.id,
                            player.anticapitalism,
                            player.base_thirst,
                            player.buoyancy,
                            player.chasiness,
                            player.coldness,
                            player.continuation,
                            player.divinity,
                            player.ground_friction,
                            player.indulgence,
                            player.laserlikeness,
                            player.martyrdom,
                            player.moxie,
                            player.musclitude,
                            player.bat.id or "",
                            player.omniscience,
                            player.overpowerment,
                            player.patheticism,
                            player.ruthlessness,
                            player.shakespearianism,
                            player.suppression,
                            player.tenaciousness,
                            player.thwackability,
                            player.tragicness,
                            player.unthwackability,
                            player.watchfulness,
                            player.pressurization,
                            player.total_fingers,
                            player.soul,
                            player.deceased,
                            player.peanut_allergy,
                            player.cinnamon,
                            player.fate,
                            player.armor.id or "",
                            player.ritual,
                            player._blood_id,
                            player._coffee_id,
                            ";".join(attr.id for attr in player.perm_attr +
                                     player.item_attr),
                            ";".join(attr.id for attr in player.seas_attr),
                            ";".join(attr.id for attr in player.week_attr),
                            ";".join(attr.id for attr in player.game_attr),
                            player.batting_rating * 5.0,
                            player.pitching_rating * 5.0,
                            player.baserunning_rating * 5.0,
                            player.defense_rating * 5.0,
                        ]
                        output.append(player_row)
    output.sort(key=operator.itemgetter(0, 4, 5))
    with open(filename, "w") as f:
        f.write("{}\n".format(",".join('"{}"'.format(col) for col in COLUMNS)))
        f.write("\n".join(",".join(['"{}"'.format(d) for d in datarow])
                          for datarow in output))