From eb9a60d53bd55a8ef79d1f82d9e378dae9f6fcb2 Mon Sep 17 00:00:00 2001 From: DrFrankinStein Date: Sun, 2 Mar 2025 14:23:12 -0500 Subject: [PATCH 1/3] Add NCP indicator in rounds s18 query --- queries/public/s18/rounds_s18.sql | 50 ++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/queries/public/s18/rounds_s18.sql b/queries/public/s18/rounds_s18.sql index 6b5e08d..4461e9c 100644 --- a/queries/public/s18/rounds_s18.sql +++ b/queries/public/s18/rounds_s18.sql @@ -1,19 +1,55 @@ select + -- Get serie and game id m.id as match_id, r.id as round_id, - fph.title as "Home", - tslh.stats->'stats'->'core'->'goals' as "Home Goals", - fpa.title as "Away", - tsla.stats->'stats'->'core'->'goals' as "Away Goals" + + -- Get home team name + fph.title as home, + + -- Get home goals from team stats or 0 if NCP + CASE + WHEN r."invalidationId" IS NOT NULL OR + m."invalidationId" IS NOT NULL OR + tslh.stats IS NULL THEN 0 + ELSE (tslh.stats->'stats'->'core'->'goals')::INT + END as home_goals, + + -- Get away team name + fpa.title as away, + + -- Get away goals from team stats or 0 if NCP + CASE + WHEN r."invalidationId" IS NOT NULL OR + m."invalidationId" IS NOT NULL OR + tsla.stats IS NULL THEN 0 + ELSE (tsla.stats->'stats'->'core'->'goals')::INT + END as away_goals, + + -- Get winner team name + CASE + WHEN r."homeWon" THEN fph.title + ELSE fpa.title + END as winner, + + -- If invalidation is filled in either serie or game, consider this game NCP + r."invalidationId" IS NOT NULL OR m."invalidationId" IS NOT NULL as is_ncp from sprocket.round as r -inner join sprocket.match m on m.id = r."matchId" +inner join sprocket."match" m on m.id = r."matchId" -- match in quotation to avoid syntax warning inner join sprocket.match_parent mp on mp.id = m."matchParentId" inner join sprocket.schedule_fixture sf on sf.id = mp."fixtureId" inner join sprocket.schedule_group sg on sg.id = sf."scheduleGroupId" inner join sprocket.franchise_profile fph on sf."homeFranchiseId" = fph."franchiseId" inner join sprocket.franchise_profile fpa on sf."awayFranchiseId" = fpa."franchiseId" -inner join sprocket.team_stat_line tslh on (tslh."roundId" = r.id and tslh."teamName" = fph.title) -inner join sprocket.team_stat_line tsla on (tsla."roundId" = r.id and tsla."teamName" = fpa.title) +-- We want to add the team stats if they exist, so left join +left join sprocket.team_stat_line tslh on (tslh."roundId" = r.id and tslh."teamName" = fph.title) +left join sprocket.team_stat_line tsla on (tsla."roundId" = r.id and tsla."teamName" = fpa.title) + +-- Season 18 ID is 291 where sg."parentGroupId" = 291 + +-- Order by series then individual games id +order by + m.id, + r.id \ No newline at end of file From 00a00dc02fb04e31e6d16cc38a4c94c3917c0577 Mon Sep 17 00:00:00 2001 From: DrFrankinStein Date: Sun, 2 Mar 2025 14:28:26 -0500 Subject: [PATCH 2/3] Fix tabs and spaces --- queries/public/s18/rounds_s18.sql | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/queries/public/s18/rounds_s18.sql b/queries/public/s18/rounds_s18.sql index 4461e9c..f8e84c9 100644 --- a/queries/public/s18/rounds_s18.sql +++ b/queries/public/s18/rounds_s18.sql @@ -1,36 +1,36 @@ select - -- Get serie and game id + -- Get serie and game id m.id as match_id, r.id as round_id, - + -- Get home team name fph.title as home, - + -- Get home goals from team stats or 0 if NCP CASE WHEN r."invalidationId" IS NOT NULL OR m."invalidationId" IS NOT NULL OR tslh.stats IS NULL THEN 0 - ELSE (tslh.stats->'stats'->'core'->'goals')::INT + ELSE (tslh.stats->'stats'->'core'->'goals')::INT END as home_goals, - + -- Get away team name fpa.title as away, - + -- Get away goals from team stats or 0 if NCP - CASE + CASE WHEN r."invalidationId" IS NOT NULL OR m."invalidationId" IS NOT NULL OR tsla.stats IS NULL THEN 0 - ELSE (tsla.stats->'stats'->'core'->'goals')::INT + ELSE (tsla.stats->'stats'->'core'->'goals')::INT END as away_goals, - + -- Get winner team name CASE WHEN r."homeWon" THEN fph.title ELSE fpa.title END as winner, - + -- If invalidation is filled in either serie or game, consider this game NCP r."invalidationId" IS NOT NULL OR m."invalidationId" IS NOT NULL as is_ncp @@ -51,5 +51,5 @@ where sg."parentGroupId" = 291 -- Order by series then individual games id order by - m.id, - r.id \ No newline at end of file + m.id, + r.id \ No newline at end of file From 47a90d81af0188e530f8ee249580bf8f1d4f1984 Mon Sep 17 00:00:00 2001 From: DrFrankinStein Date: Wed, 5 Mar 2025 22:52:37 -0500 Subject: [PATCH 3/3] Reverting to existing column names to avoid breaking changes --- queries/public/s18/rounds_s18.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/queries/public/s18/rounds_s18.sql b/queries/public/s18/rounds_s18.sql index f8e84c9..9802294 100644 --- a/queries/public/s18/rounds_s18.sql +++ b/queries/public/s18/rounds_s18.sql @@ -4,7 +4,7 @@ select r.id as round_id, -- Get home team name - fph.title as home, + fph.title as "Home", -- Get home goals from team stats or 0 if NCP CASE @@ -12,10 +12,10 @@ select m."invalidationId" IS NOT NULL OR tslh.stats IS NULL THEN 0 ELSE (tslh.stats->'stats'->'core'->'goals')::INT - END as home_goals, + END as "Home Goals", -- Get away team name - fpa.title as away, + fpa.title as "Away", -- Get away goals from team stats or 0 if NCP CASE @@ -23,7 +23,7 @@ select m."invalidationId" IS NOT NULL OR tsla.stats IS NULL THEN 0 ELSE (tsla.stats->'stats'->'core'->'goals')::INT - END as away_goals, + END as "Away Goals", -- Get winner team name CASE