Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 123 additions & 40 deletions server/db/migration/V1__tables.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ insert into
coalesce(max(continent_rank), 0)
from
ranks_average r
inner join users u on u.wca_id = r.person_id
inner join countries c on c.iso2 = u.country_iso2
inner join persons p on p.wca_id = r.person_id
inner join countries c on c.iso2 = p.country_id
where
c.continent_id = c2.id
and r.event_id = e.id
Expand All @@ -37,15 +37,15 @@ select
countries c
left join continents c2 on c.continent_id = c2.id
where
u.country_iso2 = c.iso2
p.country_id = c.id
) region,
(
select
'Continent'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Average'
Expand Down Expand Up @@ -74,15 +74,16 @@ select
) events
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_average r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
and r.person_id = p.wca_id
left join countries c on c.iso2 = p.country_id
left join continents c2 on c.continent_id = c2.id
left join default_ranks dr on dr.event_id = e.id
and dr.region = c2.name
where
wca_id is not null
and sub_id = 1
and exists (
-- Some events has no averages and this excludes them to avoid adding 1 into the sum
select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ insert into
coalesce(max(continent_rank), 0)
from
ranks_single r
inner join users u on u.wca_id = r.person_id
inner join countries c on c.iso2 = u.country_iso2
inner join persons p on p.wca_id = r.person_id
inner join countries c on c.iso2 = p.country_id
where
c.continent_id = c2.id
and r.event_id = e.id
Expand All @@ -37,15 +37,15 @@ select
countries c
left join continents c2 on c.continent_id = c2.id
where
u.country_iso2 = c.iso2
p.country_id = c.id
) region,
(
select
'Continent'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Single'
Expand Down Expand Up @@ -74,14 +74,15 @@ select
) events
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_single r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
and r.person_id = p.wca_id
left join countries c on c.iso2 = p.country_id
left join continents c2 on c.continent_id = c2.id
left join default_ranks dr on dr.event_id = e.id
and dr.region = c2.name
where
wca_id is not null
and sub_id = 1
group by
wca_id
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ insert into
coalesce(max(country_rank), 0)
from
ranks_average r
inner join users u on u.wca_id = r.person_id
inner join persons p on p.wca_id = r.person_id
where
r.event_id = e.id
and u.country_iso2 = c2.iso2
and p.country_id = c2.iso2
) + 1 default_rank
from
events e,
Expand All @@ -35,15 +35,15 @@ select
from
countries c
where
u.country_iso2 = c.iso2
p.country_id = c.id
) region,
(
select
'Country'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Average'
Expand Down Expand Up @@ -72,14 +72,15 @@ select
) events
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_average r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
and r.person_id = p.wca_id
left join countries c on c.iso2 = p.country_id
left join default_ranks dr on dr.event_id = e.id
and dr.region = c.iso2
where
wca_id is not null
and sub_id = 1
and exists (
-- Some events has no averages and this excludes them to avoid adding 1 into the sum
select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ from
and dr.region = c.id
where
wca_id is not null
and sub_id = 1
group by
wca_id,
country_id,
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/resources/db/query/sumofranks/getMeta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ select
)
)
from
Events e
events e
where
e.`rank` < 900
and (
Expand All @@ -24,9 +24,9 @@ select
select
1
from
RanksAverage ra
ranks_average ra
where
ra.eventId = e.id
ra.event_id = e.id
)
)
) availableEvents
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ create table if not exists sum_of_ranks (
region_type varchar(20) not null,
wca_id varchar(10) not null,
name varchar(255),
country_iso2 varchar(2),
country_iso2 varchar(100),
result_type varchar(7) not null,
overall int default null,
events json not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"regionRank": 1,
"wcaId": "2014GERB01",
"name": "Henri Gerber",
"countryIso2": "DE",
"name": "2014GERB01",
"countryIso2": "Germany",
"overall": 3277,
"events": [
{
Expand Down Expand Up @@ -167,8 +167,8 @@
{
"regionRank": 2,
"wcaId": "2015CECC01",
"name": "Vicenzo Guerino Cecchini",
"countryIso2": "BR",
"name": "2015CECC01 Cecchini",
"countryIso2": "Brazil",
"overall": 5495,
"events": [
{
Expand Down Expand Up @@ -329,8 +329,8 @@
{
"regionRank": 3,
"wcaId": "2014FRIT02",
"name": "Oliver Fritz",
"countryIso2": "DE",
"name": "2014FRIT02",
"countryIso2": "Germany",
"overall": 5515,
"events": [
{
Expand Down Expand Up @@ -491,8 +491,8 @@
{
"regionRank": 4,
"wcaId": "2013GERH01",
"name": "Kevin Gerhardt",
"countryIso2": "DE",
"name": "2013GERH01",
"countryIso2": "Germany",
"overall": 6035,
"events": [
{
Expand Down Expand Up @@ -653,8 +653,8 @@
{
"regionRank": 5,
"wcaId": "2015MATT05",
"name": "Enzo Mattos",
"countryIso2": "BR",
"name": "2015MATT05",
"countryIso2": "Brazil",
"overall": 9504,
"events": [
{
Expand Down Expand Up @@ -815,8 +815,8 @@
{
"regionRank": 6,
"wcaId": "2010BENT01",
"name": "Jan Bentlage",
"countryIso2": "DE",
"name": "2010BENT01",
"countryIso2": "Germany",
"overall": 9967,
"events": [
{
Expand Down Expand Up @@ -977,8 +977,8 @@
{
"regionRank": 7,
"wcaId": "2016CETR01",
"name": "Joel Cetra",
"countryIso2": "DE",
"name": "2016CETR01",
"countryIso2": "Germany",
"overall": 11470,
"events": [
{
Expand Down Expand Up @@ -1139,8 +1139,8 @@
{
"regionRank": 8,
"wcaId": "2013BOTZ01",
"name": "Alexander Botz",
"countryIso2": "DE",
"name": "2013BOTZ01",
"countryIso2": "Germany",
"overall": 11710,
"events": [
{
Expand Down Expand Up @@ -1301,8 +1301,8 @@
{
"regionRank": 9,
"wcaId": "2016IHLE01",
"name": "Malte Ihlefeld",
"countryIso2": "DE",
"name": "2016IHLE01",
"countryIso2": "Germany",
"overall": 11859,
"events": [
{
Expand Down Expand Up @@ -1463,8 +1463,8 @@
{
"regionRank": 10,
"wcaId": "2017MAND13",
"name": "Francisco Moraes Mandalozzo",
"countryIso2": "BR",
"name": "2017MAND13 Mandalozzo",
"countryIso2": "Brazil",
"overall": 12063,
"events": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"regionRank": 7,
"wcaId": "2016CETR01",
"name": "Joel Cetra",
"countryIso2": "DE",
"name": "2016CETR01",
"countryIso2": "Germany",
"overall": 11470,
"events": [
{
Expand Down Expand Up @@ -167,8 +167,8 @@
{
"regionRank": 8,
"wcaId": "2013BOTZ01",
"name": "Alexander Botz",
"countryIso2": "DE",
"name": "2013BOTZ01",
"countryIso2": "Germany",
"overall": 11710,
"events": [
{
Expand Down Expand Up @@ -329,8 +329,8 @@
{
"regionRank": 9,
"wcaId": "2016IHLE01",
"name": "Malte Ihlefeld",
"countryIso2": "DE",
"name": "2016IHLE01",
"countryIso2": "Germany",
"overall": 11859,
"events": [
{
Expand Down Expand Up @@ -491,8 +491,8 @@
{
"regionRank": 10,
"wcaId": "2017MAND13",
"name": "Francisco Moraes Mandalozzo",
"countryIso2": "BR",
"name": "2017MAND13 Mandalozzo",
"countryIso2": "Brazil",
"overall": 12063,
"events": [
{
Expand Down Expand Up @@ -653,8 +653,8 @@
{
"regionRank": 11,
"wcaId": "2012WESC01",
"name": "Lucas Wesche",
"countryIso2": "DE",
"name": "2012WESC01",
"countryIso2": "Germany",
"overall": 12268,
"events": [
{
Expand Down Expand Up @@ -815,8 +815,8 @@
{
"regionRank": 12,
"wcaId": "2015KOEN01",
"name": "Christian König",
"countryIso2": "DE",
"name": "2015KOEN01",
"countryIso2": "Germany",
"overall": 13372,
"events": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"regionRank": 31,
"wcaId": "2017SOUZ10",
"name": "Gabriel Lincon Souza",
"countryIso2": "BR",
"name": "2017SOUZ10 Souza",
"countryIso2": "Brazil",
"overall": 44247,
"events": [
{
Expand Down Expand Up @@ -167,8 +167,8 @@
{
"regionRank": 32,
"wcaId": "2011LIMA02",
"name": "Bruno Fonsêca Coelho Lima",
"countryIso2": "BR",
"name": "2011LIMA02 Coelho Lima",
"countryIso2": "Brazil",
"overall": 45708,
"events": [
{
Expand Down Expand Up @@ -329,8 +329,8 @@
{
"regionRank": 33,
"wcaId": "2011LIMA01",
"name": "Allyson Dias de Lima",
"countryIso2": "BR",
"name": "2011LIMA01 de Lima",
"countryIso2": "Brazil",
"overall": 47807,
"events": [
{
Expand Down
Loading