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

This commit is contained in:
zman 2025-04-11 12:06:56 -04:00
parent 3ec9fef3cf
commit c234285788

View File

@ -154,7 +154,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('tcgplayer_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)
@ -163,10 +163,10 @@ class PricingService:
logger.warning(f"Missing pricing data for row: {row}") logger.warning(f"Missing pricing data for row: {row}")
row['new_price'] = None row['new_price'] = None
return row return row
# Define precision for rounding
TWO_PLACES = Decimal('0.01') TWO_PLACES = Decimal('0.01')
# Apply pricing rules # Original markup bands
markup_bands = { markup_bands = {
2.53: (Decimal('0.01'), Decimal('0.50')), 2.53: (Decimal('0.01'), Decimal('0.50')),
1.42: (Decimal('0.51'), Decimal('1.00')), 1.42: (Decimal('0.51'), Decimal('1.00')),
@ -179,38 +179,53 @@ class PricingService:
1.01: (Decimal('200.01'), Decimal('1000.00')) 1.01: (Decimal('200.01'), Decimal('1000.00'))
} }
# Adjust markups if quantity is high
if quantity > 3: if quantity > 3:
quantity_markup = Decimal('0.1') adjusted_bands = {}
for markup in markup_bands: increment = Decimal('0.10')
markup = markup + quantity_markup for markup, price_range in zip(markup_bands.keys(), markup_bands.values()):
quantity_markup = quantity_markup - Decimal('0.01') new_markup = Decimal(str(markup)) + increment
adjusted_bands[new_markup] = price_range
if FREE_SHIPPING: increment -= Decimal('0.01')
free_shipping_markup = Decimal('0.05') markup_bands = adjusted_bands
for markup in markup_bands:
markup = markup + free_shipping_markup
free_shipping_markup = free_shipping_markup - Decimal('0.005')
# Apply the smoothed markup
new_price = self.smooth_markup(tcg_market_price, markup_bands)
if tcg_low_shipping is not None and tcg_low_shipping < new_price: if FREE_SHIPPING:
new_price = tcg_low_shipping if tcg_low_shipping:
tcg_compare_price = tcg_low_shipping
elif tcg_low:
tcg_compare_price = tcg_low + Decimal('1.31')
else:
logger.warning(f"No TCG low or shipping price available for row: {row}")
row['new_price'] = None
return row
else:
tcg_compare_price = tcg_low
if tcg_compare_price is None:
logger.warning(f"No TCG low price available for row: {row}")
row['new_price'] = None
return row
# Apply the smoothed markup
new_price = self.smooth_markup(tcg_compare_price, markup_bands)
# Enforce minimum price
if new_price < Decimal('0.25'): if new_price < Decimal('0.25'):
new_price = Decimal('0.25') new_price = Decimal('0.25')
if current_price / new_price > Decimal('0.25'): # Avoid huge price drops
if current_price is not None and new_price / current_price > Decimal('0.25'):
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
# Ensure exactly 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)
# Convert back to float or string as needed for your dataframe
# Convert back to float for dataframe
row['new_price'] = float(new_price) row['new_price'] = float(new_price)
return row return row
def default_pricing_algo(self, row: pd.Series) -> pd.Series: def default_pricing_algo(self, row: pd.Series) -> pd.Series:
"""Default pricing algorithm with complex pricing rules""" """Default pricing algorithm with complex pricing rules"""