fixes #169: divisionstandings trims standings display to a single division

This commit is contained in:
Sakimori 2021-02-03 04:00:20 -05:00
parent 28173cd691
commit 1bc8c39068
2 changed files with 52 additions and 2 deletions

View file

@ -331,6 +331,30 @@ class league_structure(object):
this_embed.set_footer(text=f"Standings as of day {self.day-1} / {self.season_length()}")
return this_embed
def standings_embed_div(self, division, div_name):
this_embed = Embed(color=Color.purple(), title=f"{self.name} Season {self.season}")
standings = {}
for team_name, wins, losses, run_diff in league_db.get_standings(self.name):
standings[team_name] = {"wins" : wins, "losses" : losses, "run_diff" : run_diff}
teams = self.division_standings(division, standings)
for index in range(0, len(teams)):
if index == self.constraints["division_leaders"] - 1:
teams[index][4] = "-"
else:
games_behind = ((teams[self.constraints["division_leaders"] - 1][1] - teams[index][1]) + (teams[index][2] - teams[self.constraints["division_leaders"] - 1][2]))/2
teams[index][4] = games_behind
teams_string = ""
for this_team in teams:
if this_team[2] != 0 or this_team[1] != 0:
teams_string += f"**{this_team[0].name}\n**{this_team[1]} - {this_team[2]} WR: {round(this_team[1]/(this_team[1]+this_team[2]), 3)} GB: {this_team[4]}\n\n"
else:
teams_string += f"**{this_team[0].name}\n**{this_team[1]} - {this_team[2]} WR: - GB: {this_team[4]}\n\n"
this_embed.add_field(name=f"{div_name} Division:", value=teams_string, inline = False)
this_embed.set_footer(text=f"Standings as of day {self.day-1} / {self.season_length()}")
return this_embed
def wildcard_embed(self):
this_embed = Embed(color=Color.purple(), title=f"{self.name} Wildcard Race")
standings = {}

View file

@ -877,6 +877,33 @@ class LeagueDisplayCommand(Command):
else:
await msg.channel.send("Can't find that league, boss.")
class LeagueDivisionDisplayCommand(Command):
name = "divisionstandings"
template = "m;divisionstandings [league name]\n[team name]"
description = "Displays the current standings for the given division in the given league."
async def execute(self, msg, command):
if league_exists(command.split("\n")[0].strip()):
league = leagues.load_league_file(command.split("\n")[0].strip())
division_name = command.split("\n")[1].strip()
division = None
for subleague in iter(league.league.keys()):
for div in iter(league.league[subleague].keys()):
if div == division_name:
division = league.league[subleague][div]
if division is None:
await msg.channel.send("Chief, that division doesn't exist in that league.")
return
try:
await msg.channel.send(embed=league.standings_embed_div(division, division_name))
except ValueError:
await msg.channel.send("Give us a proper number, boss.")
#except TypeError:
#await msg.channel.send("That season hasn't been played yet, chief.")
else:
await msg.channel.send("Can't find that league, boss.")
class LeagueWildcardCommand(Command):
name = "leaguewildcard"
template = "m;leaguewildcard [league name]"
@ -1046,6 +1073,7 @@ commands = [
StartLeagueCommand(),
LeaguePauseCommand(),
LeagueDisplayCommand(),
LeagueDivisionDisplayCommand(),
LeagueWildcardCommand(),
LeagueScheduleCommand(),
LeagueTeamScheduleCommand(),
@ -1054,8 +1082,6 @@ commands = [
HelpCommand(),
StartDraftCommand(),
DraftPlayerCommand(),
DebugLeagueStart(),
DebugLeagueDisplay()
]
client = discord.Client()