Skip to content

Commit 7f2304e

Browse files
AskaholicBrutus5000
authored andcommitted
Added query to include old ladder games in win ratio calculation
1 parent 758b460 commit 7f2304e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Updates numGames and winGames on the ladder1v1_rating table based on
2+
-- aggregated results from old ladder games.
3+
4+
-- NOTE: If running this manually, this query will increment the existing values,
5+
-- it will not start from 0. Run V65__fix-ladder-win-ratio.sql first to
6+
-- initialize the count correctly.
7+
--
8+
-- Old ladder games are ones that happened before the 'ladder1v1' game mode
9+
-- was added. This means we need to identify them as best we can using other
10+
-- properties:
11+
--
12+
-- Name: always 'Player1 Vs Player2'
13+
-- Number of players: 2 (always human)
14+
-- Color: red or blue (1 or 2)
15+
-- Score: always 1 (win), 0 (loss), or -1 (draw or no result)
16+
-- Start Time: Before the first 'ladder1v1' game
17+
--
18+
-- We perform the player count twice, once with additional filters and once
19+
-- without in order to verify that there are exactly 2 players and they also
20+
-- fullfill the additional requirements.
21+
22+
UPDATE ladder1v1_rating
23+
INNER JOIN (
24+
SELECT
25+
count(score) numGames,
26+
sum(case when score = 1 then 1 else 0 end) winGames,
27+
game_player_stats.playerId playerId
28+
FROM game_stats
29+
INNER JOIN game_player_stats on game_stats.id = game_player_stats.gameId
30+
WHERE
31+
gameMod=0 AND
32+
startTime < '2014-03-22 12:59:25' AND
33+
gameName collate latin1_general_cs LIKE '% Vs %' AND
34+
(
35+
SELECT count(*) FROM game_player_stats
36+
WHERE gameId = game_stats.id
37+
) = 2
38+
AND
39+
(
40+
SELECT count(*) FROM game_player_stats
41+
WHERE gameId = game_stats.id AND
42+
AI = 0 AND
43+
color IN (1, 2) AND
44+
score in (-1, 0, 1)
45+
) = 2
46+
GROUP BY game_player_stats.playerId
47+
) game_records
48+
ON ladder1v1_rating.id = game_records.playerId
49+
SET
50+
ladder1v1_rating.numGames = ladder1v1_rating.numGames + game_records.numGames,
51+
ladder1v1_rating.winGames = ladder1v1_rating.winGames + game_records.winGames
52+
;

0 commit comments

Comments
 (0)