code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0088_update_game_stats.sql (about) 1 -- +goose Up 2 3 create or replace view game_stats as 4 with 5 game_epochs as ( 6 select distinct 7 game_id, epoch_id 8 from rewards 9 where 10 game_id is not null 11 ), 12 dispatch_strategies AS ( 13 SELECT DISTINCT 14 ON (game_id) game_id, dispatch_strategy 15 FROM transfers 16 WHERE 17 transfer_type = 'Recurring' 18 ORDER BY game_id, vega_time DESC 19 ), 20 game_rewards as ( 21 select 22 r.*, t.dispatch_strategy, tm.team_id, tmr.rank as member_rank, tr.rank as team_rank, tmr.total_rewards, tr.total_rewards as team_total_rewards, 'ENTITY_SCOPE_TEAMS' as entity_scope 23 from 24 rewards r 25 join game_epochs ge on r.game_id = ge.game_id 26 and r.epoch_id = ge.epoch_id 27 JOIN dispatch_strategies t ON r.game_id = t.game_id 28 AND t.dispatch_strategy ->> 'entity_scope' = '2' 29 join team_members tm on r.party_id = tm.party_id 30 left join game_team_rankings tr on r.game_id = tr.game_id 31 and r.epoch_id = tr.epoch_id 32 and tm.team_id = tr.team_id 33 left join game_team_member_rankings tmr on r.game_id = tmr.game_id 34 and r.epoch_id = tmr.epoch_id 35 and tm.team_id = tmr.team_id 36 and r.party_id = tmr.party_id 37 union all 38 select 39 r.*, t.dispatch_strategy, null as team_id, tmr.rank as member_rank, null as team_rank, tmr.total_rewards, null as team_total_rewards, 'ENTITY_SCOPE_INDIVIDUALS' as entity_scope 40 from 41 rewards r 42 join game_epochs ge on r.game_id = ge.game_id 43 and r.epoch_id = ge.epoch_id 44 JOIN dispatch_strategies t ON r.game_id = t.game_id 45 AND t.dispatch_strategy ->> 'entity_scope' = '1' 46 left join game_individual_rankings tmr on r.game_id = tmr.game_id 47 and r.epoch_id = tmr.epoch_id 48 and r.party_id = tmr.party_id 49 ) 50 select * 51 from game_rewards; 52 53 create or replace view game_stats_current as 54 with 55 game_epochs as ( 56 select game_id, max(epoch_id) as epoch_id 57 from rewards 58 where 59 game_id is not null 60 group by 61 game_id 62 ), 63 dispatch_strategies AS ( 64 SELECT DISTINCT 65 ON (game_id) game_id, dispatch_strategy 66 FROM transfers 67 WHERE 68 transfer_type = 'Recurring' 69 ORDER BY game_id, vega_time DESC 70 ), 71 game_rewards as ( 72 select 73 r.*, t.dispatch_strategy, tm.team_id, tmr.rank as member_rank, tr.rank as team_rank, tmr.total_rewards, 'ENTITY_SCOPE_TEAMS' as entity_scope 74 from 75 rewards r 76 join game_epochs ge on r.game_id = ge.game_id 77 and r.epoch_id = ge.epoch_id 78 JOIN dispatch_strategies t ON r.game_id = t.game_id 79 AND t.dispatch_strategy ->> 'entity_scope' = '2' 80 join team_members tm on r.party_id = tm.party_id 81 left join game_team_rankings tr on r.game_id = tr.game_id 82 and r.epoch_id = tr.epoch_id 83 and tm.team_id = tr.team_id 84 left join game_team_member_rankings tmr on r.game_id = tmr.game_id 85 and r.epoch_id = tmr.epoch_id 86 and tm.team_id = tmr.team_id 87 and r.party_id = tmr.party_id 88 union all 89 select 90 r.*, t.dispatch_strategy, null as team_id, tmr.rank as member_rank, null as team_rank, tmr.total_rewards, 'ENTITY_SCOPE_INDIVIDUALS' as entity_scope 91 from 92 rewards r 93 join game_epochs ge on r.game_id = ge.game_id 94 and r.epoch_id = ge.epoch_id 95 JOIN dispatch_strategies t ON r.game_id = t.game_id 96 AND t.dispatch_strategy ->> 'entity_scope' = '1' 97 left join game_individual_rankings tmr on r.game_id = tmr.game_id 98 and r.epoch_id = tmr.epoch_id 99 and r.party_id = tmr.party_id 100 ) 101 select * 102 from game_rewards; 103 104 -- +goose Down 105 106 create or replace view game_stats as 107 with 108 game_epochs as ( 109 select distinct 110 game_id, epoch_id 111 from rewards 112 where 113 game_id is not null 114 ), 115 game_rewards as ( 116 select 117 r.*, t.dispatch_strategy, tm.team_id, tmr.rank as member_rank, tr.rank as team_rank, tmr.total_rewards, tr.total_rewards as team_total_rewards, 'ENTITY_SCOPE_TEAMS' as entity_scope 118 from 119 rewards r 120 join game_epochs ge on r.game_id = ge.game_id 121 and r.epoch_id = ge.epoch_id 122 join transfers t on r.game_id = t.game_id 123 and t.transfer_type = 'Recurring' 124 join team_members tm on r.party_id = tm.party_id 125 left join game_team_rankings tr on r.game_id = tr.game_id 126 and r.epoch_id = tr.epoch_id 127 and tm.team_id = tr.team_id 128 left join game_team_member_rankings tmr on r.game_id = tmr.game_id 129 and r.epoch_id = tmr.epoch_id 130 and tm.team_id = tmr.team_id 131 and r.party_id = tmr.party_id 132 where 133 dispatch_strategy ->> 'entity_scope' = '2' 134 union all 135 select 136 r.*, t.dispatch_strategy, null as team_id, tmr.rank as member_rank, null as team_rank, tmr.total_rewards, null as team_total_rewards, 'ENTITY_SCOPE_INDIVIDUALS' as entity_scope 137 from 138 rewards r 139 join game_epochs ge on r.game_id = ge.game_id 140 and r.epoch_id = ge.epoch_id 141 join transfers t on r.game_id = t.game_id 142 and t.transfer_type = 'Recurring' 143 left join game_individual_rankings tmr on r.game_id = tmr.game_id 144 and r.epoch_id = tmr.epoch_id 145 and r.party_id = tmr.party_id 146 where 147 dispatch_strategy ->> 'entity_scope' = '1' 148 ) 149 select * 150 from game_rewards; 151 152 create or replace view game_stats_current as 153 with 154 game_epochs as ( 155 select game_id, max(epoch_id) as epoch_id 156 from rewards 157 where 158 game_id is not null 159 group by 160 game_id 161 ), 162 game_rewards as ( 163 select 164 r.*, t.dispatch_strategy, tm.team_id, tmr.rank as member_rank, tr.rank as team_rank, tmr.total_rewards, 'ENTITY_SCOPE_TEAMS' as entity_scope 165 from 166 rewards r 167 join game_epochs ge on r.game_id = ge.game_id 168 and r.epoch_id = ge.epoch_id 169 join transfers t on r.game_id = t.game_id 170 and t.transfer_type = 'Recurring' 171 join team_members tm on r.party_id = tm.party_id 172 left join game_team_rankings tr on r.game_id = tr.game_id 173 and r.epoch_id = tr.epoch_id 174 and tm.team_id = tr.team_id 175 left join game_team_member_rankings tmr on r.game_id = tmr.game_id 176 and r.epoch_id = tmr.epoch_id 177 and tm.team_id = tmr.team_id 178 and r.party_id = tmr.party_id 179 where 180 dispatch_strategy ->> 'entity_scope' = '2' 181 union all 182 select 183 r.*, t.dispatch_strategy, null as team_id, tmr.rank as member_rank, null as team_rank, tmr.total_rewards, 'ENTITY_SCOPE_INDIVIDUALS' as entity_scope 184 from 185 rewards r 186 join game_epochs ge on r.game_id = ge.game_id 187 and r.epoch_id = ge.epoch_id 188 join transfers t on r.game_id = t.game_id 189 and t.transfer_type = 'Recurring' 190 left join game_individual_rankings tmr on r.game_id = tmr.game_id 191 and r.epoch_id = tmr.epoch_id 192 and r.party_id = tmr.party_id 193 where 194 dispatch_strategy ->> 'entity_scope' = '1' 195 ) 196 select * 197 from game_rewards;