Skip to content

Commit 039474e

Browse files
committed
bug: fix elo factors
1 parent 6bf0af4 commit 039474e

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

hasura/functions/match/match_player_elo.sql

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,38 +142,38 @@ BEGIN
142142

143143
SELECT COALESCE(SUM(damage), 0) INTO _player_damage
144144
FROM player_damages
145-
WHERE match_id = match_record.id AND attacker_steam_id = player_record.steam_id;
145+
WHERE match_id = match_record.id AND attacker_steam_id = player_record.steam_id AND attacker_steam_id IS NOT NULL;
146146

147147
-- Get team's total performance metrics
148148
SELECT COUNT(*) INTO _team_total_kills
149149
FROM player_kills pk
150150
JOIN match_lineup_players mlp ON pk.attacker_steam_id = mlp.steam_id
151-
WHERE match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
151+
WHERE pk.match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
152152

153153
SELECT COUNT(*) INTO _team_total_deaths
154154
FROM player_kills pk
155155
JOIN match_lineup_players mlp ON pk.attacked_steam_id = mlp.steam_id
156-
WHERE match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
156+
WHERE pk.match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
157157

158158
SELECT COUNT(*) INTO _team_total_assists
159159
FROM player_assists pa
160160
JOIN match_lineup_players mlp ON pa.attacker_steam_id = mlp.steam_id
161-
WHERE match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
161+
WHERE pa.match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
162162

163-
SELECT COALESCE(SUM(damage), 0) INTO _team_total_damage
163+
SELECT COALESCE(SUM(pd.damage), 0) INTO _team_total_damage
164164
FROM player_damages pd
165165
JOIN match_lineup_players mlp ON pd.attacker_steam_id = mlp.steam_id
166-
WHERE match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id;
166+
WHERE pd.match_id = match_record.id AND mlp.match_lineup_id = _player_lineup_id AND pd.attacker_steam_id IS NOT NULL;
167167

168168
-- Calculate player's KDA (Kills + Assists / Deaths, with a minimum of 1 death to avoid division by zero)
169-
_player_kda := (_player_kills + _player_assists) / GREATEST(_player_deaths, 1);
169+
_player_kda := (_player_kills + _player_assists)::FLOAT / GREATEST(_player_deaths, 1)::FLOAT;
170170

171171
-- Calculate team's average KDA
172-
_team_avg_kda := (_team_total_kills + _team_total_assists) / GREATEST(_team_total_deaths, 1);
172+
_team_avg_kda := (_team_total_kills + _team_total_assists)::FLOAT / GREATEST(_team_total_deaths, 1)::FLOAT;
173173

174174
-- Calculate player's damage percentage
175175
_player_damage_percent := CASE
176-
WHEN _team_total_damage > 0 THEN _player_damage / _team_total_damage
176+
WHEN _team_total_damage > 0 THEN _player_damage::FLOAT / _team_total_damage::FLOAT
177177
ELSE 0
178178
END;
179179

@@ -220,8 +220,8 @@ BEGIN
220220
'deaths', _player_deaths,
221221
'assists', _player_assists,
222222
'damage', _player_damage,
223-
'kda', _player_kda,
224-
'team_avg_kda', _team_avg_kda,
223+
'kda', _player_kda::FLOAT,
224+
'team_avg_kda', _team_avg_kda::FLOAT,
225225
'damage_percent', _player_damage_percent,
226226
'performance_multiplier', _performance_multiplier
227227
);

0 commit comments

Comments
 (0)