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

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

View File

@@ -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'])