diff --git a/games.py b/games.py index 5a314c3..69d1d16 100644 --- a/games.py +++ b/games.py @@ -829,7 +829,7 @@ def base_string(base): elif base == 3: return "third" elif base == 4: - return "fourth" + return "None" class weather(object): name = "Sunny" diff --git a/leagues.py b/leagues.py index 96ab48e..5e85f61 100644 --- a/leagues.py +++ b/leagues.py @@ -154,6 +154,7 @@ class league_structure(object): a_home = not a_home for i in range(0, self.constraints["inter_div_games"]): #inter-division matchups + extra_teams = [] for subleague in league.keys(): division_max = 1 divisions = [] @@ -164,10 +165,7 @@ class league_structure(object): last_div = None if len(divisions) % 2 != 0: - if division_max % 2 != 0: - divisions.append(["OFF" for i in range(0, division_max)]) - else: - last_div = divisions.pop() + last_div = divisions.pop() divs_a = list(chain(divisions[int(len(divisions)/2):]))[0] if last_div is not None: @@ -179,6 +177,11 @@ class league_structure(object): divs_a.extend(last_div[:int(len(last_div)/2)]) random.shuffle(divs_b) + if len(divs_a) % 2 != 0: + extra_teams.append(divs_a.pop()) + if len(divs_b) % 2 != 0: + extra_teams.append(divs_b.pop()) + a_home = True for team_a, team_b in zip(divs_a, divs_b): if a_home: @@ -187,6 +190,11 @@ class league_structure(object): matchups.append([team_a.name, team_b.name]) a_home = not a_home + if extra_teams != []: + if len(extra_teams) % 2 == 0: + for index in range(0, int(len(extra_teams)/2)): + matchups.append(extra_teams[index], extra_teams[index+1]) + for subleague in league.keys(): for division in league[subleague].values(): #generate round-robin matchups diff --git a/sql scripts/batting average leaders.sql b/sql scripts/batting average leaders.sql index e731e6d..acea05f 100644 --- a/sql scripts/batting average leaders.sql +++ b/sql scripts/batting average leaders.sql @@ -1,8 +1,8 @@ -SELECT name, +SELECT name, team_name, plate_appearances - (walks_taken + sacrifices) as atbats, ROUND(hits*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as average, ROUND(total_bases*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as slg, ROUND((walks_taken + hits)*1.0/plate_appearances*1.0,3) as obp, ROUND((walks_taken + hits)*1.0/plate_appearances*1.0,3) + ROUND(total_bases*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as ops FROM stats WHERE plate_appearances > 50 -ORDER BY ops DESC; \ No newline at end of file +ORDER BY average DESC; \ No newline at end of file diff --git a/sql scripts/pitching leaders.sql b/sql scripts/era leaders.sql similarity index 89% rename from sql scripts/pitching leaders.sql rename to sql scripts/era leaders.sql index 27bda9c..46cc7dd 100644 --- a/sql scripts/pitching leaders.sql +++ b/sql scripts/era leaders.sql @@ -1,4 +1,4 @@ -SELECT name, +SELECT name, team_name, outs_pitched, ROUND(runs_allowed*27.0/(outs_pitched*1.0),3) as era, ROUND((walks_allowed+hits_allowed)*3.0/(outs_pitched*1.0),3) as whip, diff --git a/sql scripts/ops leaders.sql b/sql scripts/ops leaders.sql new file mode 100644 index 0000000..d6df9e4 --- /dev/null +++ b/sql scripts/ops leaders.sql @@ -0,0 +1,8 @@ +SELECT name, team_name, + plate_appearances - (walks_taken + sacrifices) as atbats, + ROUND(hits*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as average, + ROUND(total_bases*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as slg, + ROUND((walks_taken + hits)*1.0/plate_appearances*1.0,3) as obp, + ROUND((walks_taken + hits)*1.0/plate_appearances*1.0,3) + ROUND(total_bases*1.0 / (plate_appearances - (walks_taken + sacrifices)*1.0),3) as ops +FROM stats WHERE plate_appearances > 50 +ORDER BY ops DESC; \ No newline at end of file diff --git a/sql scripts/sql scripts.zip b/sql scripts/sql scripts.zip new file mode 100644 index 0000000..756b852 Binary files /dev/null and b/sql scripts/sql scripts.zip differ diff --git a/sql scripts/strikeouts per walks leaders.sql b/sql scripts/strikeouts per walks leaders.sql new file mode 100644 index 0000000..7410477 --- /dev/null +++ b/sql scripts/strikeouts per walks leaders.sql @@ -0,0 +1,9 @@ +SELECT name, team_name, + outs_pitched, + ROUND(runs_allowed*27.0/(outs_pitched*1.0),3) as era, + ROUND((walks_allowed+hits_allowed)*3.0/(outs_pitched*1.0),3) as whip, + ROUND(walks_allowed*27.0/(outs_pitched*1.0),3) as bbper9, + ROUND(strikeouts_given*27.0/(outs_pitched*1.0),3) as kper9, + ROUND(strikeouts_given*1.0/walks_allowed*1.0,3) as kperbb +FROM stats WHERE outs_pitched > 150 +ORDER BY kperbb ASC; \ No newline at end of file diff --git a/sql scripts/whip leaders.sql b/sql scripts/whip leaders.sql new file mode 100644 index 0000000..28b6a4d --- /dev/null +++ b/sql scripts/whip leaders.sql @@ -0,0 +1,9 @@ +SELECT name, team_name, + outs_pitched, + ROUND(runs_allowed*27.0/(outs_pitched*1.0),3) as era, + ROUND((walks_allowed+hits_allowed)*3.0/(outs_pitched*1.0),3) as whip, + ROUND(walks_allowed*27.0/(outs_pitched*1.0),3) as bbper9, + ROUND(strikeouts_given*27.0/(outs_pitched*1.0),3) as kper9, + ROUND(strikeouts_given*1.0/walks_allowed*1.0,3) as kperbb +FROM stats WHERE outs_pitched > 150 +ORDER BY whip ASC; \ No newline at end of file diff --git a/the_prestige.py b/the_prestige.py index dd4d13c..c91853c 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -443,6 +443,45 @@ class RemovePlayerCommand(Command): except IndexError: await msg.channel.send("Three lines, remember? Command, then team, then name.") +class ReplacePlayerCommand(Command): + name = "replaceplayer" + template = """m;replaceplayer + [team name] + [player name to **remove**] + [player name to **add**]""" + description = "Replaces a player on your team. If there are multiple copies of the same player on a team this will only replace the first one. Requires team ownership and exact spelling of team name." + + async def execute(self, msg, command): + try: + team_name = command.split("\n")[1].strip() + remove_name = command.split("\n")[2].strip() + add_name = command.split("\n")[3].strip() + team, owner_id = games.get_team_and_owner(team_name) + if owner_id != msg.author.id and msg.author.id not in config()["owners"]: + await msg.channel.send("You're not authorized to mess with this team. Sorry, boss.") + return + + old_player, old_pos, old_list = team.find_player(remove_name) + new_player = games.player(ono.get_stats(add_name)) + + if old_player is None: + await msg.channel.send("We've got bad news: that player isn't on your team. The good news is that... that player isn't on your team?") + return + + else: + if old_list == team.lineup: + team.delete_player(remove_name) + team.add_lineup(new_player) + team.slide_player(add_name, old_pos+1) + else: + team.delete_player(remove_name) + team.add_pitcher(new_player) + team.slide_player(add_name, old_pos+1) + await msg.channel.send(embed=build_team_embed(team)) + games.update_team(team) + await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.") + except IndexError: + await msg.channel.send("Four lines, remember? Command, then team, then the two names.") class HelpCommand(Command): name = "help" @@ -807,6 +846,7 @@ Plays a league with a given name, provided that league has been saved on the web if league_exists(league_name): league = leagues.load_league_file(league_name) if "--noautopostseason" in command: + await msg.channel.send("Automatic postseason disabled.") autoplay = int(list(league.schedule.keys())[-1]) - league.day_to_series_num(league.day) + 1 if league.historic: @@ -874,7 +914,7 @@ class LeagueWildcardCommand(Command): class LeaguePauseCommand(Command): name = "pauseleague" template = "m;pauseleague [league name]" - descripton = "Tells a currently running league to stop running automatically after the current series." + description = "Tells a currently running league to stop running automatically after the current series." async def execute(self, msg, command): league_name = command.strip() @@ -970,6 +1010,7 @@ commands = [ MovePlayerCommand(), AddPlayerCommand(), RemovePlayerCommand(), + ReplacePlayerCommand(), DeleteTeamCommand(), ShowTeamCommand(), ShowAllTeamsCommand(),