11DROP VIEW IF EXISTS v_player_elo;
22
3-
4- -- Create a view that shows ELO changes for each match for each player
53CREATE OR REPLACE VIEW v_player_elo AS
6- WITH match_player_elo_data AS (
7- SELECT
8- m .id AS match_id,
9- mo." type" AS " type" ,
10- m .created_at AS match_created_at,
11- p .steam_id AS player_steam_id,
12- p .name AS player_name,
13- CASE
14- WHEN m .winning_lineup_id = mlp .match_lineup_id THEN ' win'
15- ELSE ' loss'
16- END AS match_result,
17- get_elo_for_match(m .id , p .steam_id ) AS elo_data
18- FROM
19- matches m
20- JOIN
21- match_lineup_players mlp ON (mlp .match_lineup_id = m .lineup_1_id OR mlp .match_lineup_id = m .lineup_2_id )
22- JOIN
23- players p ON p .steam_id = mlp .steam_id
24- JOIN
25- match_options mo ON mo .id = m .match_options_id
26- )
274SELECT
28- match_id,
29- " type" ,
30- match_created_at,
31- player_steam_id,
32- player_name,
33- match_result,
5+ m .id AS match_id,
6+ mo." type" AS " type" ,
7+ m .created_at AS match_created_at,
8+ p .steam_id AS player_steam_id,
9+ p .name AS player_name,
10+ CASE
11+ WHEN m .winning_lineup_id = mlp .match_lineup_id THEN ' win'
12+ ELSE ' loss'
13+ END AS match_result,
14+ -- Extract ELO data using LATERAL join for better performance
3415 (elo_data- >> ' current_elo' )::INTEGER + (elo_data- >> ' elo_change' )::INTEGER AS updated_elo,
3516 (elo_data- >> ' current_elo' )::INTEGER AS current_elo,
3617 (elo_data- >> ' elo_change' )::INTEGER AS elo_change,
@@ -48,4 +29,12 @@ SELECT
4829 (elo_data- >> ' damage_percent' )::FLOAT AS damage_percent,
4930 (elo_data- >> ' performance_multiplier' )::FLOAT AS performance_multiplier
5031FROM
51- match_player_elo_data;
32+ matches m
33+ JOIN
34+ match_lineup_players mlp ON (mlp .match_lineup_id = m .lineup_1_id OR mlp .match_lineup_id = m .lineup_2_id )
35+ JOIN
36+ players p ON p .steam_id = mlp .steam_id
37+ JOIN
38+ match_options mo ON mo .id = m .match_options_id
39+ CROSS JOIN LATERAL
40+ get_elo_for_match(m .id , p .steam_id ) AS elo_data;
0 commit comments