Skip to content

Commit a8178d2

Browse files
committed
Add achievements "Consolation Price" and "10 times 10"
1 parent 52f9bb1 commit a8178d2

6 files changed

+110
-21
lines changed

.sqlx/query-52d88351ccef32308375e7b4b0ff2d223db062650a1b4b01ea5a0862205e7003.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-e6da22369b655e61d95af15776520459543c0c00d02cd3a6d34907a8412e6f2f.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-af6f4e4004130325ab33bd51ca06f9ccc0bd6ec0f5804d1f4ac064ac5807248c.json renamed to .sqlx/query-e9d0eb989251e3e6446d5c13a70b44e29cbc38c89a514501945fc40211d0295a.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/achievements.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ pub enum ChallengeCategory {
2626
#[derive(Copy, Clone, PartialEq, Eq, Hash, VariantArray, IntoStaticStr, EnumString, Debug)]
2727
pub enum AchievementType {
2828
// Solve Related
29-
// OnePoint,
29+
OnePoint,
3030
UncontestedFirstPlace,
3131
FirstPlace,
3232
OnlySolution,
3333
UncontestedFirstPlacePostMortem,
34+
TenTopTen,
3435
// FiveLanguages,
3536
// ImproveFirstPlace,
3637
FirstDaySolve,
@@ -84,6 +85,8 @@ pub enum AchievementType {
8485
impl AchievementType {
8586
pub fn get_achievement_name(self) -> &'static str {
8687
match self {
88+
AchievementType::OnePoint => "Consolation Prize",
89+
AchievementType::TenTopTen => "Ten times Ten",
8790
AchievementType::CodeGolf1Point => "Code Golf Baby",
8891
AchievementType::CodeGolf250Point => "Code Golf Newbie",
8992
AchievementType::CodeGolf500Point => "Code Golf Starter",
@@ -138,7 +141,9 @@ impl AchievementType {
138141
| AchievementType::UncontestedFirstPlace
139142
| AchievementType::SolveBeta
140143
| AchievementType::SolvePostMortem
141-
| AchievementType::UncontestedFirstPlacePostMortem => AchievementCategory::SolveRelated,
144+
| AchievementType::UncontestedFirstPlacePostMortem
145+
| AchievementType::OnePoint
146+
| AchievementType::TenTopTen => AchievementCategory::SolveRelated,
142147
AchievementType::ImproveExample
143148
| AchievementType::ImproveJudge
144149
| AchievementType::ImproveDescription
@@ -150,7 +155,12 @@ impl AchievementType {
150155

151156
pub fn get_associated_number(self) -> Option<i32> {
152157
match self {
153-
Self::CodeGolf1Point | Self::RestrictedSource1Point => Some(1),
158+
Self::CodeGolf1Point
159+
| Self::RestrictedSource1Point
160+
| Self::Vote
161+
| Self::OnePoint
162+
| Self::OnlySolution => Some(1),
163+
Self::TenTopTen => Some(10),
154164
Self::CodeGolf250Point | Self::RestrictedSource250Point => Some(250),
155165
Self::CodeGolf500Point | Self::RestrictedSource500Point => Some(500),
156166
Self::CodeGolf1000Point
@@ -162,6 +172,7 @@ impl AchievementType {
162172
| Self::JavaScript1000Point
163173
| Self::Rust1000Point => Some(1000),
164174
Self::CodeGolf2000Point | Self::RestrictedSource2000Point => Some(2000),
175+
Self::FirstDaySolve | Self::LastDaySolve => Some(24),
165176

166177
AchievementType::JavaScript3500Point => Some(3500),
167178
_ => None,
@@ -170,7 +181,9 @@ impl AchievementType {
170181

171182
pub fn get_achievement_description(self) -> &'static str {
172183
match self {
173-
AchievementType::OnlySolution => "Be the first to solve a challenge in a language",
184+
AchievementType::OnePoint => "Earn just one score for a solution",
185+
AchievementType::TenTopTen => "Earn top 10% in 10 different challenges",
186+
AchievementType::OnlySolution => "Be the first to solve a heist in a language",
174187
AchievementType::UncontestedFirstPlace => "Beat the best score",
175188
AchievementType::CodeGolf1Point => "Earn your first point in Code Golf",
176189
AchievementType::CodeGolf250Point => "Earn 250 points in Code Golf",
@@ -190,27 +203,23 @@ impl AchievementType {
190203
AchievementType::C1000Point => "Earn 1,000 points in C",
191204
AchievementType::Apl1000Point => "Earn 1,000 points in APL",
192205
AchievementType::StarTheRepo => "Star the Byte Heist Github Repo",
193-
AchievementType::FirstDaySolve => {
194-
"Solve a challenge within 24 hours of when it goes live"
195-
}
196-
AchievementType::LastDaySolve => "Solve a challenge less than 24 hours before it ends",
197-
AchievementType::SolveBeta => "Solve a beta challenge",
198-
AchievementType::SolvePostMortem => "Solve a challenge after it ends",
206+
AchievementType::FirstDaySolve => "Solve a heist within 24 hours of when it goes live",
207+
AchievementType::LastDaySolve => "Solve a heist less than 24 hours before it ends",
208+
AchievementType::SolveBeta => "Solve a beta heist",
209+
AchievementType::SolvePostMortem => "Solve a heist after it ends",
199210
AchievementType::UncontestedFirstPlacePostMortem => {
200-
"Beat the best score after the challenge has ended"
211+
"Beat the best score after the heist has ended"
201212
}
202213
AchievementType::Contribute => "Contribute to Byte Heist",
203-
AchievementType::FirstPlace => {
204-
"Get first place on a challenge, even if just for a moment"
205-
}
214+
AchievementType::FirstPlace => "Get first place on a heist, even if just for a moment",
206215
AchievementType::ImproveDescription => {
207-
"Submit a change suggestion that updates a challenge's description and is accepted"
216+
"Submit a change suggestion that updates a heist's description and is accepted"
208217
}
209218
AchievementType::ImproveExample => {
210-
"Submit a change suggestion that updates a challenge's example code and is accepted"
219+
"Submit a change suggestion that updates a heist's example code and is accepted"
211220
}
212221
AchievementType::ImproveJudge => {
213-
"Submit a change suggestion that updates a challenge's judge and is accepted"
222+
"Submit a change suggestion that updates a heist's judge and is accepted"
214223
}
215224
AchievementType::ChangeSuggestionInvalidates1 => {
216225
"Submit a change suggestion that invalidates a solution"
@@ -247,7 +256,6 @@ impl AchievementType {
247256
| AchievementType::RestrictedSource500Point => {
248257
Some(ChallengeCategory::RestrictedSource)
249258
}
250-
251259
_ => None,
252260
}
253261
}

main-server/src/achievements/points_based.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn point_based_score(
3232
FROM user_scoring_info
3333
WHERE total_score > $2 AND category = $3::challenge_category
3434
ON CONFLICT(user_id, achievement) DO UPDATE SET
35-
achieved=excluded.achieved,
35+
achieved=achievements.achieved OR excluded.achieved,
3636
progress=excluded.progress,
3737
awarded_at=COALESCE(achievements.awarded_at, excluded.awarded_at)
3838
"#,

main-server/src/achievements/solve_related.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,59 @@ use sqlx::{PgPool, query};
44
pub(super) async fn award_solve_related(pool: &PgPool) -> Result<(), sqlx::Error> {
55
let first_day_solve_name: &str = AchievementType::FirstDaySolve.into();
66
let last_day_solve_name: &str = AchievementType::LastDaySolve.into();
7+
let ten_top_ten_name: &str = AchievementType::TenTopTen.into();
8+
let one_point_name: &str = AchievementType::OnePoint.into();
9+
10+
query!(
11+
r#"
12+
INSERT INTO achievements(
13+
user_id,
14+
achievement,
15+
awarded_at,
16+
achieved,
17+
progress,
18+
total
19+
) SELECT
20+
author as user_id,
21+
$1,
22+
case when SUM(top_ten_percents) >= 10 then now() else null end,
23+
SUM(top_ten_percents) >=10,
24+
LEAST(10, SUM(top_ten_percents)),
25+
10
26+
FROM user_scoring_info
27+
GROUP BY author
28+
HAVING SUM(top_ten_percents) > 0
29+
ON CONFLICT(user_id, achievement) DO UPDATE SET
30+
achieved = achievements.achieved OR excluded.achieved,
31+
progress=case when achievements.achieved then 10 else excluded.progress end,
32+
awarded_at = coalesce(achievements.awarded_at, excluded.awarded_at)
33+
34+
"#,
35+
ten_top_ten_name
36+
)
37+
.execute(pool)
38+
.await?;
39+
40+
query!(
41+
r#"
42+
INSERT INTO achievements(
43+
user_id,
44+
achievement,
45+
awarded_at,
46+
achieved
47+
) SELECT DISTINCT ON (author)
48+
author as user_id,
49+
$1,
50+
now(),
51+
true
52+
FROM scores
53+
WHERE score = 1
54+
ON CONFLICT DO NOTHING
55+
"#,
56+
one_point_name
57+
)
58+
.execute(pool)
59+
.await?;
760

861
query!(
962
"INSERT INTO achievements(user_id, achievement, related_language, related_challenge, awarded_at, achieved)

0 commit comments

Comments
 (0)