diff --git a/models/marts/player_skill_snapshot.sql b/models/marts/player_skill_snapshot.sql new file mode 100644 index 0000000..b68f874 --- /dev/null +++ b/models/marts/player_skill_snapshot.sql @@ -0,0 +1,75 @@ +{{ config(location='data_export/player_skill_snapshot.parquet') }} + +WITH + matches AS ( + SELECT + match_id, + start_time, + game_type, + lower(game_type) AS game_type_l + FROM {{ ref("matches") }} + WHERE is_ranked = true + ), + players AS ( + SELECT + user_id, + name, + country AS country_code + FROM {{ ref("players") }} + ), + joined AS ( + SELECT + m.start_time, + mp.user_id, + p.name, + p.country_code, + mp.new_skill, + mp.new_uncertainty, + CASE + WHEN m.game_type_l LIKE '%duel%' THEN 'duel' + WHEN m.game_type_l LIKE '%ffa%' THEN 'ffa' + WHEN m.game_type_l LIKE '%large%' THEN 'large' + WHEN m.game_type_l LIKE '%small%' THEN 'small' + END AS game_type + FROM {{ ref("match_players") }} AS mp + INNER JOIN matches AS m ON mp.match_id = m.match_id + INNER JOIN players AS p ON mp.user_id = p.user_id + ), + aggregated AS ( + SELECT + user_id, + arg_max(new_skill, start_time) FILTER (WHERE game_type = 'duel') AS duel_skill, + arg_max(new_uncertainty, start_time) FILTER (WHERE game_type = 'duel') AS duel_skill_un, + arg_max(new_skill, start_time) FILTER (WHERE game_type = 'ffa') AS ffa_skill, + arg_max(new_uncertainty, start_time) FILTER (WHERE game_type = 'ffa') AS ffa_skill_un, + arg_max(new_skill, start_time) FILTER (WHERE game_type = 'large') AS team_skill, + arg_max(new_uncertainty, start_time) FILTER (WHERE game_type = 'large') AS team_skill_un, + arg_max(start_time, start_time) FILTER (WHERE game_type = 'duel') AS last_duel, + arg_max(start_time, start_time) FILTER (WHERE game_type = 'ffa') AS last_ffa, + arg_max(start_time, start_time) FILTER (WHERE game_type = 'large') AS last_team, + arg_max(start_time, start_time) FILTER (WHERE game_type = 'small') AS last_small_team, + arg_max(new_skill, start_time) FILTER (WHERE game_type = 'small') AS small_team_skill, + arg_max(new_uncertainty, start_time) FILTER (WHERE game_type = 'small') AS small_team_skill_un + FROM joined + WHERE game_type IS NOT null + GROUP BY user_id + ) +SELECT + a.user_id AS id, + p.name, + a.duel_skill, + a.duel_skill_un, + a.ffa_skill, + a.ffa_skill_un, + a.team_skill, + a.team_skill_un, + a.last_duel, + a.last_ffa, + a.last_team, + p.country_code, + a.last_small_team, + a.small_team_skill, + a.small_team_skill_un +FROM aggregated AS a +INNER JOIN players AS p ON a.user_id = p.user_id +ORDER BY a.user_id diff --git a/models/marts/schema.yml b/models/marts/schema.yml index 6006613..53930b4 100644 --- a/models/marts/schema.yml +++ b/models/marts/schema.yml @@ -123,8 +123,61 @@ models: - name: name data_type: string description: Current user selected name + data_tests: - unique - not_null - name: country data_type: string description: Country code of the player, e.g. PL, US, or NULL if hidden by player + + - name: player_skill_snapshot + description: Latest OpenSkill snapshot per player and game type. + columns: + - name: id + data_type: bigint + description: Teiserver account id of the user + data_tests: + - unique + - not_null + - name: name + data_type: string + description: Current user selected name + - name: duel_skill + data_type: float + description: Latest duel skill (mu) + - name: duel_skill_un + data_type: float + description: Latest duel uncertainty (sigma) + - name: ffa_skill + data_type: float + description: Latest FFA skill (mu) + - name: ffa_skill_un + data_type: float + description: Latest FFA uncertainty (sigma) + - name: team_skill + data_type: float + description: Latest large team skill (mu) + - name: team_skill_un + data_type: float + description: Latest large team uncertainty (sigma) + - name: last_duel + data_type: timestamp + description: Time of latest duel match for this user + - name: last_ffa + data_type: timestamp + description: Time of latest FFA match for this user + - name: last_team + data_type: timestamp + description: Time of latest large team match for this user + - name: country_code + data_type: string + description: Country code of the player, e.g. PL, US, or NULL if hidden by player + - name: last_small_team + data_type: timestamp + description: Time of latest small team match for this user + - name: small_team_skill + data_type: float + description: Latest small team skill (mu) + - name: small_team_skill_un + data_type: float + description: Latest small team uncertainty (sigma) diff --git a/scripts/build_more_formats.sql b/scripts/build_more_formats.sql index 58d7c3f..5119b30 100644 --- a/scripts/build_more_formats.sql +++ b/scripts/build_more_formats.sql @@ -3,3 +3,4 @@ COPY 'data_export/matches.parquet' TO 'data_export/matches.csv.gz'; COPY 'data_export/match_players.parquet' TO 'data_export/match_players.csv.gz'; COPY 'data_export/players.parquet' TO 'data_export/players.csv.gz'; +COPY 'data_export/player_skill_snapshot.parquet' TO 'data_export/player_skill_snapshot.csv';