Skip to content

Commit 5aaa2b5

Browse files
committed
chore: fix clear rate definition in map service
1 parent e087553 commit 5aaa2b5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
create or replace view maps_published as
2+
select m.id,
3+
m.owner,
4+
m.m_type,
5+
m.created_at,
6+
m.updated_at,
7+
m.authz_key,
8+
m.verification,
9+
m.file_id,
10+
m.legacy_map_id,
11+
m.published_id,
12+
m.published_at,
13+
m.quality_override,
14+
m.opt_name,
15+
m.opt_icon,
16+
m.size,
17+
m.opt_variant,
18+
m.opt_subvariant,
19+
m.opt_spawn_point,
20+
m.opt_only_sprint,
21+
m.opt_no_sprint,
22+
m.opt_no_jump,
23+
m.opt_no_sneak,
24+
m.opt_boat,
25+
m.opt_extra,
26+
m.opt_tags,
27+
m.protocol_version,
28+
m.contest,
29+
m.listed,
30+
m.ext,
31+
coalesce(stats.play_count, 0) as play_count,
32+
coalesce(stats.win_count, 0) as win_count,
33+
coalesce(likes.total_likes, 0) as total_likes,
34+
coalesce(stats.clear_rate, 0) as clear_rate,
35+
case
36+
when stats.play_count < 10 then -1
37+
when stats.clear_rate < 0.05 then 4
38+
when stats.clear_rate < 0.25 then 3
39+
when stats.clear_rate < 0.5 then 2
40+
when stats.clear_rate < 0.75 then 1
41+
else 0
42+
end as difficulty
43+
from public.maps as m
44+
left join (select map_id, play_count, win_count, win_count::float / nullif(play_count, 0)::float as clear_rate
45+
from map_stats) stats on m.id = stats.map_id
46+
left join (select map_id, sum(case when rating = 1 then 1 when rating = 2 then -1 else 0 end) as total_likes
47+
from map_ratings
48+
group by map_id) likes on m.id = likes.map_id
49+
where m.deleted_at is null
50+
and m.published_at is not null
51+
and m.published_id is not null;

0 commit comments

Comments
 (0)