-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
with | ||
json_game_lineups as ( | ||
|
||
select | ||
json(value) as raw_json_row, | ||
str_split(filename, '/')[4] as season, | ||
json_extract_string(raw_json_row, '$.game_id')::integer as game_id, | ||
row_number() over (partition by game_id order by season desc) as n | ||
|
||
from {{ source("raw_tfmkt", "game_lineups") }} | ||
|
||
), | ||
home_club_starting_lineup as ( | ||
|
||
select | ||
unnest(json_transform(json_extract(raw_json_row, '$.home_club.starting_lineup'), '["JSON"]')) as json_row, | ||
(str_split(json_extract_string(raw_json_row, '$.home_club.href'), '/')[5])::integer as club_id, | ||
'starting_lineup' as "type", | ||
game_id | ||
from json_game_lineups | ||
|
||
where n = 1 | ||
|
||
), | ||
home_club_substitutes as ( | ||
|
||
select | ||
unnest(json_transform(json_extract(raw_json_row, '$.home_club.substitutes'), '["JSON"]')) as json_row, | ||
(str_split(json_extract_string(raw_json_row, '$.home_club.href'), '/')[5])::integer as club_id, | ||
'substitutes' as "type", | ||
game_id | ||
from json_game_lineups | ||
|
||
where n = 1 | ||
|
||
), | ||
away_club_starting_lineup as ( | ||
|
||
select | ||
unnest(json_transform(json_extract(raw_json_row, '$.away_club.starting_lineup'), '["JSON"]')) as json_row, | ||
(str_split(json_extract_string(raw_json_row, '$.away_club.href'), '/')[5])::integer as club_id, | ||
'starting_lineup' as "type", | ||
game_id | ||
from json_game_lineups | ||
|
||
where n = 1 | ||
|
||
), | ||
away_club_substitutes as ( | ||
|
||
select | ||
unnest(json_transform(json_extract(raw_json_row, '$.away_club.substitutes'), '["JSON"]')) as json_row, | ||
(str_split(json_extract_string(raw_json_row, '$.away_club.href'), '/')[5])::integer as club_id, | ||
'substitutes' as "type", | ||
game_id | ||
from json_game_lineups | ||
|
||
where n = 1 | ||
|
||
), | ||
all_game_lineups as ( | ||
|
||
select * from home_club_starting_lineup | ||
UNION ALL | ||
select * from home_club_substitutes | ||
UNION ALL | ||
select * from away_club_starting_lineup | ||
UNION ALL | ||
select * from away_club_substitutes | ||
|
||
) | ||
|
||
select | ||
game_id, | ||
club_id, | ||
"type", | ||
(json_row ->> 'number') as "number", | ||
(str_split((json_row ->> 'href'), '/')[5])::integer as player_id, | ||
(json_row ->> 'name') as "player_name", | ||
(json_row ->> 'team_captain')::integer as "team_captain", | ||
(json_row ->> 'position') as "position", | ||
|
||
from all_game_lineups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
with game_lineups_cte as ( | ||
|
||
select * from {{ ref('base_game_lineups') }} | ||
|
||
) | ||
|
||
select | ||
{{ dbt_utils.generate_surrogate_key([ | ||
'game_id', | ||
'player_id', | ||
'club_id', | ||
'type', | ||
'player_name', | ||
'position', | ||
'team_captain', | ||
'number' | ||
]) }} as game_lineups_id, | ||
game_lineups_cte.* | ||
|
||
from game_lineups_cte | ||
|
||
order by game_id, club_id, "type" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from transfermarkt_datasets.core.asset import Asset | ||
from transfermarkt_datasets.core.schema import Schema, Field | ||
|
||
class CurGameLineupsAsset(Asset): | ||
|
||
name = "cur_game_lineups" | ||
description = """ | ||
The `games_lineups` asset contains one row per game player in the dataset. | ||
Players are extracted from the game ["line-ups"](https://www.transfermarkt.co.uk/spielbericht/aufstellung/spielbericht/3098550) in transfermarkt and they are tied to one particular `game`, identified by the `game_id` column. | ||
""" | ||
file_name = "game_lineups.csv.gz" | ||
|
||
def __init__(self, *args, **kwargs) -> None: | ||
super().__init__(*args, **kwargs) | ||
|
||
self.schema = Schema( | ||
fields=[ | ||
Field( | ||
name='game_lineups_id', | ||
type='string', | ||
description="Surrogate key" | ||
), | ||
Field(name='game_id', type='integer'), | ||
Field(name='player_id', type='integer'), | ||
Field(name='club_id', type='integer'), | ||
Field(name='type', type='string'), | ||
Field(name='player_name', type='string'), | ||
Field(name='team_captain', type='string'), | ||
Field(name='number', type='string'), | ||
Field(name='position', type='string'), | ||
] | ||
) | ||
|
||
self.schema.primary_key = [ | ||
'game_id', | ||
'player_id', | ||
'club_id', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters