예제 #1
0
def display_vibes(player, day=None):
    """
    Display a player's current vibes

    :param player: Player
    :param day: Game Day to get vibes for, defaults to current day
    :return: vibes str
    """
    if not isinstance(player, Player):
        return

    if not day:
        day = SimulationData.load().day + 1

    vibe = player.get_vibe(day)
    print(vibe_to_string(vibe))
예제 #2
0
def display_team(team, day=None):
    """
    Display a team page similarly to the Blaseball website

    :param team: Team
    :param day: gameday for vibes. defaults to current day
    :return: ipython Display
    """
    if isinstance(team, list):
        if len(team) > 1:
            raise ValueError("Can only display one team at a time")
        team = team[0]

    if isinstance(team, dict):
        if len(team) > 1:
            raise ValueError("Can only display one team at a time")
        team = list(team.values())[0]

    if not isinstance(team, Team):
        raise ValueError("Team is not a team")

    if not day:
        sim = SimulationData.load()
        day = sim.day + 1

    emoji = parse_emoji(team.emoji)

    lineup_html = "".join(
        [_get_player_html(x, day, i, True) for i, x in enumerate(team.lineup)])
    rotation_html = "".join([
        _get_player_html(x, day, i, False) for i, x in enumerate(team.rotation)
    ])

    if getattr(team, "card", None):
        card_html = f"""<div style="margin-top:5px;margin-left:auto;border:1px solid #fff;padding:4px 10px;border-radius:5px;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;color:#fff">
                        {team.card.text}
                    </div>"""
    else:
        card_html = ""

    # ATTRIBUTES
    team_attributes = ""
    if len(team.perm_attr) > 0 or len(team.seas_attr) > 0 or len(
            team.week_attr) > 0 or len(team.game_attr) > 0:
        team_attributes += """<div style="padding:5px 40px;display:flex;flex-direction:row;background:#111;border-bottom:1px solid #fff;">
            <div style="display:flex;flex-direction:row;padding:5px;border-radius:5px;background:#222;">"""
        if len(team.perm_attr) > 0:
            team_attributes += _html_attr(team.perm_attr, "#dbbc0b")
        if len(team.seas_attr) > 0:
            team_attributes += _html_attr(team.seas_attr, "#c2157a")
        if len(team.week_attr) > 0:
            team_attributes += _html_attr(team.week_attr, "#0a78a3")
        if len(team.game_attr) > 0:
            team_attributes += _html_attr(team.game_attr, "#639e47")
        team_attributes += "</div></div>"

    html = f"""
    <div style="width:500px;background:#000;border:1px solid #fff;color:#fff;display:flex;flex-direction:column;box-sizing:border-box;font-size:14px;">
        <div style="padding: 40px 40px 20px;border-bottom:1px solid #fff;">
            <div style="width:100%;display:flex;flex-direction:row;justify-content:flex-start;align-items:center;">
                <div style="background-color:{team.main_color};border-radius:50%;height:60px;width:60px;font-size:36px;display:flex;align-items:center;justify-content:center;flex-shrink:0;">
                    {emoji}
                </div>
                <div style="display:flex;flex-direction:column;margin-left:10px;">
                    <div style="font-size:24px;">
                        {team.full_name}
                    </div>
                    <div>
                        <i>"{team.slogan}"</i>
                    </div>
                    {card_html}
                </div>
            </div>
        </div>
        {team_attributes}
        <div style="padding:20px 40px 20px;">
            <div style="margin-bottom:10px;">
                <div style="font-size:18px;margin-bottom:10px;color:#aaa;text-align:center;">
                    Lineup
                </div>
                <ul style="margin:0;padding:0;width:100%;">
                    {lineup_html}
                </ul>
            </div>
            <div style="margin-bottom:10px;">
                <div style="font-size:18px;margin-bottom:10px;color:#aaa;text-align:center;">
                    Rotation
                </div>
                <ul style="margin:0;padding:0;width:100%;">
                    {rotation_html}
                </ul>
            </div>
        </div>
    </div>
    """

    return HTMLWrapper(html)
예제 #3
0
 def simulation_data_current(self):
     return SimulationData.load()
예제 #4
0
 def simulation_data_s2(self):
     return SimulationData.load_at_time("2020-08-01T12:00:00.000Z")
예제 #5
0
def display_player(player, day=None):
    """
    Display a player page similarly to the Blaseball website

    :param player: Player
    :param day: gameday for vibes. defaults to current day
    :return: ipython Display
    """
    if isinstance(player, list):
        if len(player) > 1:
            raise ValueError("Can only display one player at a time")
        player = player[0]

    if isinstance(player, dict):
        if len(player) > 1:
            raise ValueError("Can only display one player at a time")
        player = list(player.values())[0]

    if not isinstance(player, Player):
        raise ValueError("Player is not a player")

    if not day:
        sim = SimulationData.load()
        day = sim.day + 1

    if getattr(player, "_perm_attr_ids", None):
        retired = "RETIRED" in player._perm_attr_ids

        if retired or "COFFEE_EXIT" in player._perm_attr_ids:
            soul_name = "Soulsong"
        else:
            soul_name = "Soulscream"
    else:
        retired = False
        soul_name = "Soulscream"

    player_team = ""
    if player.league_team and not retired:
        player_team = f"""
            <div style="display:flex;flex-direction:row;justify-content:space-between;align-items:center;margin-bottom:10px;">
                <div style="font-size:18px;display:flex;align-items:center;border-radius:50%;height:30px;width:30px;justify-content:center;flex-shrink:0;background-color:{player.league_team.main_color};">
                    {parse_emoji(player.league_team.emoji)}
                </div>
                <div style="padding:0 10px;">
                    {player.league_team.full_name}
                </div>
            </div>"""

    if retired:
        soul_color = "#5988ff"
    else:
        soul_color = "#F00"

    try:
        vibe = player.get_vibe(day)
    except AttributeError:
        vibe = 0

    if player.deceased:
        player_status = f"""<div style="padding:15px 40px;display:flex;flex-direction:row;justify-content:space-between;align-items:center;background:#111;border-bottom:1px solid #fff;">
            <div style="padding:0 10px;display:flex;align-items:center;font-size:18px;">
                Deceased
            </div>
        </div>"""
    else:
        player_status = ""

    if getattr(player, "ritual", None):
        ritual = player.ritual
    else:
        ritual = "None?"

    if getattr(player, "fate", None):
        fate = player.fate
    else:
        fate = "????"

    # ATTRIBUTES
    player_attributes = ""
    if len(player.perm_attr) > 0 or len(player.seas_attr) > 0 or len(
            player.week_attr) > 0 or len(
                player.game_attr) > 0 or player.bat.attr or player.armor.attr:
        player_attributes += """<div style="padding:5px 40px;display:flex;flex-direction:row;background:#111;border-bottom:1px solid #fff;">
        <div style="display:flex;flex-direction:row;padding:5px;border-radius:5px;background:#222;">"""
        if len(player.perm_attr) > 0:
            player_attributes += _html_attr(player.perm_attr, "#dbbc0b")
        if len(player.seas_attr) > 0:
            player_attributes += _html_attr(player.seas_attr, "#c2157a")
        if len(player.week_attr) > 0:
            player_attributes += _html_attr(player.week_attr, "#0a78a3")
        if len(player.game_attr) > 0:
            player_attributes += _html_attr(player.game_attr, "#639e47")
        if player.bat.attr:
            player_attributes += _html_attr([player.bat.attr], "#bababa")
        if player.armor.attr:
            player_attributes += _html_attr([player.armor.attr], "#bababa")
        player_attributes += "</div></div>"

    html = f"""
    <div style="width:500px;background:#000;border:1px solid #fff;color:#fff;display:flex;flex-direction:column;box-sizing:border-box;font-size:14px;">
        <div style="border-bottom:1px solid #fff;display:flex;flex-direction:column;align-items:flex-start;justify-content:space-between;padding:40px 40px 20px;">
            <div style="font-size:24px;">
                {player.name}
            </div>
            {player_team}
        </div>
        {player_status}
        {player_attributes}
        <div style="padding:20px 0;">
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Current Vibe
                </div>
                <span style="color:{vibe_to_color(vibe)};">
                    {vibe_to_string(vibe)}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;">
                <div style="width:180px;font-weight:700;">
                    Batting
                </div>
                <span>
                    {stars_to_string(player.batting_stars)}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Pitching
                </div>
                <span>
                    {stars_to_string(player.pitching_stars)}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;">
                <div style="width:180px;font-weight:700;">
                    Baserunning
                </div>
                <span>
                    {stars_to_string(player.baserunning_stars)}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Defense
                </div>
                <span>
                    {stars_to_string(player.defense_stars)}
                </span>
            </div>
            <div style="padding:10px;40px;display:flex;flex-direction:row;justify-content:space-around;">
                <div style="display:flex;flex-direction:column;justify-content:space-between;align-items:center;width:auto;min-width:150px;height:80px;margin:5px;padding:10px 0;background:#111;border-radius:5px;">
                    <div style="font-weight:700;">
                        ITEM
                    </div>
                    <div>
                        {player.bat.name}
                    </div>
                </div>
                <div style="display:flex;flex-direction:column;justify-content:space-between;align-items:center;width:auto;min-width:150px;height:80px;margin:5px;padding:10px 0;background:#111;border-radius:5px;">
                    <div style="font-weight:700;">
                        ARMOR
                    </div>
                    <div>
                        {player.armor.name}
                    </div>
                </div>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Evolution
                </div>
                <span>
                    Base
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;">
                <div style="width:180px;font-weight:700;">
                    Pregame Ritual
                </div>
                <span>
                    {ritual}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Coffee Style
                </div>
                <span>
                    {player.coffee}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;">
                <div style="width:180px;font-weight:700;">
                    Blood Type
                </div>
                <span>
                    {player.blood}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;background:rgba(30,30,30,1)">
                <div style="width:180px;font-weight:700;">
                    Fate
                </div>
                <span>
                    {fate}
                </span>
            </div>
            <div style="display:flex;flex-direction:row;align-items:center;padding:2px 40px;">
                <div style="width:180px;font-weight:700;">
                    {soul_name}
                </div>
                <span style="max-width:240px;height:auto;border-radius:5px;font-size:16px;font-weight:700;font-style:italic;word-wrap:break-word;color:{soul_color}">
                    {player.soulscream[0:110]}
                </span>
            </div>
        </div>
    </div>
    """

    return HTMLWrapper(html)
예제 #6
0
pies = Team.load_by_name("Philly Pies")

# Fix Attractors
real_pies = deepcopy(pies)
for p in real_pies.lineup + real_pies.rotation:
    p.batting_rating = None
    p.pitching_rating = None
    p.baserunning_rating = None
    p.defense_rating = None

sim = SimulationData.load()
display(Markdown(f"**Last Updated Season {sim.season}, Day {sim.day}**"))"""

# Check that Notes for the current season do not currently exist
season = SimulationData.load().season
file_name = f"s{season}.ipynb"

if os.path.exists(file_name):
    print(f"Notes for Season {season} already exist, aborting")
    exit(-1)

notes_header = f"""# Season {season} Election Notes

>**FORBIDDEN KNOWLEDGE WARNING**
>
>This document contains some information that is not currently present on the main site and may be considered spoilers.
>Continue at your own discretion. Some information in this document cannot be shared on the Discord without spoiler tags.
"""

# Make new notebook
예제 #7
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))