omg
All checks were successful
Deploy App to Docker / deploy (push) Successful in 33s

This commit is contained in:
zman 2025-04-20 19:26:48 -04:00
parent fb3134723a
commit b151ef9920

View File

@ -103,16 +103,19 @@ class PricingService:
self.tcgplayer_service.load_tcgplayer_cards(file_content) self.tcgplayer_service.load_tcgplayer_cards(file_content)
self.load_pricing_csv_content_to_db(file_content) self.load_pricing_csv_content_to_db(file_content)
def get_all_prices_for_products(self, product_ids: List[str]) -> Dict[str, Dict[str, float]]: def get_latest_prices_for_products(self, product_ids: List[str]) -> Dict[str, Dict[str, float]]:
all_prices = self.db.query(Price).filter( latest_prices = self.db.query(Price).filter(
Price.product_id.in_(product_ids) Price.product_id.in_(product_ids)
).distinct(Price.product_id, Price.type).order_by(
Price.product_id,
Price.type,
Price.date_created.desc()
).all() ).all()
price_lookup = {} price_lookup = {}
for price in all_prices: for price in latest_prices:
if price.product_id not in price_lookup: price_lookup.setdefault(price.product_id, {})[price.type] = price.price
price_lookup[price.product_id] = {}
price_lookup[price.product_id][price.type] = price.price
return price_lookup return price_lookup
def apply_price_to_df_columns(self, row: pd.Series, price_lookup: Dict[str, Dict[str, float]]) -> pd.Series: def apply_price_to_df_columns(self, row: pd.Series, price_lookup: Dict[str, Dict[str, float]]) -> pd.Series:
@ -156,7 +159,7 @@ class PricingService:
tcg_low = Decimal(str(row.get('tcg_low_price'))) if not pd.isna(row.get('tcg_low_price')) else None tcg_low = Decimal(str(row.get('tcg_low_price'))) if not pd.isna(row.get('tcg_low_price')) else None
tcg_low_shipping = Decimal(str(row.get('tcg_low_price_with_shipping'))) if not pd.isna(row.get('tcg_low_price_with_shipping')) else None tcg_low_shipping = Decimal(str(row.get('tcg_low_price_with_shipping'))) if not pd.isna(row.get('tcg_low_price_with_shipping')) else None
tcg_market_price = Decimal(str(row.get('tcg_market_price'))) if not pd.isna(row.get('tcg_market_price')) else None tcg_market_price = Decimal(str(row.get('tcg_market_price'))) if not pd.isna(row.get('tcg_market_price')) else None
current_price = Decimal(str(row.get('tcg_marketplace_price'))) if not pd.isna(row.get('tcg_marketplace_price')) else None #current_price = Decimal(str(row.get('tcg_marketplace_price'))) if not pd.isna(row.get('tcg_marketplace_price')) else None
total_quantity = str(row.get('total_quantity')) if not pd.isna(row.get('total_quantity')) else "0" total_quantity = str(row.get('total_quantity')) if not pd.isna(row.get('total_quantity')) else "0"
added_quantity = str(row.get('add_to_quantity')) if not pd.isna(row.get('add_to_quantity')) else "0" added_quantity = str(row.get('add_to_quantity')) if not pd.isna(row.get('add_to_quantity')) else "0"
quantity = int(total_quantity) + int(added_quantity) quantity = int(total_quantity) + int(added_quantity)
@ -219,9 +222,9 @@ class PricingService:
new_price = Decimal('0.25') new_price = Decimal('0.25')
# Avoid huge price drops # Avoid huge price drops
if current_price is not None and Decimal(str(((current_price - new_price) / current_price))) > Decimal('0.5'): #if current_price is not None and Decimal(str(((current_price - new_price) / current_price))) > Decimal('0.5'):
logger.warning(f"Price drop too large for row: {row}") #logger.warning(f"Price drop too large for row: {row}")
new_price = current_price #new_price = current_price
# Round to 2 decimal places # Round to 2 decimal places
new_price = new_price.quantize(TWO_PLACES, rounding=ROUND_HALF_UP) new_price = new_price.quantize(TWO_PLACES, rounding=ROUND_HALF_UP)
@ -236,7 +239,6 @@ class PricingService:
TCG Low: {tcg_low} TCG Low: {tcg_low}
TCG Low Shipping: {tcg_low_shipping} TCG Low Shipping: {tcg_low_shipping}
TCG Market Price: {tcg_market_price} TCG Market Price: {tcg_market_price}
Current Price: {current_price}
Total Quantity: {total_quantity} Total Quantity: {total_quantity}
Added Quantity: {added_quantity} Added Quantity: {added_quantity}
Quantity: {quantity} Quantity: {quantity}
@ -349,7 +351,7 @@ class PricingService:
if null_product_ids: if null_product_ids:
logger.warning(f"The following tcgplayer_ids could not be mapped to a product_id: {null_product_ids}") logger.warning(f"The following tcgplayer_ids could not be mapped to a product_id: {null_product_ids}")
price_lookup = self.get_all_prices_for_products(df['product_id'].unique()) price_lookup = self.get_latest_prices_for_products(df['product_id'].unique())
# Apply price columns # Apply price columns
df = df.apply(lambda row: self.apply_price_to_df_columns(row, price_lookup), axis=1) df = df.apply(lambda row: self.apply_price_to_df_columns(row, price_lookup), axis=1)