1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| /* TODO slightly off -- jsut sums finals and original together */
with rank as (
select round,player, percent_rank() over (
partition by round
order by sum(score)
) as rank from match
group by 1,2 order by 1
),
card as (
select round,player,card1 as card from deck
union select round,player,card2 as card from deck
union select round,player,card3 as card from deck),
new as (
select min(card.round) as rnd, card, card.player
from match join card on match.round = card.round and match.player = card.player
group by 2 order by 1),
newcnt as (select player,count(1) as count from new group by 1),
/* select * from newcnt; */
/* TODO -- median percentile, not mean */
allpl as (
select deck.player, count(1) as cnt, printf('%.2f', avg(rank.rank)) as avg_rank,
printf('%.2f', (newcnt.count / 3.0) / count(1)) as avg_newness from deck
join rank on deck.round = rank.round
and deck.player = rank.player
join newcnt on deck.player = newcnt.player
group by 1 order by 4 desc)
select * from allpl;
|