Skip to content

Commit

Permalink
sort grades by descending date (decided by last "freigabe" in subgrades)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnschmidt committed Aug 15, 2024
1 parent 2ef2b9d commit 5635375
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/campus_backend/req_client_funcs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use chrono::NaiveDate;
use cookie_store::CookieStore;
use lazy_static::lazy_static;
use regex::Regex;
Expand Down Expand Up @@ -115,7 +116,6 @@ pub fn extract_grades(html_text: String) -> Result<Vec<CampusDualGrade>> {
};
subgrades.push(bloat);
}

grades.push(CampusDualGrade {
name: name.to_string(),
grade: grade.to_string(),
Expand All @@ -126,9 +126,23 @@ pub fn extract_grades(html_text: String) -> Result<Vec<CampusDualGrade>> {
});
}

grades.sort_by(|grade_a, grade_b| {
get_newest_subgrade_date(grade_b).cmp(&get_newest_subgrade_date(grade_a))
});

Ok(grades)
}

fn get_newest_subgrade_date(grade: &CampusDualGrade) -> NaiveDate {
let newest_subgrade = grade
.subgrades
.iter()
.max_by(|a, b| a.bekanntgabe.cmp(&b.bekanntgabe))
.unwrap();

NaiveDate::parse_from_str(&newest_subgrade.bekanntgabe, "%d.%m.%Y").unwrap()
}

pub async fn extract_exam_signup_options(html_text: String) -> Result<Vec<CampusDualSignupOption>> {
let mut signup_options = Vec::new();

Expand Down

0 comments on commit 5635375

Please sign in to comment.