got leagues actually functioning, i think

This commit is contained in:
Sakimori 2021-01-13 06:32:28 -05:00
parent 0349f45394
commit 8255d838e5
6 changed files with 119 additions and 53 deletions

View File

@ -199,6 +199,7 @@ class team(object):
def finalize(self):
if self.is_ready():
if self.pitcher == None:
self.set_pitcher()
while len(self.lineup) <= 4:
self.lineup.append(random.choice(self.lineup))
@ -363,6 +364,7 @@ class game(object):
run_roll = run_roll * .9 #stealing third is harder
if run_roll < 1:
outcome["steals"].append(f"{baserunner} was caught stealing {base_string(start_base+1)} base by {defender}!")
self.get_pitcher().game_stats["outs_pitched"] += 1
self.outs += 1
else:
outcome["steals"].append(f"{baserunner} steals {base_string(start_base+1)} base!")
@ -687,6 +689,19 @@ class game(object):
players.append((self.teams["away"].pitcher.name, self.teams["away"].pitcher.game_stats))
return players
def get_team_specific_stats(self):
players = {
self.teams["away"].name : [],
self.teams["home"].name : []
}
for this_player in self.teams["away"].lineup:
players[self.teams["away"].name].append((this_player.name, this_player.game_stats))
for this_player in self.teams["home"].lineup:
players[self.teams["home"].name].append((this_player.name, this_player.game_stats))
players[self.teams["home"].name].append((self.teams["home"].pitcher.name, self.teams["home"].pitcher.game_stats))
players[self.teams["away"].name].append((self.teams["away"].pitcher.name, self.teams["away"].pitcher.game_stats))
return players
def random_star_gen(key, player):

View File

@ -8,7 +8,10 @@ def create_connection(league_name):
#create connection, create db if doesn't exist
conn = None
try:
conn = sql.connect(os.path.join(data_dir, league_dir, f"{league_name}.db"))
if not os.path.exists(os.path.join(data_dir, league_dir, league_name)):
os.makedirs(os.path.join(data_dir, league_dir, league_name))
conn = sql.connect(os.path.join(data_dir, league_dir, league_name, f"{league_name}.db"))
# enable write-ahead log for performance and resilience
conn.execute('pragma journal_mode=wal')
@ -19,7 +22,9 @@ def create_connection(league_name):
return conn
def state(league_name):
with open(os.path.join(data_dir, league_dir, f"{league_name}.state")) as state_file:
if not os.path.exists(os.path.dirname(os.path.join(data_dir, league_dir, league_name, f"{league_name}.state"))):
os.makedirs(os.path.dirname(os.path.join(data_dir, league_dir, league_name, f"{league_name}.state")))
with open(os.path.join(data_dir, league_dir, league_name, f"{league_name}.state")) as state_file:
return json.load(state_file)
def init_league_db(league):
@ -75,7 +80,9 @@ def init_league_db(league):
"games_per_hour" : league.games_per_hour,
"historic" : False
}
with open(os.path.join(data_dir, league_dir, f"{league.name}.state"), "w") as state_file:
if not os.path.exists(os.path.dirname(os.path.join(data_dir, league_dir, league.name, f"{league.name}.state"))):
os.makedirs(os.path.dirname(os.path.join(data_dir, league_dir, league.name, f"{league.name}.state")))
with open(os.path.join(data_dir, league_dir, league.name, f"{league.name}.state"), "w") as state_file:
json.dump(state_dic, state_file, indent=4)
conn.commit()
@ -85,18 +92,19 @@ def add_stats(league_name, player_game_stats_list):
conn = create_connection(league_name)
if conn is not None:
c=conn.cursor()
for (name, player_stats_dic) in player_game_stats_list:
c.execute("SELECT * FROM stats WHERE name=?",(name,))
for team_name in player_game_stats_list.keys():
for (name, player_stats_dic) in player_game_stats_list[team_name]:
c.execute("SELECT * FROM stats WHERE name=? AND team_name=?",(name, team_name))
this_player = c.fetchone()
if this_player is not None:
for stat in player_stats_dic.keys():
c.execute(f"SELECT {stat} FROM stats WHERE name=?",(name,))
c.execute(f"SELECT {stat} FROM stats WHERE name=? AND team_name=?",(name, team_name))
old_value = int(c.fetchone()[0])
c.execute(f"UPDATE stats SET {stat} = ? WHERE name=?",(player_stats_dic[stat]+old_value,name))
c.execute(f"UPDATE stats SET {stat} = ? WHERE name=? AND team_name=?",(player_stats_dic[stat]+old_value, name, team_name))
else:
c.execute("INSERT INTO stats(name) VALUES (?)",(name,))
for stat in player_stats_dic.keys():
c.execute(f"UPDATE stats SET {stat} = ? WHERE name=?",(player_stats_dic[stat],name))
c.execute(f"UPDATE stats SET {stat} = ? WHERE name=? AND team_name=?",(player_stats_dic[stat], name, team_name))
conn.commit()
conn.close()
@ -118,7 +126,7 @@ def update_standings(league_name, update_dic):
def league_exists(league_name):
with os.scandir(os.path.join(data_dir, league_dir)) as folder:
for file in folder:
if file.name == f"{league_name}.state":
for subfolder in folder:
if league_name in subfolder.name:
return not state(league_name)["historic"]
return False

View File

@ -25,15 +25,18 @@ class league_structure(object):
self.active = False
self.games_per_hour = games_per_hour
def add_stats_from_game(self, players_list):
league_db.add_stats(players_list)
def add_stats_from_game(self, players_dic):
league_db.add_stats(self.name, players_dic)
def update_standings(self, results_dic):
league_db.update_standings(self.name, results_dic)
def last_series_check(self):
return self.day + 1 in self.schedule.keys()
return str(math.ceil((self.day)/self.series_length) + 1) in self.schedule.keys()
def day_to_series_num(self, day):
return math.ceil((self.day)/self.series_length)
def find_team(self, team_name):
for subleague in iter(self.league.keys()):
@ -282,7 +285,7 @@ class bracket(object):
def save_league(this_league):
if not league_db.league_exists(this_league.name):
league_db.init_league_db(this_league)
with open(os.path.join(data_dir, league_dir, f"{this_league.name}.league"), "w") as league_file:
with open(os.path.join(data_dir, league_dir, this_league.name, f"{this_league.name}.league"), "w") as league_file:
league_json_string = jsonpickle.encode(this_league.league, keys=True)
json.dump(league_json_string, league_file, indent=4)
return True
@ -291,8 +294,8 @@ def load_league_file(league_name):
if league_db.league_exists(league_name):
state = league_db.state(league_name)
this_league = league_structure(league_name)
with open(os.path.join(data_dir, league_dir, f"{this_league.name}.league")) as league_file:
with open(os.path.join(data_dir, league_dir, league_name, f"{this_league.name}.league")) as league_file:
this_league.league = jsonpickle.decode(json.load(league_file), keys=True, classes=team)
with open(os.path.join(data_dir, league_dir, f"{this_league.name}.state")) as state_file:
with open(os.path.join(data_dir, league_dir, league_name, f"{this_league.name}.state")) as state_file:
state_dic = json.load(state_file)
return this_league

View File

@ -1974,6 +1974,7 @@
"version": "7.29.1",
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.29.1.tgz",
"integrity": "sha512-6BU7vAjKuMspCy9QQEtbWgmkuXi/yOSZo3ANdvZmNQW8N/WQGjO9cvlcA5EFJaPtp2hL1RAaPGpCXxumijUxCg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.10.4",
"@babel/runtime": "^7.12.5",
@ -1989,6 +1990,7 @@
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
@ -1997,6 +1999,7 @@
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
@ -2006,6 +2009,7 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
@ -2013,17 +2017,20 @@
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
@ -2034,6 +2041,7 @@
"version": "5.11.8",
"resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.11.8.tgz",
"integrity": "sha512-ScyKrWQM5xNcr79PkSewnA79CLaoxVskE+f7knTOhDD9ftZSA1Jw8mj+pneqhEu3x37ncNfW84NUr7lqK+mXjA==",
"dev": true,
"requires": {
"@babel/runtime": "^7.9.2",
"@types/testing-library__jest-dom": "^5.9.1",
@ -2049,6 +2057,7 @@
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
@ -2057,6 +2066,7 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
"integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
@ -2066,6 +2076,7 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
@ -2073,12 +2084,14 @@
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"css": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/css/-/css-3.0.0.tgz",
"integrity": "sha512-DG9pFfwOrzc+hawpmqX/dHYHJG+Bsdb0klhyi1sDneOgGOXy9wQIC8hzyVp1e4NRYDBdxcylvywPkkXCHAzTyQ==",
"dev": true,
"requires": {
"inherits": "^2.0.4",
"source-map": "^0.6.1",
@ -2088,17 +2101,20 @@
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"source-map-resolve": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.6.0.tgz",
"integrity": "sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w==",
"dev": true,
"requires": {
"atob": "^2.1.2",
"decode-uri-component": "^0.2.0"
@ -2108,6 +2124,7 @@
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
@ -2118,6 +2135,7 @@
"version": "11.2.2",
"resolved": "https://registry.npmjs.org/@testing-library/react/-/react-11.2.2.tgz",
"integrity": "sha512-jaxm0hwUjv+hzC+UFEywic7buDC9JQ1q3cDsrWVSDAPmLotfA6E6kUHlYm/zOeGCac6g48DR36tFHxl7Zb+N5A==",
"dev": true,
"requires": {
"@babel/runtime": "^7.12.5",
"@testing-library/dom": "^7.28.1"
@ -2127,6 +2145,7 @@
"version": "12.6.0",
"resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-12.6.0.tgz",
"integrity": "sha512-FNEH/HLmOk5GO70I52tKjs7WvGYckeE/SrnLX/ip7z2IGbffyd5zOUM1tZ10vsTphqm+VbDFI0oaXu0wcfQsAQ==",
"dev": true,
"requires": {
"@babel/runtime": "^7.12.5"
}
@ -2139,7 +2158,8 @@
"@types/aria-query": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.0.tgz",
"integrity": "sha512-iIgQNzCm0v7QMhhe4Jjn9uRh+I6GoPmt03CbEtwx3ao8/EfoQcmgtqH4vQ5Db/lxiIGaWDv6nwvunuh0RyX0+A=="
"integrity": "sha512-iIgQNzCm0v7QMhhe4Jjn9uRh+I6GoPmt03CbEtwx3ao8/EfoQcmgtqH4vQ5Db/lxiIGaWDv6nwvunuh0RyX0+A==",
"dev": true
},
"@types/babel__core": {
"version": "7.1.12",
@ -2217,7 +2237,8 @@
"@types/history": {
"version": "4.7.8",
"resolved": "https://registry.npmjs.org/@types/history/-/history-4.7.8.tgz",
"integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA=="
"integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==",
"dev": true
},
"@types/html-minifier-terser": {
"version": "5.1.1",
@ -2249,6 +2270,7 @@
"version": "26.0.19",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.19.tgz",
"integrity": "sha512-jqHoirTG61fee6v6rwbnEuKhpSKih0tuhqeFbCmMmErhtu3BYlOZaXWjffgOstMM4S/3iQD31lI5bGLTrs97yQ==",
"dev": true,
"requires": {
"jest-diff": "^26.0.0",
"pretty-format": "^26.0.0"
@ -2292,7 +2314,8 @@
"@types/prop-types": {
"version": "15.7.3",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz",
"integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw=="
"integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==",
"dev": true
},
"@types/q": {
"version": "1.5.4",
@ -2303,6 +2326,7 @@
"version": "16.14.2",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.2.tgz",
"integrity": "sha512-BzzcAlyDxXl2nANlabtT4thtvbbnhee8hMmH/CcJrISDBVcJS1iOsP1f0OAgSdGE0MsY9tqcrb9YoZcOFv9dbQ==",
"dev": true,
"requires": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@ -2312,6 +2336,7 @@
"version": "16.9.10",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.10.tgz",
"integrity": "sha512-ItatOrnXDMAYpv6G8UCk2VhbYVTjZT9aorLtA/OzDN9XJ2GKcfam68jutoAcILdRjsRUO8qb7AmyObF77Q8QFw==",
"dev": true,
"requires": {
"@types/react": "^16"
}
@ -2320,6 +2345,7 @@
"version": "5.1.10",
"resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-5.1.10.tgz",
"integrity": "sha512-yu11Hu16CfGvvBWc7wluRlxbwfuSlY0snEntbbOTvfgMvyO6uLaEpAbnVOntr+9TNIpR++OOlPkmDcJPxOXRaQ==",
"dev": true,
"requires": {
"@types/history": "*",
"@types/react": "*"
@ -2329,6 +2355,7 @@
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-5.1.7.tgz",
"integrity": "sha512-D5mHD6TbdV/DNHYsnwBTv+y73ei+mMjrkGrla86HthE4/PVvL1J94Bu3qABU+COXzpL23T1EZapVVpwHuBXiUg==",
"dev": true,
"requires": {
"@types/history": "*",
"@types/react": "*",
@ -2346,7 +2373,8 @@
"@types/socket.io-client": {
"version": "1.4.34",
"resolved": "https://registry.npmjs.org/@types/socket.io-client/-/socket.io-client-1.4.34.tgz",
"integrity": "sha512-Lzia5OTQFJZJ5R4HsEEldywiiqT9+W2rDbyHJiiTGqOcju89sCsQ8aUXDljY6Ls33wKZZGC0bfMhr/VpOyjtXg=="
"integrity": "sha512-Lzia5OTQFJZJ5R4HsEEldywiiqT9+W2rDbyHJiiTGqOcju89sCsQ8aUXDljY6Ls33wKZZGC0bfMhr/VpOyjtXg==",
"dev": true
},
"@types/source-list-map": {
"version": "0.1.2",
@ -2367,6 +2395,7 @@
"version": "5.9.5",
"resolved": "https://registry.npmjs.org/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.9.5.tgz",
"integrity": "sha512-ggn3ws+yRbOHog9GxnXiEZ/35Mow6YtPZpd7Z5mKDeZS/o7zx3yAle0ov/wjhVB5QT4N2Dt+GNoGCdqkBGCajQ==",
"dev": true,
"requires": {
"@types/jest": "*"
}
@ -2374,7 +2403,8 @@
"@types/twemoji": {
"version": "12.1.1",
"resolved": "https://registry.npmjs.org/@types/twemoji/-/twemoji-12.1.1.tgz",
"integrity": "sha512-dW1B1WHTfrWmEzXb/tp8xsZqQHAyMB9JwLwbBqkIQVzmNUI02R7lJqxUpKFM114ygNZHKA1r74oPugCAiYHt1A=="
"integrity": "sha512-dW1B1WHTfrWmEzXb/tp8xsZqQHAyMB9JwLwbBqkIQVzmNUI02R7lJqxUpKFM114ygNZHKA1r74oPugCAiYHt1A==",
"dev": true
},
"@types/uglify-js": {
"version": "3.11.1",
@ -4598,7 +4628,8 @@
"css.escape": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz",
"integrity": "sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s="
"integrity": "sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s=",
"dev": true
},
"cssdb": {
"version": "4.4.0",
@ -4769,7 +4800,8 @@
"csstype": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.5.tgz",
"integrity": "sha512-uVDi8LpBUKQj6sdxNaTetL6FpeCqTjOvAQuQUa/qAqq8oOd4ivkbhgnqayl0dnPal8Tb/yB1tF+gOvCBiicaiQ=="
"integrity": "sha512-uVDi8LpBUKQj6sdxNaTetL6FpeCqTjOvAQuQUa/qAqq8oOd4ivkbhgnqayl0dnPal8Tb/yB1tF+gOvCBiicaiQ==",
"dev": true
},
"cyclist": {
"version": "1.0.1",
@ -5090,7 +5122,8 @@
"dom-accessibility-api": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.4.tgz",
"integrity": "sha512-TvrjBckDy2c6v6RLxPv5QXOnU+SmF9nBII5621Ve5fu6Z/BDrENurBEvlC1f44lKEUVqOpK4w9E5Idc5/EgkLQ=="
"integrity": "sha512-TvrjBckDy2c6v6RLxPv5QXOnU+SmF9nBII5621Ve5fu6Z/BDrENurBEvlC1f44lKEUVqOpK4w9E5Idc5/EgkLQ==",
"dev": true
},
"dom-converter": {
"version": "0.2.0",
@ -9818,7 +9851,8 @@
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=",
"dev": true
},
"magic-string": {
"version": "0.25.7",
@ -9994,7 +10028,8 @@
"min-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg=="
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==",
"dev": true
},
"mini-create-react-context": {
"version": "0.4.1",
@ -12670,6 +12705,7 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
"integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==",
"dev": true,
"requires": {
"indent-string": "^4.0.0",
"strip-indent": "^3.0.0"
@ -14279,6 +14315,7 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz",
"integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==",
"dev": true,
"requires": {
"min-indent": "^1.0.0"
}

View File

@ -738,10 +738,10 @@ class DebugLeague(Command):
"aL west" : [get_team_fuzzy_search("deep space"), get_team_fuzzy_search("phoenix")],
"aL east" : [get_team_fuzzy_search("cheyenne mountain"), get_team_fuzzy_search("tarot dragons")]
}
}, division_games=6, inter_division_games=3, inter_league_games=3)
}, division_games=6, inter_division_games=3, inter_league_games=3, games_per_hour = 12)
league.generate_schedule()
leagues.save_league(league)
await start_league_day(msg.channel, league, 2)
await start_league_day(msg.channel, league, autoplay = 1)
@ -1407,10 +1407,8 @@ def get_team_fuzzy_search(team_name):
async def start_league_day(channel, league, autoplay = 1):
current_games = []
if league.schedule is {}:
league.generate_schedule()
games_to_start = league.schedule[math.ceil(league.day/league.series_length)]
games_to_start = league.schedule[league.day_to_series_num(league.day)]
if league.game_length is None:
game_length = games.config()["default_length"]
else:
@ -1419,7 +1417,9 @@ async def start_league_day(channel, league, autoplay = 1):
for pair in games_to_start:
if pair[0] is not None and pair[1] is not None:
away = get_team_fuzzy_search(pair[0])
away.set_pitcher(rotation_slot=league.day-1)
home = get_team_fuzzy_search(pair[1])
this_game = games.game(away.prepare_for_save().finalize(), home.prepare_for_save().finalize(), length = game_length)
this_game, state_init = prepare_game(this_game)
@ -1459,10 +1459,12 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
game, key = games_list[i]
if game.over and main_controller.master_games_dic[key][1]["end_delay"] <= 8:
if game.teams['home'].name not in series_results.keys():
series_results[game.teams["home"].name] = {}
series_results[game.teams["home"].name]["wins"] = 0
series_results[game.teams["home"].name]["losses"] = 0
series_results[game.teams["home"].name]["run_diff"] = 0
if game.teams['away'].name not in series_results.keys():
series_results[game.teams["away"].name] = {}
series_results[game.teams["away"].name]["wins"] = 0
series_results[game.teams["away"].name]["losses"] = 0
series_results[game.teams["away"].name]["run_diff"] = 0
@ -1476,7 +1478,7 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
series_results[loser_name]["losses"] += 1
series_results[loser_name]["run_diff"] -= rd
league.add_stats_from_game(game.get_stats())
league.add_stats_from_game(game.get_team_specific_stats())
final_embed = game_over_embed(game)
await channel.send(f"A {league.name} game just ended!")
@ -1487,8 +1489,8 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
break
except:
print("something went wrong in league_day_watcher")
await asyncio.sleep(4)
await asyncio.sleep(1)
league.day += 1
if len(queued_games) > 0:
@ -1502,7 +1504,7 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
else:
delta = datetime.timedelta(minutes= (60 - now.minute))
next_start = (now + delta).replace(seconds=0, microsecond=0)
next_start = (now + delta).replace(microsecond=0)
wait_seconds = (next_start - now).seconds
@ -1515,7 +1517,6 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
league.update_standings(series_results)
league.day += 1
if last or autoplay <= 0: #if this series was the last of the season OR number of series to autoplay has been reached
#needs some kind of notification that it's over here
@ -1532,7 +1533,7 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
else:
delta = datetime.timedelta(minutes= (60 - now.minute))
next_start = (now + delta).replace(seconds=0, microsecond=0)
next_start = (now + delta).replace(microsecond=0)
wait_seconds = (next_start - now).seconds
await channel.send(f"""This {league.name} series is now complete! The next series will be starting in {int(wait_seconds/60)} minutes.""")
@ -1540,11 +1541,13 @@ async def league_day_watcher(channel, league, games_list, filter_url, autoplay,
await start_league_day(channel, league, autoplay)
async def continue_league_series(tourney, queue, games_list, series_results):
async def continue_league_series(league, queue, games_list, series_results):
for oldgame in queue:
away_team = games.get_team(oldgame.teams["away"].name)
away_team.set_pitcher(rotation_slot=league.day)
home_team = games.get_team(oldgame.teams["home"].name)
this_game = games.game(away_team.finalize(), home_team.finalize(), length = tourney.game_length)
home_team.set_pitcher(rotation_slot=league.day)
this_game = games.game(away_team.finalize(), home_team.finalize(), length = league.game_length)
this_game, state_init = prepare_game(this_game)
state_init["is_league"] = True