Skip to content

Commit 1416f23

Browse files
committed
update to leaderboard generation, ghosts drop off after new submissions sigma is better or is 48 old or is worse than current, change values calculated from last game, not last leaderboard
1 parent b0c6641 commit 1416f23

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

sql/2_generate_leaderboard.sql

+27-17
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,42 @@ select
1818
s.user_id, s.submission_id, s.version,
1919
@count1 := @count1 + 1 as seq,
2020
@rank := if(s.latest > 0, @count2 := @count2 + 1 , null) as rank,
21-
r.rank - @rank as rank_change,
22-
s.mu as mu, s.mu - r.mu as mu_change,
23-
s.sigma as sigma, s.sigma - r.sigma as sigma_change,
24-
@skill := if(3*s.sigma>s.mu, 0.0, s.mu - s.sigma * 3) as skill, @skill - r.skill as skill_change,
21+
gp.rank - @rank as rank_change,
22+
s.mu as mu, gp.mu_after - gp.mu_before as mu_change,
23+
s.sigma as sigma, gp.sigma_after - gp.sigma_before as sigma_change,
24+
@skill := if(3*s.sigma>s.mu, 0.0, s.mu - s.sigma * 3) as skill,
25+
(gp.mu_after - gp.sigma_after * 3) - (gp.mu_before - gp.sigma_before * 3) as skill_change,
2526
s.latest, timediff(now(),s.timestamp) as age
2627
from
2728
(select * from submission order by mu - sigma * 3 desc, mu desc, sigma asc, submission_id asc) s
2829
-- inner join to ensure both user and submission record exists
2930
inner join user u
3031
on s.user_id = u.user_id
31-
left outer join ranking r
32-
on s.submission_id = r.submission_id and r.leaderboard_id = @last_leader,
32+
-- these 2 joins bring in the last game_player for a submission
33+
left outer join (select submission_id, max(game_id) as game_id
34+
from game_player
35+
group by submission_id) gpmax
36+
on gpmax.submission_id = s.submission_id
37+
left outer join game_player gp
38+
on gp.submission_id = gpmax.submission_id
39+
and gp.game_id = gpmax.game_id,
3340
(select @count1 := 0) c1,
3441
(select @count2 := 0) c2
3542
where s.latest = 1
36-
or s.submission_id in (
37-
select submission_id
38-
from ranking
39-
where leaderboard_id = @last_leader
40-
and seq in (
41-
select min(seq)
42-
from ranking
43-
where leaderboard_id = @last_leader
44-
group by user_id
45-
)
46-
);
43+
-- ghost requirements
44+
or (
45+
-- can only be 48 hours old
46+
s.timestamp > timestampadd(hour, -400, current_timestamp)
47+
-- must have smaller sigma (more confident than current)
48+
and s.sigma = (select min(sigma)
49+
from submission s2
50+
where s2.user_id = s.user_id)
51+
-- must be a higher rank
52+
and (s.mu - s.sigma * 3) > (select mu - sigma * 3
53+
from submission s3
54+
where s3.user_id = s.user_id
55+
and latest = 1)
56+
);
4757

4858
-- sigma will be updated on a per game basis
4959
-- update submission

0 commit comments

Comments
 (0)