fix: Correct leaderboards queries to use proper Rating FKs
This commit is contained in:
parent
c1ceb65d04
commit
591ab8f6d3
1 changed files with 6 additions and 12 deletions
|
|
@ -22,7 +22,7 @@ def get_top_shows(limit: int = 10, session: Session = Depends(get_session)):
|
|||
)
|
||||
.join(Rating, Rating.show_id == Show.id)
|
||||
.join(Venue, Show.venue_id == Venue.id)
|
||||
.where(Rating.entity_type == "show")
|
||||
# Rating FK already filters via join
|
||||
.group_by(Show.id, Venue.id)
|
||||
.having(func.count(Rating.id) >= 1)
|
||||
.order_by(desc("avg_score"), desc("rating_count"))
|
||||
|
|
@ -57,7 +57,7 @@ def get_top_performances(limit: int = 20, session: Session = Depends(get_session
|
|||
.join(Song, Performance.song_id == Song.id)
|
||||
.join(Show, Performance.show_id == Show.id)
|
||||
.join(Venue, Show.venue_id == Venue.id)
|
||||
.where(Rating.entity_type == "performance")
|
||||
# Rating FK already filters via join
|
||||
.group_by(Performance.id, Song.id, Show.id, Venue.id)
|
||||
.having(func.count(Rating.id) >= 1)
|
||||
.order_by(desc("avg_score"), desc("rating_count"))
|
||||
|
|
@ -80,19 +80,16 @@ def get_top_performances(limit: int = 20, session: Session = Depends(get_session
|
|||
|
||||
@router.get("/venues/top")
|
||||
def get_top_venues(limit: int = 10, session: Session = Depends(get_session)):
|
||||
"""Get top rated venues based on show ratings there?"""
|
||||
# A venue's rating is often derivative of the shows there, or specific venue ratings.
|
||||
# Let's assume venue rating directly for now if entity_type='venue' exists,
|
||||
# otherwise we might avg show ratings. Let's start with direct venue ratings.
|
||||
|
||||
"""Get top rated venues based on show ratings there"""
|
||||
# Aggregate ratings from shows played at each venue
|
||||
query = (
|
||||
select(
|
||||
Venue,
|
||||
func.avg(Rating.score).label("avg_score"),
|
||||
func.count(Rating.id).label("rating_count")
|
||||
)
|
||||
.join(Rating, Rating.venue_id == Venue.id)
|
||||
.where(Rating.entity_type == "venue")
|
||||
.join(Show, Show.venue_id == Venue.id)
|
||||
.join(Rating, Rating.show_id == Show.id)
|
||||
.group_by(Venue.id)
|
||||
.having(func.count(Rating.id) >= 1)
|
||||
.order_by(desc("avg_score"))
|
||||
|
|
@ -101,9 +98,6 @@ def get_top_venues(limit: int = 10, session: Session = Depends(get_session)):
|
|||
|
||||
results = session.exec(query).all()
|
||||
|
||||
# Fallback: if no direct venue ratings, maybe average the shows played there?
|
||||
# Keeping it simple for now.
|
||||
|
||||
return [
|
||||
{
|
||||
"venue": venue,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue