Skip to content

Commit

Permalink
Support Set Booster field (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeldaZach authored Jun 24, 2023
1 parent c6bd59d commit 2649a56
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
51 changes: 50 additions & 1 deletion mtgsqlive/converters/parents/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AbstractConverter(abc.ABC):
data_type: MtgjsonDataType

set_keys_to_skip = {
"booster", # WIP for own table
"booster", # Broken out into BoosterContents, BoosterContentWeights, BoosterSheets, BoosterSheetCards
"cards", # Broken out into cards
"sealedProduct", # WIP for own table
"tokens", # Broken out into tokens
Expand Down Expand Up @@ -163,3 +163,52 @@ def get_next_card_price(
"price": price_amount,
"currency": currency,
}

def get_next_booster_contents_entry(self) -> Iterator[Dict[str, str | int]]:
for set_code, set_data in self.mtgjson_data["data"].items():
for booster_name, booster_object in set_data.get("booster", {}).items():
for index, booster_contents in enumerate(booster_object["boosters"]):
for sheet_name, sheet_picks in booster_contents["contents"].items():
yield {
"setCode": set_code,
"boosterName": booster_name,
"boosterIndex": index,
"sheetName": sheet_name,
"sheetPicks": sheet_picks,
}

def get_next_booster_weights_entry(self) -> Iterator[Dict[str, str | int]]:
for set_code, set_data in self.mtgjson_data["data"].items():
for booster_name, booster_object in set_data.get("booster", {}).items():
for index, booster_contents in enumerate(booster_object["boosters"]):
yield {
"setCode": set_code,
"boosterName": booster_name,
"boosterIndex": index,
"boosterWeight": booster_contents["weight"],
}

def get_next_booster_sheets_entry(self) -> Iterator[Dict[str, str | bool]]:
for set_code, set_data in self.mtgjson_data["data"].items():
for booster_object in set_data.get("booster", {}).values():
for sheet_name, sheet_contents in booster_object["sheets"].items():
yield {
"setCode": set_code,
"sheetName": sheet_name,
"sheetIsFoil": sheet_contents.get("foil", False),
"sheetHasBalanceColors": sheet_contents.get(
"balanceColors", False
),
}

def get_next_booster_sheet_cards_entry(self) -> Iterator[Dict[str, str | int]]:
for set_code, set_data in self.mtgjson_data["data"].items():
for booster_object in set_data.get("booster", {}).values():
for sheet_name, sheet_contents in booster_object["sheets"].items():
for card_uuid, card_weight in sheet_contents["cards"].items():
yield {
"setCode": set_code,
"sheetName": sheet_name,
"cardUuid": card_uuid,
"cardWeight": card_weight,
}
45 changes: 45 additions & 0 deletions mtgsqlive/converters/parents/sql_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ def __get_mtgjson_card_generators(self) -> List[Iterator[str]]:
"setTranslations",
self.get_next_set_field_with_normalization("translations"),
),
self.__generate_insert_statement(
"setBoosterContents", self.get_next_booster_contents_entry()
),
self.__generate_insert_statement(
"setBoosterContentWeights", self.get_next_booster_weights_entry()
),
self.__generate_insert_statement(
"setBoosterSheets", self.get_next_booster_sheets_entry()
),
self.__generate_insert_statement(
"setBoosterSheetCards", self.get_next_booster_sheet_cards_entry()
),
]

def __get_mtgjson_card_prices_generators(self) -> List[Iterator[str]]:
Expand Down Expand Up @@ -113,6 +125,10 @@ def _generate_sql_schema_dict(self) -> Dict[str, Any]:
self._add_card_purchase_urls_table_schema(schema)
self._add_token_identifiers_table_schema(schema)
self._add_set_translation_table_schema(schema)
self._add_set_booster_contents_schema(schema)
self._add_set_booster_content_weights_schema(schema)
self._add_set_booster_sheets_schema(schema)
self._add_set_booster_sheet_cards_schema(schema)
elif self.data_type == MtgjsonDataType.MTGJSON_CARD_PRICES:
self._add_all_prices_schema(schema)

Expand Down Expand Up @@ -219,6 +235,35 @@ def _add_all_prices_schema(schema: Dict[str, Any]) -> None:
schema["cardPrices"]["currency"]["type"] = "VARCHAR(10)"
schema["cardPrices"]["uuid"]["type"] = "VARCHAR(36) NOT NULL"

@staticmethod
def _add_set_booster_contents_schema(schema: Dict[str, Any]) -> None:
schema["setBoosterContents"]["setCode"]["type"] = "VARCHAR(20)"
schema["setBoosterContents"]["boosterName"]["type"] = "VARCHAR(255)"
schema["setBoosterContents"]["boosterIndex"]["type"] = "INTEGER"
schema["setBoosterContents"]["sheetName"]["type"] = "VARCHAR(255)"
schema["setBoosterContents"]["sheetPicks"]["type"] = "INTEGER"

@staticmethod
def _add_set_booster_content_weights_schema(schema: Dict[str, Any]) -> None:
schema["setBoosterContentWeights"]["setCode"]["type"] = "VARCHAR(20)"
schema["setBoosterContentWeights"]["boosterName"]["type"] = "VARCHAR(255)"
schema["setBoosterContentWeights"]["boosterIndex"]["type"] = "INTEGER"
schema["setBoosterContentWeights"]["boosterWeight"]["type"] = "INTEGER"

@staticmethod
def _add_set_booster_sheets_schema(schema: Dict[str, Any]) -> None:
schema["setBoosterSheets"]["setCode"]["type"] = "VARCHAR(20)"
schema["setBoosterSheets"]["sheetName"]["type"] = "VARCHAR(255)"
schema["setBoosterSheets"]["sheetIsFoil"]["type"] = "BOOLEAN"
schema["setBoosterSheets"]["sheetHasBalanceColors"]["type"] = "BOOLEAN"

@staticmethod
def _add_set_booster_sheet_cards_schema(schema: Dict[str, Any]) -> None:
schema["setBoosterSheetCards"]["setCode"]["type"] = "VARCHAR(20)"
schema["setBoosterSheetCards"]["sheetName"]["type"] = "VARCHAR(255)"
schema["setBoosterSheetCards"]["cardUuid"]["type"] = "VARCHAR(36) NOT NULL"
schema["setBoosterSheetCards"]["cardWeight"]["type"] = "INTEGER"

@staticmethod
def _convert_schema_dict_to_query(
schema: Dict[str, Any],
Expand Down

0 comments on commit 2649a56

Please sign in to comment.