Local db to Postgresql
This commit is contained in:
parent
8be5e94536
commit
f6bae8c208
@ -227,6 +227,21 @@ class Gameplay(commands.Cog):
|
||||
|
||||
await self.post_play(session, interaction, next_play, buffer_message)
|
||||
|
||||
@commands.command(name='test-write', help='Test concurrent db writes', hidden=True)
|
||||
@commands.is_owner()
|
||||
async def test_write_command(self, ctx):
|
||||
await ctx.send(f'I am going to open a connection, delay, then try to write')
|
||||
with Session(engine) as session:
|
||||
ncb_team = await get_team_or_none(session, team_id=31)
|
||||
await ctx.send(f'The {ncb_team.lname} has_guide value is: {ncb_team.has_guide}. Now to delay for 10 seconds...')
|
||||
ncb_team.has_guide = not ncb_team.has_guide
|
||||
session.add(ncb_team)
|
||||
await asyncio.sleep(10)
|
||||
await ctx.send(f'Now to attempt committing the NCB change...')
|
||||
session.commit()
|
||||
await ctx.send(f'Am I alive? Did it work?')
|
||||
|
||||
|
||||
group_new_game = app_commands.Group(name='new-game', description='Start a new baseball game')
|
||||
|
||||
@group_new_game.command(name='mlb-campaign', description='Start a new MLB campaign game against an AI')
|
||||
|
||||
@ -3535,6 +3535,7 @@ async def groundballs(session: Session, interaction: discord.Interaction, this_p
|
||||
elif this_play.on_base_code in [5, 7] and groundball_letter == 'b':
|
||||
logger.info(f'Groundball {groundball_letter} with runners on including third')
|
||||
|
||||
playing_in = False
|
||||
if this_play.game.ai_team is not None and this_play.pitcher.team.is_ai:
|
||||
def_alignment = this_play.managerai.defense_alignment(session, this_play.game)
|
||||
logger.info(f'def_alignment: {def_alignment}')
|
||||
|
||||
@ -2,29 +2,31 @@ import datetime
|
||||
import logging
|
||||
import math
|
||||
from typing import Literal
|
||||
import os
|
||||
|
||||
import discord
|
||||
import pydantic
|
||||
|
||||
from pydantic import field_validator
|
||||
from sqlmodel import Session, SQLModel, UniqueConstraint, create_engine, select, or_, Field, Relationship, text
|
||||
from sqlalchemy import func, desc
|
||||
from sqlmodel import Session, SQLModel, UniqueConstraint, create_engine, select, or_, Field, Relationship, text, BigInteger
|
||||
from sqlalchemy import Column, func, desc
|
||||
|
||||
from exceptions import *
|
||||
from in_game.managerai_responses import DefenseResponse, JumpResponse, RunResponse, TagResponse, ThrowResponse, UncappedRunResponse
|
||||
|
||||
|
||||
logger = logging.getLogger('discord_app')
|
||||
sqlite_url = 'sqlite:///storage/gameplay.db'
|
||||
connect_args = {"check_same_thread": False}
|
||||
engine = create_engine(sqlite_url, echo=False, connect_args=connect_args)
|
||||
# sqlite_url = 'sqlite:///storage/gameplay.db'
|
||||
# connect_args = {"check_same_thread": False}
|
||||
# engine = create_engine(sqlite_url, echo=False, connect_args=connect_args)
|
||||
engine = create_engine(f'postgresql://{os.getenv('DB_USERNAME')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_URL')}/{os.getenv('DB_NAME')}')
|
||||
CACHE_LIMIT = 1209600 # in seconds
|
||||
SBA_COLOR = 'a6ce39'
|
||||
SBA_LOGO = 'https://sombaseball.ddns.net/static/images/sba-logo.png'
|
||||
|
||||
|
||||
class ManagerAiBase(SQLModel):
|
||||
id: int | None = Field(primary_key=True)
|
||||
id: int | None = Field(sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
name: str = Field(index=True)
|
||||
steal: int | None = Field(default=5)
|
||||
running: int | None = Field(default=5)
|
||||
@ -59,11 +61,11 @@ class RosterLink(SQLModel, table=True):
|
||||
|
||||
|
||||
class TeamBase(SQLModel):
|
||||
id: int = Field(primary_key=True)
|
||||
id: int = Field(sa_column=Column(BigInteger(), primary_key=True, autoincrement=False, unique=True))
|
||||
abbrev: str = Field(index=True)
|
||||
sname: str
|
||||
lname: str
|
||||
gmid: int = Field(index=True)
|
||||
gmid: int = Field(sa_column=Column(BigInteger(), autoincrement=False, index=True))
|
||||
gmname: str
|
||||
gsheet: str
|
||||
wallet: int
|
||||
@ -101,10 +103,10 @@ class Team(TeamBase, table=True):
|
||||
|
||||
|
||||
class Game(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
away_team_id: int = Field(foreign_key='team.id')
|
||||
home_team_id: int = Field(foreign_key='team.id')
|
||||
channel_id: int = Field(index=True)
|
||||
channel_id: int = Field(sa_column=(Column(BigInteger(), index=True)))
|
||||
season: int
|
||||
active: bool | None = Field(default=True)
|
||||
is_pd: bool | None = Field(default=True)
|
||||
@ -757,7 +759,7 @@ class ManagerAi(ManagerAiBase, table=True):
|
||||
|
||||
|
||||
class CardsetBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
name: str
|
||||
ranked_legal: bool | None = Field(default=False)
|
||||
|
||||
@ -768,7 +770,7 @@ class Cardset(CardsetBase, table=True):
|
||||
|
||||
|
||||
class PlayerBase(SQLModel):
|
||||
id: int | None = Field(primary_key=True)
|
||||
id: int | None = Field(sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
name: str
|
||||
cost: int
|
||||
image: str
|
||||
@ -857,7 +859,7 @@ def player_description(player: Player = None, player_dict: dict = None) -> str:
|
||||
|
||||
|
||||
class BattingCardBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
variant: int | None = Field(default=0)
|
||||
steal_low: int = Field(default=0, ge=0, le=20)
|
||||
steal_high: int = Field(default=0, ge=0, le=20)
|
||||
@ -881,7 +883,7 @@ class BattingCard(BattingCardBase, table=True):
|
||||
|
||||
|
||||
class BattingRatingsBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
homerun: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
bp_homerun: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
triple: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
@ -918,7 +920,7 @@ class BattingRatings(BattingRatingsBase, table=True):
|
||||
|
||||
|
||||
class BatterScoutingBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
battingcard_id: int | None = Field(default=None, foreign_key='battingcard.id', ondelete='CASCADE')
|
||||
ratings_vl_id: int | None = Field(default=None, foreign_key='battingratings.id', ondelete='CASCADE')
|
||||
ratings_vr_id: int | None = Field(default=None, foreign_key='battingratings.id', ondelete='CASCADE')
|
||||
@ -937,7 +939,7 @@ class BatterScouting(BatterScoutingBase, table=True):
|
||||
|
||||
|
||||
class PitchingCardBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
variant: int | None = Field(default=0)
|
||||
balk: int = Field(default=0, ge=0, le=20)
|
||||
wild_pitch: int = Field(default=0, ge=0, le=20)
|
||||
@ -960,7 +962,7 @@ class PitchingCard(PitchingCardBase, table=True):
|
||||
|
||||
|
||||
class PitchingRatingsBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
homerun: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
bp_homerun: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
triple: float = Field(default=0.0, ge=0.0, le=108.0)
|
||||
@ -999,7 +1001,7 @@ class PitchingRatings(PitchingRatingsBase, table=True):
|
||||
|
||||
|
||||
class PitcherScoutingBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
pitchingcard_id: int | None = Field(default=None, foreign_key='pitchingcard.id', ondelete='CASCADE')
|
||||
ratings_vl_id: int | None = Field(default=None, foreign_key='pitchingratings.id', ondelete='CASCADE')
|
||||
ratings_vr_id: int | None = Field(default=None, foreign_key='pitchingratings.id', ondelete='CASCADE')
|
||||
@ -1018,7 +1020,7 @@ class PitcherScouting(PitcherScoutingBase, table=True):
|
||||
|
||||
|
||||
class CardBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
||||
player_id: int = Field(foreign_key='player.id', index=True, ondelete='CASCADE')
|
||||
team_id: int = Field(foreign_key='team.id', index=True, ondelete='CASCADE')
|
||||
batterscouting_id: int | None = Field(default=None, foreign_key='batterscouting.id', ondelete='CASCADE')
|
||||
@ -1037,7 +1039,7 @@ class Card(CardBase, table=True):
|
||||
|
||||
class PositionRatingBase(SQLModel):
|
||||
__table_args__ = (UniqueConstraint("player_id", "variant", "position"),)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
player_id: int = Field(foreign_key='player.id', index=True, ondelete='CASCADE')
|
||||
variant: int = Field(default=0, index=True)
|
||||
position: str = Field(index=True, include=['P', 'C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF'])
|
||||
@ -1055,7 +1057,7 @@ class PositionRating(PositionRatingBase, table=True):
|
||||
|
||||
|
||||
class Lineup(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
position: str = Field(index=True)
|
||||
batting_order: int = Field(index=True)
|
||||
after_play: int | None = Field(default=0)
|
||||
@ -1081,7 +1083,7 @@ class Lineup(SQLModel, table=True):
|
||||
|
||||
|
||||
class PlayBase(SQLModel):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
|
||||
game_id: int = Field(foreign_key='game.id')
|
||||
play_num: int
|
||||
batter_id: int = Field(foreign_key='lineup.id')
|
||||
|
||||
@ -803,7 +803,7 @@ def get_db_ready_decisions(session: Session, this_game: Game, db_game_id: int) -
|
||||
|
||||
for lineup in b_save:
|
||||
decisions[lineup.player_id].b_save = 1
|
||||
decisions[lineup.player_id].save = 0
|
||||
decisions[lineup.player_id].is_save = 0
|
||||
|
||||
return [x.model_dump() for x in decisions.values()]
|
||||
|
||||
|
||||
@ -9,3 +9,4 @@ alembic
|
||||
pytest
|
||||
pytest-asyncio
|
||||
pandas
|
||||
psycopg2-binary
|
||||
|
||||
Loading…
Reference in New Issue
Block a user