{"database": "my_database", "private": false, "path": "/my_database", "size": 91439104, "tables": [{"name": "gamedata", "columns": ["game_id", "season_id", "away_team_id", "away_team_score", "home_team_id", "home_team_score", "game_status", "game_date", "game_attendance", "home_team_shots", "away_team_shots", "game_number", "venue_id"], "primary_keys": ["game_id"], "count": 25649, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [{"other_table": "gamepenalties", "column": "game_id", "other_column": "game_id"}, {"other_table": "gameofficial", "column": "game_id", "other_column": "game_id"}, {"other_table": "gameroster", "column": "game_id", "other_column": "game_id"}], "outgoing": []}, "private": false}, {"name": "gamegoals", "columns": ["id", "game_id", "home", "period_id", "time_of_goal_seconds", "team_id", "goal_type", "x_location", "y_location", "location_set", "power_play", "empty_net", "penalty_shot", "short_handed", "insurance_goal", "game_winning", "game_tieing", "scorer_goal_num", "goal_scorer_player_id", "assist1_player_id", "assist2_player_id"], "primary_keys": ["id"], "count": 148068, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "gameofficial", "columns": ["game_id", "person_id", "official_type_id"], "primary_keys": ["game_id", "person_id"], "count": 88315, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": [{"other_table": "gamedata", "column": "game_id", "other_column": "game_id"}]}, "private": false}, {"name": "gamepenalties", "columns": ["id", "game_id", "home", "period_id", "powerplay", "bench", "penalty_shot", "minutes", "penalty", "time_of_penalty_seconds", "player_penalized", "player_server"], "primary_keys": ["id"], "count": 304075, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": [{"other_table": "gamedata", "column": "game_id", "other_column": "game_id"}]}, "private": false}, {"name": "gameroster", "columns": ["game_id", "player_id", "team_id", "starter"], "primary_keys": ["game_id", "player_id", "team_id"], "count": null, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": [{"other_table": "gamedata", "column": "game_id", "other_column": "game_id"}]}, "private": false}, {"name": "official", "columns": ["person_id", "jersey_number"], "primary_keys": ["person_id"], "count": 795, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "penalty_type", "columns": ["penalty_type_id", "penalty_description", "penalty_class_id"], "primary_keys": ["penalty_type_id"], "count": 159, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": [{"other_table": "penaltyclass", "column": "penalty_class_id", "other_column": "penalty_class_id"}]}, "private": false}, {"name": "penaltyclass", "columns": ["penalty_class_id", "penalty_class_description"], "primary_keys": ["penalty_class_id"], "count": 7, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [{"other_table": "penalty_type", "column": "penalty_class_id", "other_column": "penalty_class_id"}], "outgoing": []}, "private": false}, {"name": "person", "columns": ["person_id", "first_name", "last_name", "birth"], "primary_keys": ["person_id"], "count": 795, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "player", "columns": ["id", "first_name", "last_name", "position", "height", "weight", "shoots", "birth", "birth_place", "draft_team", "draft_round", "draft_pick"], "primary_keys": ["id"], "count": 8253, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "scheduled_games", "columns": ["game_id", "home_team_id", "away_team_id", "game_date"], "primary_keys": ["game_id"], "count": 88, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": [{"other_table": "team", "column": "away_team_id", "other_column": "team_id"}, {"other_table": "team", "column": "home_team_id", "other_column": "team_id"}]}, "private": false}, {"name": "season", "columns": ["season_id", "season_name", "shortname", "career", "playoff", "start_date", "end_date"], "primary_keys": ["season_id"], "count": 74, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "sqlite_sequence", "columns": ["name", "seq"], "primary_keys": [], "count": 2, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}, {"name": "team", "columns": ["team_id", "team_code", "active", "name", "city", "nickname"], "primary_keys": ["team_id"], "count": 73, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [{"other_table": "scheduled_games", "column": "team_id", "other_column": "away_team_id"}, {"other_table": "scheduled_games", "column": "team_id", "other_column": "home_team_id"}], "outgoing": []}, "private": false}, {"name": "venue", "columns": ["venue_id", "name"], "primary_keys": ["venue_id"], "count": 157, "hidden": false, "fts_table": null, "foreign_keys": {"incoming": [], "outgoing": []}, "private": false}], "hidden_count": 0, "views": [{"name": "available_seasons", "private": false}], "queries": [{"params": ["team"], "sql": "with current_season_games as (\nselect count(*) as game_count\nfrom gamedata g\nleft join team ht on g.home_team_id = ht.team_id\nleft join team at on g.away_team_id = at.team_id\nleft join season s on g.season_id = s.season_id\nwhere s.end_date >= date('now')\nand s.career = 1\nand s.playoff = 0\nand (ht.name = :team or at.name = :team)\n),\ndata as (\nselect\ng.game_date\n, g.game_status\n, ht.name as home_team\n, g.home_team_score\n, at.name as away_team\n, g.away_team_score\n, s.season_name as season\n, s.season_id\n, s.end_date\n, row_number() over (partition by g.season_id order by g.game_date) as game_seq\n, case\nwhen\n(ht.name = :team and g.home_team_score > g.away_team_score) or (at.name = :team and g.home_team_score < g.away_team_score)\nthen\n   1\nelse\n   0\nend as 'W'\n, case\n   when g.game_status = 'Final' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'L'\n, case\n   when g.game_status = 'Final OT' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'OTL'\n, case\n   when g.game_status = 'Final SO' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'SOL'\nfrom gamedata g\nleft join team ht on g.home_team_id = ht.team_id\nleft join team at on g.away_team_id = at.team_id\nleft join season s on g.season_id = s.season_id\nwhere (ht.name = :team or at.name = :team)\nand s.career = 1\nand s.playoff = 0\n)\nselect d.season_id\n, d.season\n, sum(2*W+OTL+SOL) as 'Points'\n, count(*) as 'Games'\n, sum(W) as 'Wins'\n, sum(L) as 'Losses'\n, sum(OTL) as 'OTL'\n, sum(SOL) as 'SOL'\nfrom data d\nwhere d.game_seq <= (select count(*) from gamedata g\n                     left join team ht on g.home_team_id = ht.team_id\n                     left join team at on g.away_team_id = at.team_id\n                     left join season s on g.season_id = s.season_id\n                     where s.end_date >= date('now')\n                     and s.career = 1\n                     and s.playoff = 0\n                     and (ht.name = :team or at.name = :team))\ngroup by d.season_id, d.season\norder by d.season_id desc\nlimit 2", "title": "Year over Year Performance", "hide_sql": true, "description": "Compares performance at same point in season - last completed season vs current/ongoing season", "name": "yoy_performance", "private": false}, {"params": ["team", "season_id"], "sql": "with data as (\n    select ht.name as home_team\n    , at.name as away_team\n    , g.game_date\n    , g.home_team_score\n    , g.away_team_score\n    , g.game_status\n    , case\n        when ht.name = :team and g.home_team_score > g.away_team_score then 1\n        when at.name = :team and g.home_team_score < g.away_team_score then 1\n        else 0\n    end as 'W'\n    , case\n        when ht.name = :team and g.game_status = 'Final' and g.home_team_score < g.away_team_score then 1\n        when at.name = :team and g.game_status = 'Final' and g.home_team_score > g.away_team_score then 1\n        else 0\n    end as 'L'\n    , case\n        when ht.name = :team and (g.game_status = 'Final OT' and g.game_status != 'Final SO') and g.home_team_score < g.away_team_score then 1\n        when at.name = :team and (g.game_status = 'Final OT' and g.game_status != 'Final SO') and g.home_team_score > g.away_team_score then 1\n        else 0\n    end as 'OTL'\n    , case\n        when ht.name = :team and g.game_status = 'Final SO' and g.home_team_score < g.away_team_score then 1\n        when at.name = :team and g.game_status = 'Final SO' and g.home_team_score > g.away_team_score then 1\n        else 0\n    end as 'SOL'\nfrom gamedata g\nleft join team ht on g.home_team_id = ht.team_id\nleft join team at on g.away_team_id = at.team_id\nwhere (ht.name = :team or at.name = :team)\nand g.season_id = :season_id)\n\nselect\n    :team as team,\n    game_date,\n    SUM(W) OVER (ORDER BY game_date) as wins,\n    SUM(L) OVER (ORDER BY game_date) as losses,\n    SUM(OTL) OVER (ORDER BY game_date) as otl,\n    SUM(SOL) OVER (ORDER BY game_date) as sol,\n    SUM(W + L + OTL + SOL) OVER (ORDER BY game_date) as games_played,\n    SUM(W * 2 + OTL + SOL) OVER (ORDER BY game_date) as points\nfrom data\norder by game_date;", "title": "Team Performance By Day", "hide_sql": true, "description": "Returns cumulative performance of a team by day. Query the 'available_seasons' view to find the season_id for your desired season.", "name": "team_performance_by_day", "private": false}], "allow_execute_sql": true, "query_ms": 30.847590416669846}