agg add file, skip foil api pricing, update pricing algo

This commit is contained in:
zman 2025-03-18 12:11:39 -04:00
parent 2800135375
commit 86498d54b4
4 changed files with 60 additions and 26 deletions

View File

@ -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 = 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
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: if tcg_low is None or tcg_low_shipping is None:
logger.warning(f"Missing pricing data for row: {row}") logger.warning(f"Missing pricing data for row: {row}")
@ -132,23 +135,28 @@ class PricingService:
# Apply pricing rules # Apply pricing rules
if tcg_market_price < Decimal('1') and tcg_market_price > Decimal('0.25'): 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'): elif tcg_market_price < Decimal('0.25'):
new_price = Decimal('0.25') new_price = Decimal('0.25')
elif tcg_low < Decimal('5') or tcg_low_shipping < Decimal('5'): elif tcg_market_price < Decimal('5'):
new_price = tcg_low + ((abs(tcg_market_price - tcg_low)) * Decimal('0.75')) new_price = tcg_market_price * Decimal('1.15')
elif tcg_low_shipping > Decimal('20'): elif tcg_market_price < Decimal('10'):
new_price = tcg_low_shipping * Decimal('1.0125') new_price = tcg_market_price * Decimal('1.1')
else: elif tcg_market_price < Decimal('20'):
new_price = tcg_market_price * Decimal('1.03') new_price = tcg_market_price * Decimal('1.03')
elif tcg_market_price < Decimal('50'):
# if new price is less than half of market price, set to 90% market new_price = tcg_market_price * Decimal('1.0125')
if new_price < (tcg_market_price / Decimal('2')): elif tcg_market_price < Decimal('100'):
new_price = tcg_market_price * Decimal('0.85') new_price = tcg_market_price * Decimal('1.0025')
else:
new_price = tcg_market_price * Decimal('1.1')
if new_price < Decimal('0.25'): if new_price < Decimal('0.25'):
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 # Ensure exactly 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)

View File

@ -22,6 +22,7 @@ from sqlalchemy.exc import SQLAlchemyError
from app.schemas.file import CreateFileRequest from app.schemas.file import CreateFileRequest
import os import os
from app.services.util._docker import DockerUtil from app.services.util._docker import DockerUtil
from sqlalchemy import func
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -514,18 +515,39 @@ class TCGPlayerService:
raise raise
def open_box_cards_to_tcgplayer_inventory_df(self, open_box_ids: List[str]) -> pd.DataFrame: def open_box_cards_to_tcgplayer_inventory_df(self, open_box_ids: List[str]) -> pd.DataFrame:
tcgcards = (self.db.query(OpenBoxCard, CardTCGPlayer) # Using sqlalchemy to group and sum quantities for duplicate TCGplayer IDs
.filter(OpenBoxCard.open_box_id.in_(open_box_ids)) tcgcards = (self.db.query(
.join(CardTCGPlayer, OpenBoxCard.card_id == CardTCGPlayer.product_id) CardTCGPlayer.product_id,
.all()) 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: if not tcgcards:
return None return None
# Create dataframe # Create dataframe directly from the query results
df = pd.DataFrame([(tcg.product_id, tcg.tcgplayer_id, tcg.product_line, tcg.set_name, tcg.product_name, df = pd.DataFrame(tcgcards,
tcg.title, tcg.number, tcg.rarity, tcg.condition, obc.quantity)
for obc, tcg in tcgcards],
columns=['product_id', 'tcgplayer_id', 'product_line', 'set_name', 'product_name', columns=['product_id', 'tcgplayer_id', 'product_line', 'set_name', 'product_name',
'title', 'number', 'rarity', 'condition', 'quantity']) 'title', 'number', 'rarity', 'condition', 'quantity'])

View File

@ -147,6 +147,10 @@ class TCGPlayerAPIService:
if not manabox_card or not tcgplayer_card: if not manabox_card or not tcgplayer_card:
logger.warning(f"Card with product id {product_id} missing in either Manabox or TCGPlayer") logger.warning(f"Card with product id {product_id} missing in either Manabox or TCGPlayer")
return None 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 # get scryfall id, tcgplayer id, and tcgplayer sku
scryfall_id = manabox_card.scryfall_id scryfall_id = manabox_card.scryfall_id
tcgplayer_sku = tcgplayer_card.tcgplayer_id tcgplayer_sku = tcgplayer_card.tcgplayer_id

View File

@ -2,20 +2,20 @@ curl -J http://192.168.1.41:8000/api/tcgplayer/inventory/update --remote-name
curl -J -X POST http://192.168.1.41:8000/api/tcgplayer/inventory/add \ curl -J -X POST http://192.168.1.41:8000/api/tcgplayer/inventory/add \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"open_box_ids": ["02d14109-ad0c-41f9-b49f-24134f962c1a"]}' \ -d '{"open_box_ids": ["1d646fd3-05a9-46c6-8bfb-2e1162ff6f65"]}' \
--remote-name --remote-name
curl -X POST http://192.168.1.41:8000/api/boxes \ curl -X POST http://192.168.1.41:8000/api/boxes \
-F "type=play" \ -F "type=play" \
-F "set_code=MKM" \ -F "set_code=MH3" \
-F "sku=195166245744" \ -F "sku=1234" \
-F "num_cards_expected=504" -F "num_cards_expected=504"
curl -X POST "http://192.168.1.41:8000/api/boxes/53d2848e-86df-48ab-b9fb-d9b3bbfec114/open" \ curl -X POST "http://192.168.1.41:8000/api/boxes/dc29def4-3704-4f6c-b3e1-d3a1be729197/open" \
-F "product_id=53d2848e-86df-48ab-b9fb-d9b3bbfec114" \ -F "product_id=dc29def4-3704-4f6c-b3e1-d3a1be729197" \
-F "file_ids=8676a5f4-c508-4623-a42d-8b1c98acf5f6" \ -F "file_ids=466dac7a-481d-495c-8831-f011708c1e3d" \
-F "date_opened=2025-02-24" -F "date_opened=2025-03-17"
curl -X POST "http://192.168.1.41:8000/api/processOrders" \ curl -X POST "http://192.168.1.41:8000/api/processOrders" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"order_ids": ["E576ED4C-92196E-33E46","E576ED4C-B472A8-D6A4D","E576ED4C-B7AFD9-CBCA7","E576ED4C-F7F088-52BDE","E576ED4C-D3CAD9-F0642","E576ED4C-DA2FE7-6E606","E576ED4C-697357-D18D7","E576ED4C-7358D0-6B581","E576ED4C-2CAFBD-8D85E","E576ED4C-B4767E-72F78","E576ED4C-F0FE0E-5824F","E576ED4C-22BF76-ED926","E576ED4C-7A8059-6274E","E576ED4C-521E7D-BC5FA","E576ED4C-803C08-CB830","E576ED4C-790E48-10D1D","E576ED4C-0695F7-8715A","E576ED4C-CE8807-F142E","E576ED4C-EE581D-49448","E576ED4C-A5CAFC-E0C3B","E576ED4C-3094C4-28057","E576ED4C-14EC0D-8E4E6","E576ED4C-EDA04E-C8B93","E576ED4C-9155CF-35A0D","E576ED4C-56F053-8EF8B","E576ED4C-FA5B60-4DC85","E576ED4C-D74A72-7E742","E576ED4C-83CCB2-BB172","E576ED4C-262560-16B1A","E576ED4C-3B43FE-11A4A","E576ED4C-D7C0C5-526E1","E576ED4C-F045FB-CA986","E576ED4C-F41FF5-63374","E576ED4C-C5D26D-BCEBE","E576ED4C-0E4D56-AEE7E","E576ED4C-DD4ED4-AD401","E576ED4C-D823D6-25A29","E576ED4C-273363-D0375","E576ED4C-248400-A972A","E576ED4C-B18E0F-C55AE","E576ED4C-080F7F-7342B","E576ED4C-EF072E-FBBFA","E576ED4C-9E881F-1365E","E576ED4C-F85BB9-D2F24","E576ED4C-69777C-2725F","E576ED4C-187E7A-2F37A","E576ED4C-D7E80E-1F222","E576ED4C-BA84EF-71EEA","E576ED4C-ACD33A-6C589","E576ED4C-14A8FD-9792E","E576ED4C-C5CFFC-047AB","E576ED4C-F5BCCD-B85BB","E576ED4C-8FE692-377C5","E576ED4C-C60956-9380E","E576ED4C-E4C83F-104E4","E576ED4C-58D0C2-05AC0","E576ED4C-F8C4E7-7ABE0","E576ED4C-27B812-8132B","E576ED4C-68C830-17929","E576ED4C-3620EF-F5D1E","E576ED4C-ED4A56-F18AF"]}' -d '{"order_ids": ["E576ED4C-A472E7-36237","E576ED4C-16EDF6-A340B","E576ED4C-A25B9C-A8855","E576ED4C-0E1A20-C6350","E576ED4C-9E8C21-3A249","E576ED4C-3825F0-5A5CC","E576ED4C-628925-6348B","E576ED4C-5F4314-6E3D2","E576ED4C-60E0B9-69D1D","E576ED4C-4BEC42-B2D0A","E576ED4C-5253F2-E2E16","E576ED4C-C08EA2-F51B4","E576ED4C-EE350E-BA82C","E576ED4C-CB067C-21150","E576ED4C-85DE3E-4E518","E576ED4C-27DB4A-A7729","E576ED4C-91A537-2AEBA","E576ED4C-3961D0-4F5A9","E576ED4C-EB7B7D-DBE0D","E576ED4C-1F9576-A9351","E576ED4C-7EBF1E-6FDB9","E576ED4C-F549E2-C558B","E576ED4C-215B45-4F177","E576ED4C-572FAA-004F7","E576ED4C-9D5F33-1A3C4","E576ED4C-87276B-63EC8","E576ED4C-2143E7-4DE1B","E576ED4C-41E56A-04D55","E576ED4C-789397-BF6AD","E576ED4C-2F3F46-154FE","E576ED4C-EFCBEE-3FE93","E576ED4C-3ADBAE-7CA1B","E576ED4C-D9F68F-A5E6F","E576ED4C-DEA6E2-8B590","E576ED4C-86D96B-DC5C4","E576ED4C-EDFABA-67C3C","E576ED4C-C57373-3F638","E576ED4C-B2C2B4-FF53B","E576ED4C-3788E5-B3653","E576ED4C-8A573A-BB51B","E576ED4C-497380-63F5C","E576ED4C-A6C3F2-C7BF2","E576ED4C-FAC80B-148F3","E576ED4C-ECF1F3-AF3A4"]}'