Compare commits

..

No commits in common. "ac755ab7b029a6848006bbc3175bd43b417acb37" and "f91bc1b826933853e37c6a6b62bf97c174c08064" have entirely different histories.

View file

@ -22,7 +22,7 @@ def get_top_shows(limit: int = 10, session: Session = Depends(get_session)):
) )
.join(Rating, Rating.show_id == Show.id) .join(Rating, Rating.show_id == Show.id)
.join(Venue, Show.venue_id == Venue.id) .join(Venue, Show.venue_id == Venue.id)
# Rating FK already filters via join .where(Rating.entity_type == "show")
.group_by(Show.id, Venue.id) .group_by(Show.id, Venue.id)
.having(func.count(Rating.id) >= 1) .having(func.count(Rating.id) >= 1)
.order_by(desc("avg_score"), desc("rating_count")) .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(Song, Performance.song_id == Song.id)
.join(Show, Performance.show_id == Show.id) .join(Show, Performance.show_id == Show.id)
.join(Venue, Show.venue_id == Venue.id) .join(Venue, Show.venue_id == Venue.id)
# Rating FK already filters via join .where(Rating.entity_type == "performance")
.group_by(Performance.id, Song.id, Show.id, Venue.id) .group_by(Performance.id, Song.id, Show.id, Venue.id)
.having(func.count(Rating.id) >= 1) .having(func.count(Rating.id) >= 1)
.order_by(desc("avg_score"), desc("rating_count")) .order_by(desc("avg_score"), desc("rating_count"))
@ -80,16 +80,19 @@ def get_top_performances(limit: int = 20, session: Session = Depends(get_session
@router.get("/venues/top") @router.get("/venues/top")
def get_top_venues(limit: int = 10, session: Session = Depends(get_session)): def get_top_venues(limit: int = 10, session: Session = Depends(get_session)):
"""Get top rated venues based on show ratings there""" """Get top rated venues based on show ratings there?"""
# Aggregate ratings from shows played at each venue # 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.
query = ( query = (
select( select(
Venue, Venue,
func.avg(Rating.score).label("avg_score"), func.avg(Rating.score).label("avg_score"),
func.count(Rating.id).label("rating_count") func.count(Rating.id).label("rating_count")
) )
.join(Show, Show.venue_id == Venue.id) .join(Rating, Rating.venue_id == Venue.id)
.join(Rating, Rating.show_id == Show.id) .where(Rating.entity_type == "venue")
.group_by(Venue.id) .group_by(Venue.id)
.having(func.count(Rating.id) >= 1) .having(func.count(Rating.id) >= 1)
.order_by(desc("avg_score")) .order_by(desc("avg_score"))
@ -98,6 +101,9 @@ def get_top_venues(limit: int = 10, session: Session = Depends(get_session)):
results = session.exec(query).all() results = session.exec(query).all()
# Fallback: if no direct venue ratings, maybe average the shows played there?
# Keeping it simple for now.
return [ return [
{ {
"venue": venue, "venue": venue,