Skip to content

Commit f0cbeae

Browse files
authored
Merge pull request #1133 from kenkoooo/fix/rated_point_sum_exclude_heuristic
fix: exclude heuristic rated points
2 parents 5048ab1 + 00ec4db commit f0cbeae

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

atcoder-problems-backend/sql-client/src/models.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::{FIRST_AGC_EPOCH_SECOND, UNRATED_STATE};
21
use serde::{Deserialize, Serialize};
32
use sqlx::postgres::PgRow;
43
use sqlx::FromRow;
@@ -13,12 +12,6 @@ pub struct Contest {
1312
pub rate_change: String,
1413
}
1514

16-
impl Contest {
17-
pub fn is_rated(&self) -> bool {
18-
self.start_epoch_second >= FIRST_AGC_EPOCH_SECOND && self.rate_change != UNRATED_STATE
19-
}
20-
}
21-
2215
#[derive(Debug, Eq, PartialEq, Serialize)]
2316
pub struct Problem {
2417
pub id: String,

atcoder-problems-backend/sql-client/src/rated_point_sum.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ impl RatedPointSumClient for PgPool {
2121
async fn update_rated_point_sum(&self, ac_submissions: &[Submission]) -> Result<()> {
2222
let rated_contest_ids_fut = sqlx::query(
2323
r"
24-
SELECT id FROM contests
25-
WHERE start_epoch_second >= $1
26-
AND rate_change != $2
24+
SELECT contests.id FROM
25+
(
26+
SELECT COUNT(*) AS problem_count, contest_id
27+
FROM contest_problem
28+
GROUP BY contest_id
29+
) AS contest_problem_count
30+
JOIN contests ON contests.id=contest_problem_count.contest_id
31+
WHERE
32+
contests.start_epoch_second >= $1
33+
AND contests.rate_change != $2
34+
AND contest_problem_count.problem_count >= 2
2735
",
2836
)
2937
.bind(FIRST_AGC_EPOCH_SECOND)

atcoder-problems-backend/sql-client/tests/test_rated_point_sum.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const USER_ID2: &str = "user2";
1313
const USER_ID3: &str = "user3";
1414
const USER_ID4: &str = "user4";
1515
const RATED_CONTEST: &str = "rated_contest";
16+
const HEURISTIC_CONTEST: &str = "heuristic_contest";
1617
const UNRATED_CONTEST1: &str = "unrated_contest1";
1718
const UNRATED_CONTEST2: &str = "unrated_contest2";
1819

@@ -56,6 +57,13 @@ async fn setup_contests(pool: &PgPool) {
5657
title: "Unrated New Contest".to_string(),
5758
rate_change: UNRATED_STATE.to_string(),
5859
},
60+
Contest {
61+
id: HEURISTIC_CONTEST.to_string(),
62+
start_epoch_second: FIRST_AGC_EPOCH_SECOND,
63+
duration_second: 1000,
64+
title: "Heuristic Contest".to_string(),
65+
rate_change: "All".to_string(),
66+
},
5967
];
6068
for contest in contests {
6169
sqlx::query(
@@ -102,6 +110,18 @@ async fn setup_contest_problems(pool: &PgPool) {
102110
problem_id: "problem5".to_string(),
103111
contest_id: SAME_CONTEST_UNRATED.to_string(),
104112
},
113+
ContestProblem {
114+
problem_id: "problem6".to_string(),
115+
contest_id: SAME_CONTEST_RATED.to_string(),
116+
},
117+
ContestProblem {
118+
problem_id: "problem6".to_string(),
119+
contest_id: SAME_CONTEST_UNRATED.to_string(),
120+
},
121+
ContestProblem {
122+
problem_id: "heuristic-problem".to_string(),
123+
contest_id: HEURISTIC_CONTEST.to_string(),
124+
},
105125
];
106126

107127
for problem in problems {
@@ -175,6 +195,14 @@ async fn test_update_rated_point_sum() {
175195
contest_id: SAME_CONTEST_UNRATED.to_string(),
176196
..Default::default()
177197
},
198+
Submission {
199+
id: 6,
200+
user_id: USER_ID.to_string(),
201+
point: 1000000.0,
202+
problem_id: "heuristic-problem".to_string(),
203+
contest_id: HEURISTIC_CONTEST.to_string(),
204+
..Default::default()
205+
},
178206
];
179207

180208
pool.update_rated_point_sum(&submissions).await.unwrap();

0 commit comments

Comments
 (0)