feat: refactor project

This commit is contained in:
Stijnvandenbroek
2026-03-06 14:51:26 +00:00
parent c908d96921
commit 535a09fd75
28 changed files with 1136 additions and 51 deletions

View File

@@ -21,10 +21,7 @@ from app.schemas import (
router = APIRouter()
SAMPLE_JOIN = (
f" inner join {settings.ELO_SCHEMA}.sample_listings as s"
f" on l.global_id = s.global_id"
)
SAMPLE_JOIN = f" inner join {settings.ELO_SCHEMA}.sample_listings as s on l.global_id = s.global_id"
@router.get("/matchup", response_model=MatchupResponse)
@@ -48,15 +45,13 @@ def get_matchup(
)
recent = db.execute(text(load_sql("recent_pairs.sql")))
recent_pairs = {
frozenset([r.listing_a_id, r.listing_b_id]) for r in recent
}
recent_pairs = {frozenset([r.listing_a_id, r.listing_b_id]) for r in recent}
weights = [1.0 / (l.comparison_count + 1) ** 1.5 for l in listings]
weights = [1.0 / (x.comparison_count + 1) ** 1.5 for x in listings]
first = random.choices(listings, weights=weights, k=1)[0]
remaining = [l for l in listings if l.global_id != first.global_id]
remaining_weights = [1.0 / (l.comparison_count + 1) ** 1.5 for l in remaining]
remaining = [x for x in listings if x.global_id != first.global_id]
remaining_weights = [1.0 / (x.comparison_count + 1) ** 1.5 for x in remaining]
second = remaining[0]
for _ in range(20):
@@ -159,8 +154,7 @@ def get_stats(db: Session = Depends(get_db)):
dist_rows = db.execute(text(load_sql("elo_distribution.sql")))
elo_distribution = [
{"bucket": f"{int(r.bucket)}-{int(r.bucket) + 49}", "count": r.count}
for r in dist_rows
{"bucket": f"{int(r.bucket)}-{int(r.bucket) + 49}", "count": r.count} for r in dist_rows
]
recent_rows = db.execute(text(load_sql("history.sql")), {"limit": 10})