add: make gpa much harder
This commit is contained in:
parent
6245f9fd2e
commit
14c52b13fb
3 changed files with 17 additions and 12 deletions
|
@ -167,7 +167,7 @@
|
||||||
("class" "notification chip")
|
("class" "notification chip")
|
||||||
(text "GPA 🐇"))
|
(text "GPA 🐇"))
|
||||||
(span
|
(span
|
||||||
(text "{{ gpa }}")))
|
(text "{{ gpa|round(method=\"floor\", precision=2) }}")))
|
||||||
(text "{% if not profile.settings.private_last_seen or is_self or is_helper %}")
|
(text "{% if not profile.settings.private_last_seen or is_self or is_helper %}")
|
||||||
(div
|
(div
|
||||||
("class" "w-full flex justify-between items-center")
|
("class" "w-full flex justify-between items-center")
|
||||||
|
|
|
@ -665,9 +665,9 @@ pub async fn get_user_gpa_request(
|
||||||
let gpa = data.calculate_user_gpa(id).await;
|
let gpa = data.calculate_user_gpa(id).await;
|
||||||
return Json(ApiReturn {
|
return Json(ApiReturn {
|
||||||
ok: true,
|
ok: true,
|
||||||
message: if gpa >= 3 {
|
message: if gpa >= 3.0 {
|
||||||
"cool".to_string()
|
"cool".to_string()
|
||||||
} else if gpa >= 4 {
|
} else if gpa >= 4.0 {
|
||||||
"extraordinary".to_string()
|
"extraordinary".to_string()
|
||||||
} else {
|
} else {
|
||||||
"ok".to_string()
|
"ok".to_string()
|
||||||
|
|
|
@ -516,7 +516,7 @@ impl DataManager {
|
||||||
/// of at least 0.6.
|
/// of at least 0.6.
|
||||||
///
|
///
|
||||||
/// GPA is calculated based on the user's last 250 posts.
|
/// 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
|
// just for note, this is SUPER bad for performance... which is why we
|
||||||
// only calculate this when it expires in the cache (every week)
|
// 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 {
|
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 {
|
let conn = match self.0.connect().await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(_) => return 0,
|
Err(_) => return 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&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)],
|
&[&(id as i64)],
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
@ -550,8 +550,12 @@ impl DataManager {
|
||||||
let posts = res.unwrap();
|
let posts = res.unwrap();
|
||||||
|
|
||||||
for post in posts {
|
for post in posts {
|
||||||
if (post.likes == 0 && post.dislikes == 0) | ((post.likes + post.dislikes) < 5) {
|
if post.likes == 0 && post.dislikes == 0 {
|
||||||
// post has no likes or dislikes (or has too few reactions)... doesn't count
|
// 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;
|
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::<f32>().unwrap();
|
||||||
|
|
||||||
self.0
|
self.0
|
||||||
.1
|
.1
|
||||||
.set(format!("atto.user.gpa:{}", id), gpa.to_string())
|
.set(format!("atto.user.gpa:{}", id), gpa_rounded.to_string())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
gpa
|
gpa_rounded
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all replies from the given user (from most recent).
|
/// Get all replies from the given user (from most recent).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue