Lookup decks in seeding by player+deck-name (to take account of duplicates
This commit is contained in:
parent
d605293c8f
commit
624ef62345
@ -104,10 +104,6 @@ def all_in_one(file: UploadFile, db: Session = Depends(get_db)):
|
||||
player_id = f"Player {i+1}"
|
||||
if row[player_id]:
|
||||
player_decks[row[player_id]].add(row[f"Deck {i+1}"])
|
||||
# Hack because of missing data in the original spreadsheet... :)
|
||||
if row_idx == 28 and i == 3:
|
||||
print("In the suspect row")
|
||||
player_decks["stranger"].add(row["Deck 4"])
|
||||
|
||||
# See above
|
||||
# win_types.add(row['Type of win'])
|
||||
@ -134,7 +130,9 @@ def all_in_one(file: UploadFile, db: Session = Depends(get_db)):
|
||||
),
|
||||
)
|
||||
LOGGER.info(f"Seeded {deck=}")
|
||||
deck_id_lookup[deck_name] = deck.id
|
||||
# We need to look up deck id by `player_name:deck_name` because there could be multiple decks with the same
|
||||
# name owned by different people :D
|
||||
deck_id_lookup[f"{player_name}:{deck_name}"] = deck.id
|
||||
|
||||
def parse_date(date_string) -> datetime.datetime:
|
||||
month, day, year = date_string.split("/")
|
||||
@ -153,15 +151,25 @@ def all_in_one(file: UploadFile, db: Session = Depends(get_db)):
|
||||
for row in reader:
|
||||
# Note that we intentionally create via the API, not via direct `crud.create_game`, to trigger ELO calculation.
|
||||
|
||||
index_of_winning_deck = [
|
||||
row[f"Deck {i+1}"] == row["Winning Deck"] for i in range(6)
|
||||
].index(True)
|
||||
print(f"DEBUG - checking row {row}")
|
||||
created_game = create_game(
|
||||
schemas.GameCreate(
|
||||
date=parse_date(row["Date"]),
|
||||
**{
|
||||
f"deck_id_{i+1}": deck_id_lookup[row[f"Deck {i+1}"]]
|
||||
f"deck_id_{i+1}": deck_id_lookup[
|
||||
row[f"Player {i+1}"] + ":" + row[f"Deck {i+1}"]
|
||||
]
|
||||
for i in range(6)
|
||||
if row[f"Deck {i+1}"]
|
||||
},
|
||||
winning_deck_id=deck_id_lookup[row["Winning Deck"]],
|
||||
winning_deck_id=deck_id_lookup[
|
||||
row[f"Player {index_of_winning_deck+1}"]
|
||||
+ ":"
|
||||
+ row[f"Deck {index_of_winning_deck+1}"]
|
||||
],
|
||||
number_of_turns=int(row["# turns"]),
|
||||
first_player_out_turn=row["turn 1st player out"],
|
||||
win_type_id=[
|
||||
|
Loading…
x
Reference in New Issue
Block a user