Initial commit
This commit is contained in:
parent
17ef692d18
commit
0e1f932531
3608
card_creation.py
Normal file
3608
card_creation.py
Normal file
File diff suppressed because it is too large
Load Diff
314
card_output.py
Normal file
314
card_output.py
Normal file
@ -0,0 +1,314 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import logging
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from db_calls_card_creation import *
|
||||
from creation_helpers import get_position_string, write_to_csv, ordered_positions, defense_rg, ordered_pitching_positions
|
||||
|
||||
date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
|
||||
log_level = logging.INFO
|
||||
logging.basicConfig(
|
||||
filename=f'logs/{date}.log',
|
||||
format='%(asctime)s - card-creation - %(levelname)s - %(message)s',
|
||||
level=log_level
|
||||
)
|
||||
|
||||
|
||||
def get_batter_rarity(total_ops):
|
||||
if total_ops < .7:
|
||||
return 'Replacement'
|
||||
elif total_ops < .8:
|
||||
return 'Reserve'
|
||||
elif total_ops < .9:
|
||||
return 'Starter'
|
||||
elif total_ops < 1:
|
||||
return 'All-Star'
|
||||
elif total_ops < 1.2:
|
||||
return 'MVP'
|
||||
else:
|
||||
return 'HoF'
|
||||
|
||||
|
||||
def get_pitcher_rarity(total_ops, s_rat):
|
||||
if s_rat > 3:
|
||||
if total_ops <= .4:
|
||||
return 'HoF'
|
||||
elif total_ops <= .475:
|
||||
return 'MVP'
|
||||
elif total_ops <= .53:
|
||||
return 'All-Star'
|
||||
elif total_ops <= .6:
|
||||
return 'Starter'
|
||||
elif total_ops <= .675:
|
||||
return 'Reserve'
|
||||
else:
|
||||
return 'Replacement'
|
||||
else:
|
||||
if total_ops <= .325:
|
||||
return 'HoF'
|
||||
elif total_ops <= .4:
|
||||
return 'MVP'
|
||||
elif total_ops <= .475:
|
||||
return 'All-Star'
|
||||
elif total_ops <= .55:
|
||||
return 'Starter'
|
||||
elif total_ops <= .625:
|
||||
return 'Reserve'
|
||||
else:
|
||||
return 'Replacement'
|
||||
|
||||
|
||||
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())
|
||||
|
||||
if not cardset:
|
||||
print(f'There is no cardset named **{cardset_name}**.')
|
||||
return
|
||||
else:
|
||||
print(f'Got it! Starting on the {cardset.set_title} cardset.')
|
||||
|
||||
now = datetime.datetime.now()
|
||||
output_path = pathlib.Path(f'card-output/{cardset.set_title} Cardset/')
|
||||
if not output_path.exists():
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
all_players = Player.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',
|
||||
'vr-results-1', 'vr-splits-1', 'vr-2d6-2', 'vr-results-2', 'vr-splits-2', 'vr-2d6-3', 'vr-results-3',
|
||||
'vr-splits-3'
|
||||
]]
|
||||
batter_rg_output = [[
|
||||
'sba_id', 'cardset_id', 'player_name', 'hand', 'vl_hr', 'vl_bphr', 'vl_tr', 'vl_do3', 'vl_do2', 'vl_doP',
|
||||
'vl_si2', 'vl_si1', 'vl_siC', 'vl_bpsi', 'vl_hbp', 'vl_bb', 'vl_k', 'vl_lo', 'vl_po', 'vl_flya', 'vl_flybq',
|
||||
'vl_flylfb', 'vl_flyrfb', 'vl_gba', 'vl_gbb', 'vl_gbc', 'vr_hr', 'vr_bphr', 'vr_tr', 'vr_do3', 'vr_do2',
|
||||
'vr_doP', 'vr_si2', 'vr_si1', 'vr_siC', 'vr_bpsi', 'vr_hbp', 'vr_bb', 'vr_k', 'vr_lo', 'vr_po', 'vr_flya',
|
||||
'vr_flybq', 'vr_flylfb', 'vr_flyrfb', 'vr_gba', 'vr_gbb', 'vr_gbc'
|
||||
]]
|
||||
baserunning_output = [[
|
||||
'name', 'running', 'st-high', 'st-low', 'auto-jump', 'jump'
|
||||
]]
|
||||
pitcher_output = [[
|
||||
'name', 'hand', 'rarity', 'starter', 'reliever', 'closer', 'hold', 'batting', 'balk', 'wp', 'defense', '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', 'vr-results-1', 'vr-splits-1', 'vr-2d6-2', 'vr-results-2', 'vr-splits-2', 'vr-2d6-3',
|
||||
'vr-results-3', 'vr-splits-3'
|
||||
]]
|
||||
pitcher_peripherals_output = [[
|
||||
'name', 'starter', 'reliever', 'closer', 'hold', 'balk', 'wp'
|
||||
]]
|
||||
pitcher_rg_output = [[
|
||||
'sba-id', 'cardset-id', 'player-name', 'hand', 'hr-vL', 'bp-hr-vL', 'tr-vL', 'do***-vL', 'do**-vL', 'do-cf-vL',
|
||||
'si**-vL', 'si*-vL', 'si-cf-vL', 'bp-si-vL', 'hbp-vL', 'bb-vL', 'so-vL', 'fo-b-cf-vL', 'fo-b-slap-vL',
|
||||
'gb-a-vL', 'gb-c-vL', 'gb-x-p-vL', 'gb-x-c-vL', 'gb-x-1b-vL', 'gb-x-2b-vL', 'gb-x-3b-vL', 'gb-x-ss-vL',
|
||||
'gb-x-lf-vL', 'gb-x-cf-vL', 'gb-x-rf-vL', 'hr-vR', 'bp-hr-vR', 'tr-vR', 'do***-vR', 'do**-vR', 'do-cf-vR',
|
||||
'si**-vR', 'si*-vR', 'si-cf-vR', 'bp-si-vR', 'hbp-vR', 'bb-vR', 'so-vR', 'fo-b-cf-vR', 'fo-b-slap-vR',
|
||||
'gb-a-vR', 'gb-c-vR', 'gb-x-p-vR', 'gb-x-c-vR', 'gb-x-1b-vR', 'gb-x-2b-vR', 'gb-x-3b-vR', 'gb-x-ss-vR',
|
||||
'gb-x-lf-vR', 'gb-x-cf-vR', 'gb-x-rf-vR'
|
||||
]]
|
||||
player_json_output = [[
|
||||
'sba-id', 'name', '', 'fg-id', 'bbref-id', '', '', '', 'cardset-id'
|
||||
]]
|
||||
defense_rg_output = [[
|
||||
'full name', 'p-rat', 'c-rat', '1b-rat', '2b-rat', '3b-rat', 'ss-rat', 'lf-rat', 'cf-rat', 'rf-rat', 'p-e',
|
||||
'c-e', '1b-e', '2b-e', '3b-e', 'ss-e', 'lf-e', 'cf-e', 'rf-e', 'of-arm', 'c-arm', 'c-throw', 'c-pb', 'p-wp',
|
||||
'p-bk'
|
||||
]]
|
||||
|
||||
print(f'Found {all_players.count()} players in this cardset...')
|
||||
for player in all_players:
|
||||
b_lines = CardColumns.select().where(
|
||||
CardColumns.b_ratings.is_null(False) & (CardColumns.player == player) &
|
||||
CardColumns.b_ratings.endswith(f'{cardset.id}')
|
||||
)
|
||||
|
||||
this_output = [player.name, player.hand]
|
||||
if b_lines.count() == 2:
|
||||
vl_line = None
|
||||
vr_line = None
|
||||
for line in b_lines:
|
||||
this_columns = [
|
||||
line.one_dice, line.one_results, line.one_splits, line.two_dice, line.two_results, line.two_splits,
|
||||
line.three_dice, line.three_results, line.three_splits
|
||||
]
|
||||
if 'vL' in line.b_ratings.id:
|
||||
vl_line = this_columns
|
||||
else:
|
||||
vr_line = this_columns
|
||||
|
||||
vl_ratings = BatterRatings.get_or_none(
|
||||
BatterRatings.player == player, BatterRatings.cardset == cardset, BatterRatings.vs_hand == 'vL',
|
||||
BatterRatings.is_prep == 0
|
||||
)
|
||||
vr_ratings = BatterRatings.get_or_none(
|
||||
BatterRatings.player == player, BatterRatings.cardset == cardset, BatterRatings.vs_hand == 'vR',
|
||||
BatterRatings.is_prep == 0
|
||||
)
|
||||
|
||||
# Calculate rarity
|
||||
ops_vl = vl_ratings.obp + vl_ratings.slg
|
||||
ops_vr = vr_ratings.obp + vr_ratings.slg
|
||||
total_ops = (ops_vl + ops_vr + min(ops_vl, ops_vr)) / 3
|
||||
rarity = get_batter_rarity(total_ops)
|
||||
|
||||
this_json = [
|
||||
player.sba_id, player.name, None, player.fg_id, player.br_id, None, None, None, cardset.id, rarity, None
|
||||
]
|
||||
this_output.append(rarity)
|
||||
|
||||
batter_rg_output.append([
|
||||
player.sba_id, cardset.id, player.name, player.hand, vl_ratings.homerun, vl_ratings.bp_homerun,
|
||||
vl_ratings.triple, vl_ratings.double_three, vl_ratings.double_two, vl_ratings.double_pull,
|
||||
vl_ratings.single_two, vl_ratings.single_one, vl_ratings.single_center, vl_ratings.bp_single,
|
||||
vl_ratings.hbp, vl_ratings.walk, vl_ratings.strikeout, vl_ratings.lineout, vl_ratings.popout,
|
||||
vl_ratings.flyout_a, vl_ratings.flyout_bq, vl_ratings.flyout_lf_b, vl_ratings.flyout_rf_b,
|
||||
vl_ratings.groundout_a, vl_ratings.groundout_b, vl_ratings.groundout_c, vr_ratings.homerun, vr_ratings.bp_homerun,
|
||||
vr_ratings.triple, vr_ratings.double_three, vr_ratings.double_two, vr_ratings.double_pull,
|
||||
vr_ratings.single_two, vr_ratings.single_one, vr_ratings.single_center, vr_ratings.bp_single,
|
||||
vr_ratings.hbp, vr_ratings.walk, vr_ratings.strikeout, vr_ratings.lineout, vr_ratings.popout,
|
||||
vr_ratings.flyout_a, vr_ratings.flyout_bq, vr_ratings.flyout_lf_b, vr_ratings.flyout_rf_b,
|
||||
vr_ratings.groundout_a, vr_ratings.groundout_b, vr_ratings.groundout_c, rarity
|
||||
])
|
||||
|
||||
all_positions = Position.select().where((Position.player == player) & (Position.cardset == cardset))
|
||||
pos_list = [x for x in all_positions]
|
||||
position_string = get_position_string(pos_list, inc_p=False)
|
||||
this_json.extend(ordered_positions(pos_list))
|
||||
player_json_output.append(this_json)
|
||||
|
||||
this_batter_data = BatterData.get_or_none(BatterData.player == player, BatterData.cardset == cardset)
|
||||
if this_batter_data:
|
||||
baserunning_output.append([
|
||||
player.name, this_batter_data.running, this_batter_data.st_high, this_batter_data.st_low,
|
||||
"Y" if this_batter_data.st_auto else "N", this_batter_data.st_jump
|
||||
])
|
||||
|
||||
this_output.extend([
|
||||
position_string, this_batter_data.stealing, this_batter_data.bunting, this_batter_data.hit_and_run,
|
||||
this_batter_data.running
|
||||
])
|
||||
this_output.extend(vl_line)
|
||||
this_output.extend(vr_line)
|
||||
|
||||
batter_output.append(this_output)
|
||||
|
||||
p_lines = CardColumns.select().where(
|
||||
CardColumns.p_ratings.is_null(False) & (CardColumns.player == player) &
|
||||
CardColumns.p_ratings.endswith(f'{cardset.id}')
|
||||
)
|
||||
# if p_lines.count() > 0:
|
||||
# print(f'player: {player.name}')
|
||||
# print(f'p_lines ({p_lines.count()}): {p_lines}')
|
||||
|
||||
this_output = [player.name, player.hand]
|
||||
if p_lines.count() == 2:
|
||||
vr_line = None
|
||||
vl_line = None
|
||||
|
||||
for line in p_lines:
|
||||
this_columns = [
|
||||
line.one_dice, line.one_results, line.one_splits, line.two_dice, line.two_results, line.two_splits,
|
||||
line.three_dice, line.three_results, line.three_splits
|
||||
]
|
||||
if 'vL' in line.p_ratings.id:
|
||||
vl_line = this_columns
|
||||
else:
|
||||
vr_line = this_columns
|
||||
|
||||
if vr_line is not None and vl_line is not None:
|
||||
this_data = PitcherData.get_or_none(PitcherData.player == player, PitcherData.cardset_id == cardset.id)
|
||||
if this_data:
|
||||
pitcher_peripherals_output.append([
|
||||
player.name, this_data.starter_rating, this_data.relief_rating, this_data.closer_rating,
|
||||
this_data.hold, this_data.wild_pitch, this_data.balk
|
||||
])
|
||||
|
||||
vl_ratings = PitcherRatings.get_or_none(
|
||||
PitcherRatings.player == player, PitcherRatings.cardset == cardset,
|
||||
PitcherRatings.vs_hand == 'vL', PitcherRatings.is_prep == 0
|
||||
)
|
||||
vr_ratings = PitcherRatings.get_or_none(
|
||||
PitcherRatings.player == player, PitcherRatings.cardset == cardset,
|
||||
PitcherRatings.vs_hand == 'vR', PitcherRatings.is_prep == 0
|
||||
)
|
||||
|
||||
# Calculate rarity
|
||||
ops_vl = vl_ratings.obp + vl_ratings.slg
|
||||
ops_vr = vr_ratings.obp + vr_ratings.slg
|
||||
total_ops = (ops_vl + ops_vr + min(ops_vl, ops_vr)) / 3
|
||||
rarity = get_pitcher_rarity(total_ops, this_data.starter_rating)
|
||||
|
||||
this_json = [
|
||||
player.sba_id, player.name, None, player.fg_id, player.br_id, None, None, None, cardset.id,
|
||||
rarity, None
|
||||
]
|
||||
|
||||
this_output.extend([
|
||||
rarity, this_data.starter_rating, this_data.relief_rating, this_data.closer_rating,
|
||||
this_data.hold, this_data.batting, this_data.balk, this_data.wild_pitch
|
||||
])
|
||||
|
||||
pitcher_rg_output.append([
|
||||
player.sba_id, cardset.id, player.name, player.hand, vl_ratings.homerun, vl_ratings.bp_homerun,
|
||||
vl_ratings.triple, vl_ratings.double_three, vl_ratings.double_two, vl_ratings.double_cf,
|
||||
vl_ratings.single_two, vl_ratings.single_one, vl_ratings.single_center, vl_ratings.bp_single,
|
||||
vl_ratings.hbp, vl_ratings.walk, vl_ratings.strikeout, vl_ratings.fo_center, vl_ratings.fo_slap,
|
||||
vl_ratings.groundout_a, vl_ratings.groundout_b, vl_ratings.xcheck_p, vl_ratings.xcheck_c,
|
||||
vl_ratings.xcheck_1b, vl_ratings.xcheck_2b, vl_ratings.xcheck_3b, vl_ratings.xcheck_ss,
|
||||
vl_ratings.xcheck_lf, vl_ratings.xcheck_cf, vl_ratings.xcheck_rf,
|
||||
vr_ratings.homerun, vr_ratings.bp_homerun,
|
||||
vr_ratings.triple, vr_ratings.double_three, vr_ratings.double_two, vr_ratings.double_cf,
|
||||
vr_ratings.single_two, vr_ratings.single_one, vr_ratings.single_center, vr_ratings.bp_single,
|
||||
vr_ratings.hbp, vr_ratings.walk, vr_ratings.strikeout, vr_ratings.fo_center, vr_ratings.fo_slap,
|
||||
vr_ratings.groundout_a, vr_ratings.groundout_b, vr_ratings.xcheck_p, vr_ratings.xcheck_c,
|
||||
vr_ratings.xcheck_1b, vr_ratings.xcheck_2b, vr_ratings.xcheck_3b, vr_ratings.xcheck_ss,
|
||||
vr_ratings.xcheck_lf, vr_ratings.xcheck_cf, vr_ratings.xcheck_rf
|
||||
])
|
||||
|
||||
p_def = Position.get_or_none(
|
||||
(Position.player == player) & (Position.cardset_id == cardset.id) & (Position.position == 'P')
|
||||
)
|
||||
if p_def:
|
||||
this_output.append(f'p-{p_def.range}e{p_def.error}')
|
||||
this_output.extend(vl_line)
|
||||
this_output.extend(vr_line)
|
||||
|
||||
pitcher_output.append(this_output)
|
||||
all_p_def = Position.select().where(
|
||||
((Position.player == player) & (Position.cardset == cardset)) & (
|
||||
(Position.position == 'SP') | (Position.position == 'RP') |
|
||||
(Position.position == 'CP')
|
||||
)
|
||||
)
|
||||
pos_list = [x for x in all_p_def]
|
||||
ordered_roles = ordered_pitching_positions(pos_list)
|
||||
this_json.extend(ordered_roles)
|
||||
player_json_output.append(this_json)
|
||||
|
||||
all_pos = Position.select().where(
|
||||
(Position.player == player) & (Position.cardset == cardset)
|
||||
)
|
||||
if all_pos.count() > 0:
|
||||
this_data = [player.name]
|
||||
this_data.extend(defense_rg(all_pos))
|
||||
defense_rg_output.append(this_data)
|
||||
|
||||
print(f'Done processing players; outputting to {output_path}')
|
||||
write_to_csv(output_path, f'batter-card-output-{now.strftime("%Y-%m-%d-%f")}', batter_output)
|
||||
write_to_csv(output_path, f'batter-rg-output-{now.strftime("%Y-%m-%d-%f")}', batter_rg_output)
|
||||
write_to_csv(output_path, f'batter-baserunning-{now.strftime("%Y-%m-%d-%f")}', baserunning_output)
|
||||
write_to_csv(output_path, f'pitcher-card-output-{now.strftime("%Y-%m-%d-%f")}', pitcher_output)
|
||||
write_to_csv(output_path, f'pitcher-peripherals-{now.strftime("%Y-%m-%d-%f")}', pitcher_peripherals_output)
|
||||
write_to_csv(output_path, f'pitcher-rg-output-{now.strftime("%Y-%m-%d-%f")}', pitcher_rg_output)
|
||||
write_to_csv(output_path, f'player-json-{now.strftime("%Y-%m-%d-%f")}', player_json_output)
|
||||
write_to_csv(output_path, f'defense-rg-{now.strftime("%Y-%m-%d-%f")}', defense_rg_output)
|
||||
print(f'All done!')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main(sys.argv[1:]))
|
||||
687
creation_helpers.py
Normal file
687
creation_helpers.py
Normal file
@ -0,0 +1,687 @@
|
||||
import csv
|
||||
import random
|
||||
import logging
|
||||
from db_calls_card_creation import *
|
||||
|
||||
D20_CHANCES = {
|
||||
'2': {
|
||||
'chances': 1,
|
||||
'inc': .05
|
||||
},
|
||||
'3': {
|
||||
'chances': 2,
|
||||
'inc': .1
|
||||
},
|
||||
'4': {
|
||||
'chances': 3,
|
||||
'inc': .15
|
||||
},
|
||||
'5': {
|
||||
'chances': 4,
|
||||
'inc': .2
|
||||
},
|
||||
'6': {
|
||||
'chances': 5,
|
||||
'inc': .25
|
||||
},
|
||||
'7': {
|
||||
'chances': 6,
|
||||
'inc': .3
|
||||
},
|
||||
'8': {
|
||||
'chances': 5,
|
||||
'inc': .25
|
||||
},
|
||||
'9': {
|
||||
'chances': 4,
|
||||
'inc': .2
|
||||
},
|
||||
'10': {
|
||||
'chances': 3,
|
||||
'inc': .15
|
||||
},
|
||||
'11': {
|
||||
'chances': 2,
|
||||
'inc': .1
|
||||
},
|
||||
'12': {
|
||||
'chances': 1,
|
||||
'inc': .05
|
||||
}
|
||||
}
|
||||
BLANK_RESULTS = {
|
||||
'vL': {
|
||||
'1': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
},
|
||||
'2': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
},
|
||||
'3': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
}
|
||||
},
|
||||
'vR': {
|
||||
'1': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
},
|
||||
'2': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
},
|
||||
'3': {
|
||||
'2': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'3': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'4': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'5': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'6': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'7': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'8': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'9': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'10': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'11': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'12': {
|
||||
'result': None,
|
||||
'splits': None,
|
||||
'2d6': None
|
||||
},
|
||||
'splits': 0
|
||||
}
|
||||
}
|
||||
}
|
||||
TESTING = False
|
||||
YES = ['y', 'yes', 'yeet', 'please', 'yeah']
|
||||
|
||||
|
||||
def mround(x, prec=2, base=.05):
|
||||
return round(base * round(float(x) / base), prec)
|
||||
|
||||
|
||||
def chances_from_row(row_num):
|
||||
if row_num == '2' or row_num == '12':
|
||||
return 1
|
||||
if row_num == '3' or row_num == '11':
|
||||
return 2
|
||||
if row_num == '4' or row_num == '10':
|
||||
return 3
|
||||
if row_num == '5' or row_num == '9':
|
||||
return 4
|
||||
if row_num == '6' or row_num == '8':
|
||||
return 5
|
||||
if row_num == '7':
|
||||
return 6
|
||||
raise ValueError(f'No chance count found for row_num {row_num}')
|
||||
|
||||
|
||||
def legal_splits(tot_chances):
|
||||
legal_2d6 = []
|
||||
for x in D20_CHANCES:
|
||||
num_incs = mround(tot_chances) / D20_CHANCES[x]['inc']
|
||||
if num_incs - int(num_incs) == 0 and int(20 - num_incs) > 0:
|
||||
legal_2d6.append({
|
||||
'2d6': int(x),
|
||||
'incs': int(num_incs),
|
||||
'bad_chances': mround(D20_CHANCES[x]['chances'] * (int(20 - num_incs) / 20)),
|
||||
'bad_incs': int(20 - num_incs)
|
||||
})
|
||||
|
||||
random.shuffle(legal_2d6)
|
||||
# if TESTING: print(f'tot_chances: {myround(tot_chances)}')
|
||||
# if TESTING: print(f'legal_2d6: {legal_2d6}')
|
||||
return legal_2d6
|
||||
|
||||
|
||||
def result_string(tba_data, row_num, split_min=None, split_max=None):
|
||||
bold1 = f'{"<b>" if tba_data["bold"] else ""}'
|
||||
bold2 = f'{"</b>" if tba_data["bold"] else ""}'
|
||||
row_string = f'{"<b> </b>" if int(row_num) < 10 else ""}{row_num}'
|
||||
if TESTING: print(f'adding {tba_data["string"]} to row {row_num} / '
|
||||
f'split_min: {split_min} / split_max: {split_max}')
|
||||
|
||||
# No splits; standard result
|
||||
if not split_min:
|
||||
return f'{bold1}{row_string}-{tba_data["string"]}{bold2}'
|
||||
|
||||
# With splits
|
||||
split_nums = f'{split_min if split_min != 20 else ""}{"-" if split_min != 20 else ""}{split_max}'
|
||||
data_string = tba_data["sm-string"] if "sm-string" in tba_data.keys() else tba_data["string"]
|
||||
spaces = 18 - len(data_string) - len(split_nums)
|
||||
if 'WALK' in data_string:
|
||||
spaces -= 3
|
||||
elif 'SI**' in data_string:
|
||||
spaces += 1
|
||||
elif 'DO*' in data_string:
|
||||
spaces -= 1
|
||||
elif 'DO*' in data_string:
|
||||
spaces -= 2
|
||||
elif 'so' in data_string:
|
||||
spaces += 3
|
||||
elif 'gb' in data_string:
|
||||
spaces -= 3
|
||||
|
||||
if TESTING: print(f'len(tba_data["string"]): {len(data_string)} / len(split_nums): {len(split_nums)} '
|
||||
f'spaces: {spaces}')
|
||||
if split_min == 1 or split_min is None:
|
||||
row_output = f'{row_string}-'
|
||||
else:
|
||||
row_output = '<b> </b>'
|
||||
if TESTING: print(f'row_output: {row_output}')
|
||||
return f'{bold1}{row_output}{data_string}{" " * spaces}{split_nums}{bold2}'
|
||||
|
||||
|
||||
def result_data(tba_data, row_num, tba_data_bottom=None, top_split_max=None, fatigue=False):
|
||||
ret_data = {}
|
||||
top_bold1 = f'{"<b>" if tba_data["bold"] else ""}'
|
||||
top_bold2 = f'{"</b>" if tba_data["bold"] else ""}'
|
||||
bot_bold1 = None
|
||||
bot_bold2 = None
|
||||
if tba_data_bottom:
|
||||
bot_bold1 = f'{"<b>" if tba_data_bottom["bold"] else ""}'
|
||||
bot_bold2 = f'{"</b>" if tba_data_bottom["bold"] else ""}'
|
||||
|
||||
if tba_data_bottom is None:
|
||||
ret_data['2d6'] = f'{top_bold1}{int(row_num)}-{top_bold2}'
|
||||
ret_data['splits'] = f'{top_bold1}{top_bold2}'
|
||||
ret_data['result'] = f'{top_bold1}' \
|
||||
f'{tba_data["string"]}{" •" if fatigue else ""}' \
|
||||
f'{top_bold2}'
|
||||
else:
|
||||
ret_data['2d6'] = f'{top_bold1}{int(row_num)}-{top_bold2}\n'
|
||||
ret_data['splits'] = f'{top_bold1}1{"-" if top_split_max != 1 else ""}' \
|
||||
f'{top_split_max if top_split_max != 1 else ""}{top_bold2}\n' \
|
||||
f'{bot_bold1}{top_split_max+1}{"-20" if top_split_max != 19 else ""}{bot_bold2}'
|
||||
ret_data['result'] = \
|
||||
f'{top_bold1}{tba_data["sm-string"] if "sm-string" in tba_data.keys() else tba_data["string"]}' \
|
||||
f'{top_bold2}\n' \
|
||||
f'{bot_bold1}' \
|
||||
f'{tba_data_bottom["sm-string"] if "sm-string" in tba_data_bottom.keys() else tba_data_bottom["string"]}' \
|
||||
f'{bot_bold2}'
|
||||
|
||||
return ret_data
|
||||
|
||||
|
||||
def get_of(batter_hand, pitcher_hand, pull_side=True):
|
||||
if batter_hand == 'R':
|
||||
return 'lf' if pull_side else 'rf'
|
||||
|
||||
if batter_hand == 'L':
|
||||
return 'rf' if pull_side else 'lf'
|
||||
|
||||
if batter_hand == 'S':
|
||||
if pitcher_hand == 'L':
|
||||
return 'rf' if pull_side else 'rf'
|
||||
else:
|
||||
return 'lf' if pull_side else 'lf'
|
||||
|
||||
|
||||
def get_col(col_num):
|
||||
if col_num == '1':
|
||||
return 'one'
|
||||
if col_num == '2':
|
||||
return 'two'
|
||||
if col_num == '3':
|
||||
return 'three'
|
||||
|
||||
|
||||
def write_to_csv(output_path, file_name: str, row_data: list):
|
||||
# Build the csv output
|
||||
fpath = (output_path / f'{file_name}').with_suffix('.csv')
|
||||
logging.info(f'Printing following data to {file_name}:\n\n{row_data}')
|
||||
with fpath.open(mode='w+', newline='', encoding='utf-8') as csv_File:
|
||||
writer = csv.writer(csv_File)
|
||||
writer.writerows(row_data)
|
||||
|
||||
|
||||
def get_position_string(all_pos: list, inc_p: bool):
|
||||
if len(all_pos) == 0:
|
||||
return 'dh'
|
||||
|
||||
of_arm = None
|
||||
of_error = None
|
||||
of_innings = None
|
||||
lf_range = None
|
||||
lf_innings = 0
|
||||
cf_range = None
|
||||
cf_innings = 0
|
||||
rf_range = None
|
||||
rf_innings = 0
|
||||
|
||||
all_def = []
|
||||
|
||||
for x in all_pos:
|
||||
if x.position == 'OF':
|
||||
of_arm = f'{"+" if "-" not in x.arm else ""}{x.arm}'
|
||||
of_error = x.error
|
||||
of_innings = x.innings
|
||||
elif x.position == 'CF':
|
||||
cf_range = x.range
|
||||
cf_innings = x.innings
|
||||
elif x.position == 'LF':
|
||||
lf_range = x.range
|
||||
lf_innings = x.innings
|
||||
elif x.position == 'RF':
|
||||
rf_range = x.range
|
||||
rf_innings = x.innings
|
||||
elif x.position == 'C':
|
||||
all_def.append((f'c-{x.range}({x.arm}) e{x.error} T-{x.overthrow}(pb-{x.pb})', x.innings))
|
||||
elif 'P' in x.position and not inc_p:
|
||||
pass
|
||||
else:
|
||||
all_def.append((f'{x.position.lower()}-{x.range}e{x.error}', x.innings))
|
||||
|
||||
if of_arm is not None:
|
||||
all_of = []
|
||||
if lf_innings > 0:
|
||||
all_of.append((lf_range, lf_innings, 'lf'))
|
||||
if cf_innings > 0:
|
||||
all_of.append((cf_range, cf_innings, 'cf'))
|
||||
if rf_innings > 0:
|
||||
all_of.append((rf_range, rf_innings, 'rf'))
|
||||
|
||||
if len(all_of) > 0:
|
||||
all_of.sort(key=lambda y: y[1], reverse=True)
|
||||
out_string = f'{all_of[0][2]}-{all_of[0][0]}({of_arm})e{of_error}'
|
||||
if len(all_of) == 2:
|
||||
out_string += f', {all_of[1][2]}-{all_of[1][0]}e{of_error}'
|
||||
if len(all_of) == 3:
|
||||
out_string += f', {all_of[2][2]}-{all_of[2][0]}e{of_error}'
|
||||
all_def.append((out_string, of_innings))
|
||||
|
||||
all_def.sort(key=lambda z: z[1], reverse=True)
|
||||
|
||||
final_defense = ''
|
||||
for x in all_def:
|
||||
if len(final_defense) > 0:
|
||||
final_defense += f', '
|
||||
final_defense += f'{x[0]}'
|
||||
|
||||
return final_defense
|
||||
|
||||
|
||||
def ordered_positions(all_pos: list) -> list:
|
||||
all_def = []
|
||||
|
||||
for x in all_pos:
|
||||
if x.position not in ['OF', 'P', 'SP', 'RP', 'CP']:
|
||||
all_def.append((x.innings, x.position))
|
||||
|
||||
all_def.sort(key=lambda y: y[0], reverse=True)
|
||||
return [x[1] for x in all_def]
|
||||
|
||||
|
||||
def ordered_pitching_positions(all_pos: list) -> list:
|
||||
all_def = []
|
||||
|
||||
for x in all_pos:
|
||||
if x.position in ['SP', 'RP', 'CP']:
|
||||
all_def.append((x.innings, x.position))
|
||||
|
||||
all_def.sort(key=lambda y: y[0], reverse=True)
|
||||
return [x[1] for x in all_def]
|
||||
|
||||
|
||||
def defense_rg(all_pos: list) -> list:
|
||||
rg_data = [
|
||||
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
|
||||
None, None, None, None, None, None
|
||||
]
|
||||
all_pitcher = True
|
||||
for line in all_pos:
|
||||
if 'P' not in line.position:
|
||||
all_pitcher = False
|
||||
break
|
||||
|
||||
for line in all_pos:
|
||||
if line.position == 'P' and all_pitcher:
|
||||
this_pit = PitcherData.get_or_none(PitcherData.player == line.player, PitcherData.cardset == line.cardset)
|
||||
if this_pit:
|
||||
rg_data[0] = line.range
|
||||
rg_data[9] = line.error
|
||||
rg_data[22] = this_pit.wild_pitch
|
||||
rg_data[23] = this_pit.balk
|
||||
elif line.position == 'C':
|
||||
rg_data[1] = line.range
|
||||
rg_data[10] = line.error
|
||||
rg_data[19] = line.arm
|
||||
rg_data[20] = line.overthrow
|
||||
rg_data[21] = line.pb
|
||||
elif line.position == '1B':
|
||||
rg_data[2] = line.range
|
||||
rg_data[11] = line.error
|
||||
elif line.position == '2B':
|
||||
rg_data[3] = line.range
|
||||
rg_data[12] = line.error
|
||||
elif line.position == '3B':
|
||||
rg_data[4] = line.range
|
||||
rg_data[13] = line.error
|
||||
elif line.position == 'SS':
|
||||
rg_data[5] = line.range
|
||||
rg_data[14] = line.error
|
||||
elif line.position == 'LF':
|
||||
rg_data[6] = line.range
|
||||
elif line.position == 'CF':
|
||||
rg_data[7] = line.range
|
||||
elif line.position == 'RF':
|
||||
rg_data[8] = line.range
|
||||
elif line.position == 'OF':
|
||||
rg_data[15] = line.error
|
||||
rg_data[16] = line.error
|
||||
rg_data[17] = line.error
|
||||
rg_data[18] = line.arm
|
||||
|
||||
return rg_data
|
||||
|
||||
Loading…
Reference in New Issue
Block a user