diff --git a/crates/app/src/public/html/profile/base.lisp b/crates/app/src/public/html/profile/base.lisp index 15ee7bf..f02c553 100644 --- a/crates/app/src/public/html/profile/base.lisp +++ b/crates/app/src/public/html/profile/base.lisp @@ -167,7 +167,7 @@ ("class" "notification chip") (text "GPA 🐇")) (span - (text "{{ gpa }}"))) + (text "{{ gpa|round(method=\"floor\", precision=2) }}"))) (text "{% if not profile.settings.private_last_seen or is_self or is_helper %}") (div ("class" "w-full flex justify-between items-center") diff --git a/crates/app/src/routes/api/v1/auth/profile.rs b/crates/app/src/routes/api/v1/auth/profile.rs index df0eea4..67ee0dd 100644 --- a/crates/app/src/routes/api/v1/auth/profile.rs +++ b/crates/app/src/routes/api/v1/auth/profile.rs @@ -665,9 +665,9 @@ pub async fn get_user_gpa_request( let gpa = data.calculate_user_gpa(id).await; return Json(ApiReturn { ok: true, - message: if gpa >= 3 { + message: if gpa >= 3.0 { "cool".to_string() - } else if gpa >= 4 { + } else if gpa >= 4.0 { "extraordinary".to_string() } else { "ok".to_string() diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 997f9ff..5bda172 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -516,7 +516,7 @@ impl DataManager { /// of at least 0.6. /// /// GPA is calculated based on the user's last 250 posts. - pub async fn calculate_user_gpa(&self, id: usize) -> usize { + pub async fn calculate_user_gpa(&self, id: usize) -> f32 { // just for note, this is SUPER bad for performance... which is why we // only calculate this when it expires in the cache (every week) if let Some(cached) = self.0.1.get(format!("atto.user.gpa:{}", id)).await { @@ -528,18 +528,18 @@ impl DataManager { // ... let conn = match self.0.connect().await { Ok(c) => c, - Err(_) => return 0, + Err(_) => return 0.0, }; let res = query_rows!( &conn, - &format!("SELECT * FROM posts WHERE owner = $1 ORDER BY created DESC LIMIT 250",), + &format!("SELECT * FROM posts WHERE owner = $1 ORDER BY created DESC LIMIT 50"), &[&(id as i64)], |x| { Self::get_post_from_row(x) } ); if res.is_err() { - return 0; + return 0.0; } // ... @@ -550,8 +550,12 @@ impl DataManager { let posts = res.unwrap(); for post in posts { - if (post.likes == 0 && post.dislikes == 0) | ((post.likes + post.dislikes) < 5) { - // post has no likes or dislikes (or has too few reactions)... doesn't count + if post.likes == 0 && post.dislikes == 0 { + // post has no likes or dislikes... doesn't count + if good_posts > 8 { + good_posts -= 1; // we're going to say this is a bad post because it isn't liked enough + } + continue; } @@ -574,14 +578,15 @@ impl DataManager { // } } - let gpa = ((good_posts as f32 / real_posts_count as f32) * 4.0).round() as usize; + let gpa = (good_posts as f32 / real_posts_count as f32) * 4.0; + let gpa_rounded = format!("{gpa:.2}").parse::().unwrap(); self.0 .1 - .set(format!("atto.user.gpa:{}", id), gpa.to_string()) + .set(format!("atto.user.gpa:{}", id), gpa_rounded.to_string()) .await; - gpa + gpa_rounded } /// Get all replies from the given user (from most recent).