Consolidated db preparation
This commit is contained in:
parent
2696140365
commit
8d94655e81
@ -35,13 +35,13 @@ Data Links:
|
||||
async def main(argv):
|
||||
cardset_name = input(f'What is the name of this Cardset? ')
|
||||
# cardset_name = '2022 Live'
|
||||
cardset = Cardset.get_or_none(fn.Lower(Cardset.set_title) == cardset_name.lower())
|
||||
cardset = ScoutCardset.get_or_none(fn.Lower(ScoutCardset.set_title) == cardset_name.lower())
|
||||
testing = False
|
||||
|
||||
if not cardset:
|
||||
create_cardset = input(f'There is no cardset named **{cardset_name}**. Should I create it (y/n)? ')
|
||||
if create_cardset.lower() in YES:
|
||||
cardset = Cardset(set_title=cardset_name)
|
||||
cardset = ScoutCardset(set_title=cardset_name)
|
||||
cardset.save()
|
||||
print(f'Got it! Now on to the cards.')
|
||||
else:
|
||||
@ -97,7 +97,7 @@ async def main(argv):
|
||||
|
||||
for row in reader:
|
||||
try:
|
||||
player = Player.get_or_none(Player.fg_id == int(row[0]))
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.fg_id == int(row[0]))
|
||||
if testing:
|
||||
print(f'player fg_id: {int(row[0])} / player: {player}')
|
||||
# Standard limits
|
||||
@ -1766,7 +1766,7 @@ async def main(argv):
|
||||
|
||||
for row in reader:
|
||||
try:
|
||||
player = Player.get_or_none(Player.br_id == row[36])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[36])
|
||||
if player:
|
||||
dupe = BatterData.delete().where(
|
||||
(BatterData.player == player) & (BatterData.cardset == cardset)
|
||||
@ -1821,7 +1821,7 @@ async def main(argv):
|
||||
reader = csv.reader(file)
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.fg_id == int(row[0]))
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.fg_id == int(row[0]))
|
||||
# Standard limits
|
||||
# if player and (('Promo' in cardset.set_title) or ('Major League' in cardset.set_title) or
|
||||
# (int(row[5]) >= 28 and int(row[39]) >= 58)):
|
||||
@ -3286,7 +3286,7 @@ async def main(argv):
|
||||
br_id_col = 26
|
||||
cs_col = 24
|
||||
pick_col = 25
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player and row[15] != '' and row[12] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3348,7 +3348,7 @@ async def main(argv):
|
||||
reader = csv.reader(file)
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.br_id == row[35])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[35])
|
||||
if player:
|
||||
all_data = PitcherData.select().where(
|
||||
(PitcherData.player == player) & (PitcherData.cardset == cardset)
|
||||
@ -3390,7 +3390,7 @@ async def main(argv):
|
||||
br_id_col = 34
|
||||
else:
|
||||
br_id_col = 31
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player:
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3424,7 +3424,7 @@ async def main(argv):
|
||||
# br_id_col = 29
|
||||
# else:
|
||||
# br_id_col = 26
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player and row[19] != '' and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3456,7 +3456,7 @@ async def main(argv):
|
||||
# else:
|
||||
# br_id_col = 26
|
||||
logging.info(f'br_id: {row[br_id_col]} / type: {type(row[br_id_col])}')
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player and row[19] != '' and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3488,7 +3488,7 @@ async def main(argv):
|
||||
# br_id_col = 29
|
||||
# else:
|
||||
# br_id_col = 26
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player and row[19] != '' and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3519,7 +3519,7 @@ async def main(argv):
|
||||
# br_id_col = 29
|
||||
# else:
|
||||
# br_id_col = 26
|
||||
player = Player.get_or_none(Player.br_id == row[br_id_col])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[br_id_col])
|
||||
if player and row[19] != '' and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3545,7 +3545,7 @@ async def main(argv):
|
||||
curr_pos = 'LF'
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.br_id == row[26])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[26])
|
||||
if player and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3571,7 +3571,7 @@ async def main(argv):
|
||||
curr_pos = 'CF'
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.br_id == row[26])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[26])
|
||||
if player and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3597,7 +3597,7 @@ async def main(argv):
|
||||
curr_pos = 'RF'
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.br_id == row[26])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[26])
|
||||
if player and row[22] != '':
|
||||
# Build Position object and save
|
||||
this_pos = Position(
|
||||
@ -3622,7 +3622,7 @@ async def main(argv):
|
||||
reader = csv.reader(file)
|
||||
|
||||
for row in reader:
|
||||
player = Player.get_or_none(Player.br_id == row[26])
|
||||
player = ScoutPlayer.get_or_none(ScoutPlayer.br_id == row[26])
|
||||
all_of = Position.select().where(
|
||||
(Position.player == player) & (Position.cardset == cardset) & (Position.position.contains("F"))
|
||||
)
|
||||
|
||||
@ -62,7 +62,7 @@ def get_pitcher_rarity(total_ops, s_rat):
|
||||
|
||||
async def main(argv):
|
||||
cardset_name = input(f'What is the name of this Cardset? ')
|
||||
cardset = Cardset.get_or_none(fn.Lower(Cardset.set_title) == cardset_name.lower())
|
||||
cardset = ScoutCardset.get_or_none(fn.Lower(ScoutCardset.set_title) == cardset_name.lower())
|
||||
|
||||
if not cardset:
|
||||
print(f'There is no cardset named **{cardset_name}**.')
|
||||
@ -75,7 +75,7 @@ async def main(argv):
|
||||
if not output_path.exists():
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
all_players = Player.select()
|
||||
all_players = ScoutPlayer.select()
|
||||
batter_output = [[
|
||||
'name', 'hand', 'rarity', 'pos', 'stealing', 'bunt', 'hnr', 'running', 'vl-2d6-1', 'vl-results-1',
|
||||
'vl-splits-1', 'vl-2d6-2', 'vl-results-2', 'vl-splits-2', 'vl-2d6-3', 'vl-results-3', 'vl-splits-3', 'vr-2d6-1',
|
||||
|
||||
@ -16,12 +16,12 @@ class BaseModel(Model):
|
||||
database = db
|
||||
|
||||
|
||||
class Cardset(BaseModel):
|
||||
class ScoutCardset(BaseModel):
|
||||
set_title = CharField()
|
||||
set_subtitle = CharField(null=True)
|
||||
|
||||
|
||||
class Player(BaseModel):
|
||||
class ScoutPlayer(BaseModel):
|
||||
sba_id = IntegerField(primary_key=True)
|
||||
name = CharField()
|
||||
fg_id = IntegerField()
|
||||
@ -30,13 +30,13 @@ class Player(BaseModel):
|
||||
hand = CharField(default='R')
|
||||
|
||||
|
||||
db.create_tables([Cardset, Player])
|
||||
db.create_tables([ScoutCardset, ScoutPlayer])
|
||||
|
||||
|
||||
class BatterRatings(BaseModel):
|
||||
id = CharField(unique=True, primary_key=True)
|
||||
player = ForeignKeyField(Player)
|
||||
cardset = ForeignKeyField(Cardset)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
cardset = ForeignKeyField(ScoutCardset)
|
||||
vs_hand = FloatField()
|
||||
is_prep = BooleanField()
|
||||
homerun = FloatField()
|
||||
@ -68,8 +68,8 @@ class BatterRatings(BaseModel):
|
||||
|
||||
class PitcherRatings(BaseModel):
|
||||
id = CharField(unique=True, primary_key=True)
|
||||
player = ForeignKeyField(Player)
|
||||
cardset = ForeignKeyField(Cardset)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
cardset = ForeignKeyField(ScoutCardset)
|
||||
vs_hand = CharField()
|
||||
is_prep = BooleanField()
|
||||
homerun = FloatField()
|
||||
@ -108,7 +108,7 @@ db.create_tables([BatterRatings, PitcherRatings])
|
||||
|
||||
class CardColumns(BaseModel):
|
||||
id = CharField(unique=True, primary_key=True)
|
||||
player = ForeignKeyField(Player)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
hand = CharField()
|
||||
b_ratings = ForeignKeyField(BatterRatings, null=True)
|
||||
p_ratings = ForeignKeyField(PitcherRatings, null=True)
|
||||
@ -124,8 +124,8 @@ class CardColumns(BaseModel):
|
||||
|
||||
|
||||
class Position(BaseModel):
|
||||
player = ForeignKeyField(Player)
|
||||
cardset = ForeignKeyField(Cardset)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
cardset = ForeignKeyField(ScoutCardset)
|
||||
position = CharField()
|
||||
innings = IntegerField()
|
||||
range = IntegerField()
|
||||
@ -136,8 +136,8 @@ class Position(BaseModel):
|
||||
|
||||
|
||||
class BatterData(BaseModel):
|
||||
player = ForeignKeyField(Player)
|
||||
cardset = ForeignKeyField(Cardset)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
cardset = ForeignKeyField(ScoutCardset)
|
||||
stealing = CharField()
|
||||
st_low = IntegerField()
|
||||
st_high = IntegerField()
|
||||
@ -149,8 +149,8 @@ class BatterData(BaseModel):
|
||||
|
||||
|
||||
class PitcherData(BaseModel):
|
||||
player = ForeignKeyField(Player)
|
||||
cardset = ForeignKeyField(Cardset)
|
||||
player = ForeignKeyField(ScoutPlayer)
|
||||
cardset = ForeignKeyField(ScoutCardset)
|
||||
balk = IntegerField(null=True)
|
||||
wild_pitch = IntegerField(null=True)
|
||||
hold = CharField()
|
||||
|
||||
@ -32,7 +32,7 @@ def main(argv):
|
||||
# TODO: will want to update this to check for existing record; get_or_create ?
|
||||
with db.atomic():
|
||||
for batch in chunked(all_players, 50):
|
||||
Player.insert_many(batch).on_conflict_ignore().execute()
|
||||
ScoutPlayer.insert_many(batch).on_conflict_ignore().execute()
|
||||
db.close()
|
||||
|
||||
print(f'Processed {len(all_players)} players')
|
||||
|
||||
@ -13,4 +13,4 @@ logging.basicConfig(
|
||||
|
||||
|
||||
def process_pitcher_csv(filename: str, cardset: str, testing: bool = False):
|
||||
cardset = Cardset.get_or_none(Cardset.set_title == cardset)
|
||||
cardset = ScoutCardset.get_or_none(ScoutCardset.set_title == cardset)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user