agg add file, skip foil api pricing, update pricing algo
This commit is contained in:
@@ -121,6 +121,9 @@ class PricingService:
|
||||
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_market_price = Decimal(str(row.get('tcg_market_price'))) if not pd.isna(row.get('tcg_market_price')) else None
|
||||
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
|
||||
quantity = total_quantity + added_quantity
|
||||
|
||||
if tcg_low is None or tcg_low_shipping is None:
|
||||
logger.warning(f"Missing pricing data for row: {row}")
|
||||
@@ -132,23 +135,28 @@ class PricingService:
|
||||
|
||||
# Apply pricing rules
|
||||
if tcg_market_price < Decimal('1') and tcg_market_price > Decimal('0.25'):
|
||||
new_price = tcg_market_price * Decimal('1.05')
|
||||
new_price = tcg_market_price * Decimal('1.25')
|
||||
elif tcg_market_price < Decimal('0.25'):
|
||||
new_price = Decimal('0.25')
|
||||
elif tcg_low < Decimal('5') or tcg_low_shipping < Decimal('5'):
|
||||
new_price = tcg_low + ((abs(tcg_market_price - tcg_low)) * Decimal('0.75'))
|
||||
elif tcg_low_shipping > Decimal('20'):
|
||||
new_price = tcg_low_shipping * Decimal('1.0125')
|
||||
else:
|
||||
elif tcg_market_price < Decimal('5'):
|
||||
new_price = tcg_market_price * Decimal('1.15')
|
||||
elif tcg_market_price < Decimal('10'):
|
||||
new_price = tcg_market_price * Decimal('1.1')
|
||||
elif tcg_market_price < Decimal('20'):
|
||||
new_price = tcg_market_price * Decimal('1.03')
|
||||
|
||||
# if new price is less than half of market price, set to 90% market
|
||||
if new_price < (tcg_market_price / Decimal('2')):
|
||||
new_price = tcg_market_price * Decimal('0.85')
|
||||
elif tcg_market_price < Decimal('50'):
|
||||
new_price = tcg_market_price * Decimal('1.0125')
|
||||
elif tcg_market_price < Decimal('100'):
|
||||
new_price = tcg_market_price * Decimal('1.0025')
|
||||
else:
|
||||
new_price = tcg_market_price * Decimal('1.1')
|
||||
|
||||
if new_price < Decimal('0.25'):
|
||||
new_price = Decimal('0.25')
|
||||
|
||||
if quantity > 3:
|
||||
new_price = new_price * Decimal('1.1')
|
||||
|
||||
# Ensure exactly 2 decimal places
|
||||
new_price = new_price.quantize(TWO_PLACES, rounding=ROUND_HALF_UP)
|
||||
|
||||
|
@@ -22,6 +22,7 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from app.schemas.file import CreateFileRequest
|
||||
import os
|
||||
from app.services.util._docker import DockerUtil
|
||||
from sqlalchemy import func
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -514,18 +515,39 @@ class TCGPlayerService:
|
||||
raise
|
||||
|
||||
def open_box_cards_to_tcgplayer_inventory_df(self, open_box_ids: List[str]) -> pd.DataFrame:
|
||||
tcgcards = (self.db.query(OpenBoxCard, CardTCGPlayer)
|
||||
.filter(OpenBoxCard.open_box_id.in_(open_box_ids))
|
||||
.join(CardTCGPlayer, OpenBoxCard.card_id == CardTCGPlayer.product_id)
|
||||
.all())
|
||||
# Using sqlalchemy to group and sum quantities for duplicate TCGplayer IDs
|
||||
tcgcards = (self.db.query(
|
||||
CardTCGPlayer.product_id,
|
||||
CardTCGPlayer.tcgplayer_id,
|
||||
CardTCGPlayer.product_line,
|
||||
CardTCGPlayer.set_name,
|
||||
CardTCGPlayer.product_name,
|
||||
CardTCGPlayer.title,
|
||||
CardTCGPlayer.number,
|
||||
CardTCGPlayer.rarity,
|
||||
CardTCGPlayer.condition,
|
||||
func.sum(OpenBoxCard.quantity).label('quantity')
|
||||
)
|
||||
.filter(OpenBoxCard.open_box_id.in_(open_box_ids))
|
||||
.join(CardTCGPlayer, OpenBoxCard.card_id == CardTCGPlayer.product_id)
|
||||
.group_by(
|
||||
CardTCGPlayer.tcgplayer_id,
|
||||
CardTCGPlayer.product_id,
|
||||
CardTCGPlayer.product_line,
|
||||
CardTCGPlayer.set_name,
|
||||
CardTCGPlayer.product_name,
|
||||
CardTCGPlayer.title,
|
||||
CardTCGPlayer.number,
|
||||
CardTCGPlayer.rarity,
|
||||
CardTCGPlayer.condition
|
||||
)
|
||||
.all())
|
||||
|
||||
if not tcgcards:
|
||||
return None
|
||||
|
||||
# Create dataframe
|
||||
df = pd.DataFrame([(tcg.product_id, tcg.tcgplayer_id, tcg.product_line, tcg.set_name, tcg.product_name,
|
||||
tcg.title, tcg.number, tcg.rarity, tcg.condition, obc.quantity)
|
||||
for obc, tcg in tcgcards],
|
||||
# Create dataframe directly from the query results
|
||||
df = pd.DataFrame(tcgcards,
|
||||
columns=['product_id', 'tcgplayer_id', 'product_line', 'set_name', 'product_name',
|
||||
'title', 'number', 'rarity', 'condition', 'quantity'])
|
||||
|
||||
|
@@ -147,6 +147,10 @@ class TCGPlayerAPIService:
|
||||
if not manabox_card or not tcgplayer_card:
|
||||
logger.warning(f"Card with product id {product_id} missing in either Manabox or TCGPlayer")
|
||||
return None
|
||||
mbfoil = manabox_card.foil
|
||||
if str.lower(mbfoil) == 'foil':
|
||||
logger.warning(f"Card with product id {product_id} is foil, skipping")
|
||||
return None
|
||||
# get scryfall id, tcgplayer id, and tcgplayer sku
|
||||
scryfall_id = manabox_card.scryfall_id
|
||||
tcgplayer_sku = tcgplayer_card.tcgplayer_id
|
||||
|
Reference in New Issue
Block a user