Change result end point to output artist info

This commit is contained in:
Esa Kataja
2025-05-15 20:53:23 +03:00
parent e863a8a088
commit 0aee5ca021
2 changed files with 25 additions and 4 deletions
+17 -4
View File
@@ -141,18 +141,30 @@ CREATE TABLE CountryCodes (
CREATE VIEW ReviewSummaryGlobal AS CREATE VIEW ReviewSummaryGlobal AS
SELECT SELECT
song_id, song_id,
cc.name_fi AS country_fi,
cc.name_sv AS country_sv,
s.artist,
s.title,
COUNT(*) AS total_reviews, COUNT(*) AS total_reviews,
AVG(score_song) AS avg_score_song, AVG(score_song) AS avg_score_song,
AVG(score_show) AS avg_score_show, AVG(score_show) AS avg_score_show,
AVG(score_costume) AS avg_score_costume, AVG(score_costume) AS avg_score_costume,
AVG((score_song + score_show + score_costume)/3) AS avg_total_score AVG((score_song + score_show + score_costume)/3) AS avg_total_score
FROM Review FROM Review r
GROUP BY song_id; JOIN Song s ON r.song_id = s.id
JOIN CountryCodes cc ON s.country = cc.code
GROUP BY song_id, cc.name_fi, cc.name_sv, s.artist, s.title
ORDER BY avg_total_score DESC;
CREATE VIEW ReviewSummaryByTeam AS CREATE VIEW ReviewSummaryByTeam AS
SELECT SELECT
r.song_id, r.song_id,
cc.name_fi AS country_fi,
cc.name_sv AS country_sv,
s.artist,
s.title,
u.team_id, u.team_id,
COUNT(*) AS total_reviews,
AVG(r.score_song) AS avg_score_song, AVG(r.score_song) AS avg_score_song,
AVG(r.score_show) AS avg_score_show, AVG(r.score_show) AS avg_score_show,
AVG(r.score_costume) AS avg_score_costume, AVG(r.score_costume) AS avg_score_costume,
@@ -160,8 +172,9 @@ SELECT
FROM Review r FROM Review r
JOIN "User" u ON r.user_id = u.id JOIN "User" u ON r.user_id = u.id
JOIN Song s ON r.song_id = s.id JOIN Song s ON r.song_id = s.id
GROUP BY r.song_id, u.team_id JOIN CountryCodes cc ON s.country = cc.code
ORDER BY r.song_id, u.team_id; GROUP BY r.song_id, u.team_id, cc.name_fi, cc.name_sv, s.artist, s.title
ORDER BY avg_total_score DESC;
-- Insert country codes data -- Insert country codes data
INSERT INTO CountryCodes (code, name_en, name_fi, name_sv) VALUES ('ALB', 'Albania', 'Albania', 'Albanien'); INSERT INTO CountryCodes (code, name_en, name_fi, name_sv) VALUES ('ALB', 'Albania', 'Albania', 'Albanien');
+8
View File
@@ -3,6 +3,14 @@ from pydantic import BaseModel, Field
class Result(BaseModel): class Result(BaseModel):
song_id: int = Field(description="ID of the song", examples=[1]) song_id: int = Field(description="ID of the song", examples=[1])
country_fi: str = Field(
description="Country of the song in Finnish", examples=["Suomi"]
)
country_sv: str = Field(
description="Country of the song in Swedish", examples=["Sverige"]
)
artist: str = Field(description="Artist of the song", examples=["Käärijä"])
title: str = Field(description="Title of the song", examples=["Cha cha cha"])
total_reviews: int = Field(0, description="Total number of reviews", examples=[10]) total_reviews: int = Field(0, description="Total number of reviews", examples=[10])
avg_score_song: float = Field( avg_score_song: float = Field(
description="Average score for song quality", examples=[85.5] description="Average score for song quality", examples=[85.5]