Skip to content

Commit

Permalink
Fix broken queries (#103)
Browse files Browse the repository at this point in the history
* Fix avg competition by country

* Fix sum of ranks

* Add nvmrc

* Fix sum of all ranks

* Fix tests, fix most-solves in TDD mode
  • Loading branch information
campos20 committed Aug 14, 2023
1 parent f4cac77 commit 174663e
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 137 deletions.
1 change: 1 addition & 0 deletions client/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.17.6
2 changes: 1 addition & 1 deletion misc/python/statistics/avg_competition_by_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
where
c2.countryId = c.id
and results_posted_at is not null
and c2.`year` = year(current_date())-%(diff)s) m%(diff)s"""
and year(c2.start_date) = year(current_date())-%(diff)s) m%(diff)s"""


def avg_competitions():
Expand Down
6 changes: 3 additions & 3 deletions misc/python/statistics/sum_of_all_ranks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
`rank`
"""

# Repalce %s with Average or Single for different table
# Replace %s with Average or Single for different table
competitors_query = """
select
personId,
Expand All @@ -45,7 +45,7 @@
p.name
from
Ranks%s r
inner join Persons p on r.personId = p.id
inner join Persons p on r.personId = p.wca_id
where
eventId in (
select
Expand All @@ -65,7 +65,7 @@
inner join
(
select%(custom_sub_queries)s
) my_ranks on p.id = ':WCA_ID'
) my_ranks on p.wca_id = ':WCA_ID'
"""

custom_sub_query = """
Expand Down
215 changes: 152 additions & 63 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 @@ -113,14 +113,14 @@ queries:
sqlQuery: |-
select
wca_statistics_person_link_format(personId, personName),
year,
the_year year,
concat(solves, ' / ', attempts)
from
(
SELECT
personId,
personName,
year,
year(competition.start_date) the_year,
sum(
IF(value1 > 0, 1, 0) + IF(value2 > 0, 1, 0) + IF(value3 > 0, 1, 0) + IF(value4 > 0, 1, 0) + IF(value5 > 0, 1, 0)
) solves,
Expand Down Expand Up @@ -158,7 +158,7 @@ queries:
GROUP BY
personId,
personName,
year
year(competition.start_date)
ORDER BY
solves DESC,
attempts
Expand All @@ -168,7 +168,7 @@ queries:
sqlQueryCustom: |-
SELECT
personName,
year whereId,
year(competition.start_date) the_year,
sum(
IF(value1 > 0, 1, 0) + IF(value2 > 0, 1, 0) + IF(value3 > 0, 1, 0) + IF(value4 > 0, 1, 0) + IF(value5 > 0, 1, 0)
) solves,
Expand Down Expand Up @@ -209,7 +209,7 @@ queries:
GROUP BY
personId,
personName,
year
year(competition.start_date)
ORDER BY
solves DESC,
attempts
Expand Down
40 changes: 20 additions & 20 deletions server/src/main/resources/statistics-request-list/sum-of-ranks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ queries:
- R3
sqlQuery: |-
select
wca_statistics_person_link_format(id, name),
wca_statistics_person_link_format(wca_id, name),
countryId Country,
r3 + r4 + r5 Sum,
r3 '3x3',
Expand All @@ -21,7 +21,7 @@ queries:
from
(
select
id,
wca_id,
p.name,
p.countryId,
(
Expand All @@ -30,7 +30,7 @@ queries:
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '333'
) r3,
(
Expand All @@ -39,7 +39,7 @@ queries:
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '444'
) r4,
(
Expand All @@ -48,7 +48,7 @@ queries:
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '555'
) r5
from
Expand All @@ -73,7 +73,7 @@ queries:
from
(
select
id,
wca_id,
p.name,
p.countryId,
(
Expand All @@ -82,31 +82,31 @@ queries:
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '333') r3,
(
select
worldRank
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '444') r4,
(
select
worldRank
from
RanksSingle
where
personId = p.id
personId = p.wca_id
and eventId = '555') r5
from
Persons p) r
where
r3 is not null
and r4 is not null
and r5 is not null
and id = ':WCA_ID'
and wca_id = ':WCA_ID'
order by
Sum asc
limit 10
Expand All @@ -123,7 +123,7 @@ queries:
- R3
sqlQuery: |-
select
wca_statistics_person_link_format(id, name),
wca_statistics_person_link_format(wca_id, name),
countryId Country,
r3 + r4 + r5 Sum,
r3 '3x3',
Expand All @@ -132,7 +132,7 @@ queries:
from
(
select
id,
wca_id,
p.name,
p.countryId,
(
Expand All @@ -141,7 +141,7 @@ queries:
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '333'
) r3,
(
Expand All @@ -150,7 +150,7 @@ queries:
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '444'
) r4,
(
Expand All @@ -159,7 +159,7 @@ queries:
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '555'
) r5
from
Expand All @@ -184,7 +184,7 @@ queries:
from
(
select
id,
wca_id,
p.name,
p.countryId,
(
Expand All @@ -193,31 +193,31 @@ queries:
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '333') r3,
(
select
worldRank
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '444') r4,
(
select
worldRank
from
RanksAverage
where
personId = p.id
personId = p.wca_id
and eventId = '555') r5
from
Persons p) r
where
r3 is not null
and r4 is not null
and r5 is not null
and id = ':WCA_ID'
and wca_id = ':WCA_ID'
order by
Sum asc
limit 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static io.restassured.RestAssured.given;

@DisplayName("Best ever rank")
@DisplayName("Statistics")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@Sql({"/test-scripts/cleanTestData.sql", "/test-scripts/StatisticsControllerIT.sql"})
public class StatisticsControllerIT extends AbstractTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
{
"regionRank": 15,
"wcaId": "2017BORG02",
"name": "Gabriel Bergue Campos Borges",
"name": "Gabriel Bergue",
"countryIso2": "BR",
"overall": 571,
"events": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ VALUES

-- Competitions
INSERT INTO wca_development.Competitions
(id, name, cityName, countryId, information, `year`, `month`, `day`, endMonth, endDay, venue, venueAddress, venueDetails, external_website, cellName, showAtAll, latitude, longitude, contact, remarks, registration_open, registration_close, use_wca_registration, guests_enabled, results_posted_at, results_nag_sent_at, generate_website, announced_at, base_entry_fee_lowest_denomination, currency_code, endYear, connected_stripe_account_id, start_date, end_date, enable_donations, competitor_limit_enabled, competitor_limit, competitor_limit_reason, extra_registration_requirements, on_the_spot_registration, on_the_spot_entry_fee_lowest_denomination, refund_policy_percent, refund_policy_limit_date, guests_entry_fee_lowest_denomination, created_at, updated_at, results_submitted_at, early_puzzle_submission, early_puzzle_submission_reason, qualification_results, qualification_results_reason, name_reason, external_registration_page, confirmed_at, event_restrictions, event_restrictions_reason, registration_reminder_sent_at, announced_by, results_posted_by, main_event_id, cancelled_at, cancelled_by, waiting_list_deadline_date, event_change_deadline_date, free_guest_entry_status, allow_registration_edits)
(id, name, cityName, countryId, information, venue, venueAddress, venueDetails, external_website, cellName, showAtAll, latitude, longitude, contact, remarks, registration_open, registration_close, use_wca_registration, guests_enabled, results_posted_at, results_nag_sent_at, generate_website, announced_at, base_entry_fee_lowest_denomination, currency_code, connected_stripe_account_id, start_date, end_date, enable_donations, competitor_limit_enabled, competitor_limit, competitor_limit_reason, extra_registration_requirements, on_the_spot_registration, on_the_spot_entry_fee_lowest_denomination, refund_policy_percent, refund_policy_limit_date, guests_entry_fee_lowest_denomination, created_at, updated_at, results_submitted_at, early_puzzle_submission, early_puzzle_submission_reason, qualification_results, qualification_results_reason, name_reason, external_registration_page, confirmed_at, event_restrictions, event_restrictions_reason, registration_reminder_sent_at, announced_by, results_posted_by, main_event_id, cancelled_at, cancelled_by, waiting_list_deadline_date, event_change_deadline_date, guest_entry_status, allow_registration_edits, allow_registration_self_delete_after_acceptance, competition_series_id, use_wca_live_for_scoretaking, allow_registration_without_qualification, guests_per_registration_limit, events_per_registration_limit, force_comment_in_registration)
VALUES
('WC1982', 'World Rubik''s Cube Championship 1982', 'Budapest', 'Hungary', '', 1982, 6, 5, 6, 5, '', '', '', '', 'World Championship 1982', 1, 47498403, 19040759, '', 'remarks to the board here', NULL, NULL, 0, 1, '1982-06-05 00:00:00', '2016-09-04 14:01:15', NULL, '1982-05-08 00:00:00', NULL, 'USD', 1982, NULL, '1982-06-05', '1982-06-05', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '1982-06-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, '2018-09-15 17:46:45', NULL, NULL, NULL, 1681, 1, '333', NULL, NULL, NULL, NULL, 0, 0),
('WC2003', 'World Rubik''s Games Championship 2003', 'Toronto, Ontario', 'Canada', '', 2003, 8, 23, 8, 24, '[Ontario Science Center](http://www.osc.ca)', '', '', 'http://www.speedcubing.com/events/wc2003', 'World Championship 2003', 1, 43716470, -79338711, '', 'remarks to the board here', NULL, NULL, 0, 1, '2003-08-24 00:00:00', '2016-09-04 14:01:16', NULL, '2003-07-26 00:00:00', NULL, 'USD', 2003, NULL, '2003-08-23', '2003-08-24', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2003-08-24 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, '2018-09-15 17:46:45', NULL, NULL, NULL, 125297, 1, '333', NULL, NULL, NULL, NULL, 0, 0),
('DutchOpen2003', 'Dutch Open 2003', 'Veldhoven', 'Netherlands', '', 2003, 10, 11, 10, 11, '[ASML](http://www.asml.com)', 'De Run 6501, 5504 DR Veldhoven', 'Building 7', '', 'Dutch Open 2003', 1, 51405966, 5414813, NULL, 'remarks to the board here', NULL, NULL, 0, 1, '2003-10-11 00:00:00', '2016-09-04 14:00:23', NULL, '2003-09-13 00:00:00', NULL, 'USD', 2003, NULL, '2003-10-11', '2003-10-11', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2003-10-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, '2018-09-15 17:46:45', NULL, NULL, NULL, 125297, 1, '333', NULL, NULL, NULL, NULL, 0, 0);
('DutchOpen2003', 'Dutch Open 2003', 'Veldhoven', 'Netherlands', '', '[ASML](http://www.asml.com)', 'De Run 6501, 5504 DR Veldhoven', 'Building 7', '', 'Dutch Open 2003', 1, 51405966, 5414813, NULL, 'remarks to the board here', NULL, NULL, 0, 1, '2003-10-11 00:00:00', '2016-09-04 14:00:23', NULL, '2003-09-13 00:00:00', NULL, 'USD', NULL, '2003-10-11', '2003-10-11', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2003-10-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, '2018-09-15 17:46:45', NULL, NULL, NULL, 125297, 1, '333', NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0, 0, NULL, NULL, NULL),
('WC1982', 'World Rubik''s Cube Championship 1982', 'Budapest', 'Hungary', '', '', '', '', '', 'World Championship 1982', 1, 47498403, 19040759, '', 'remarks to the board here', NULL, NULL, 0, 1, '1982-06-05 00:00:00', '2016-09-04 14:01:15', NULL, '1982-05-08 00:00:00', NULL, 'USD', NULL, '1982-06-05', '1982-06-05', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '1982-06-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, '2018-09-15 17:46:45', NULL, NULL, NULL, 1681, 1, '333', NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0, 0, NULL, NULL, NULL),
('WC2003', 'World Rubik''s Games Championship 2003', 'Toronto, Ontario', 'Canada', '', '[Ontario Science Center](http://www.osc.ca)', '770 Don Mills Rd, North York, ON M3C IT3, Canada', '', 'https://web.archive.org/web/20220820061419/http://www.speedcubing.com/events/wc2003/', 'World Championship 2003', 1, 43714618, -79339509, '', 'remarks to the board here', NULL, NULL, 0, 1, '2003-08-24 00:00:00', '2016-09-04 14:01:16', 0, '2003-07-26 00:00:00', NULL, 'USD', NULL, '2003-08-23', '2003-08-24', 0, NULL, NULL, '', '', NULL, NULL, NULL, NULL, NULL, NULL, '2023-08-03 05:20:36', '2003-08-24 00:00:00', 0, '', 0, '', '', '', '2018-09-15 17:46:45', 0, '', NULL, 125297, 1, '333', NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0, 0, NULL, NULL, 0);

-- Continents
INSERT INTO wca_development.Continents
Expand Down
Loading

0 comments on commit 174663e

Please sign in to comment.