Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions bszet-davinci/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Change {
notice,
..
} => {
match find_lesson(lessons, lesson, Some(subject))? {
match find_lesson(lessons, lesson, Some(subject), false)? {
None => false,
Some(lesson) => {
// TODO: place, teachers
Expand All @@ -158,7 +158,7 @@ impl Change {
notice,
..
} => {
match find_lesson(lessons, lesson, Some(subject))? {
match find_lesson(lessons, lesson, Some(subject), false)? {
None => false,
Some(lesson) => {
// TODO: teachers, place.from
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Change {
notice,
..
} => {
match find_lesson(lessons, lesson, subject.from.as_ref())? {
match find_lesson(lessons, lesson, subject.from.as_ref(), true)? {
None => false,
Some(lesson) => {
// TODO: teachers, place.from
Expand Down Expand Up @@ -222,6 +222,7 @@ fn find_lesson<'a>(
lessons: &'a mut [Lesson],
lesson: &u8,
subject: Option<&Subject>,
allow_cancel: bool,
) -> anyhow::Result<Option<&'a mut Lesson>> {
let lessons = lessons
.iter_mut()
Expand All @@ -236,11 +237,19 @@ fn find_lesson<'a>(
Err(anyhow!("Found multiple subjects without original value to clearly identify lesson. less: {}, subjs: {:?}",lesson , lessons))
}
}
Some(subject) => Ok(
lessons
.into_iter()
.find(|lesson| &lesson.subject == subject),
),
Some(subject) => Ok(lessons.into_iter().find(|lesson| {
if &lesson.subject == subject {
true
} else if allow_cancel {
if let Subject::Cancel(inner) = &lesson.subject {
inner.as_ref() == subject
} else {
false
}
} else {
false
}
})),
}
}

Expand Down
75 changes: 51 additions & 24 deletions bszet-davinci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,25 @@ impl Davinci {
let mut relevant_rows = Vec::new();

if let Some(data) = self.data.read().await.as_ref() {
// first ally all cancel
// sometimes there is a cancel and than a replacement for the canceled lesson
for row in &data.rows {
if row.date != date
|| !(row.class.contains(&"IGD21".to_string())
|| row.class.contains(&"IGD 21".to_string()))
{
continue;
}

match row.change.apply(&mut day) {
Ok(applied) => {
if applied {
continue;
}
if let Change::Cancel { .. } = row.change {
if apply_change(&date, &mut day, &mut relevant_rows, row) {
continue;
}
Err(err) => error!("Could not apply row: {}", err),
}
}

{
let uuid = Uuid::new_v4();
let event = Event {
event_id: uuid,
message: Some(format!("Unable to apply change: {row:?}")),
level: sentry::protocol::Level::Warning,
..Default::default()
};

sentry::capture_event(event);
// alter that apply all other changes
for row in &data.rows {
if let Change::Cancel { .. } = row.change {
continue;
}

relevant_rows.push(row.clone());
if apply_change(&date, &mut day, &mut relevant_rows, row) {
continue;
}
}
}

Expand Down Expand Up @@ -254,3 +243,41 @@ impl PartialEq<Self> for Row {
}

impl Eq for Row {}

fn apply_change(
date: &Date,
mut day: &mut Vec<Lesson>,
relevant_rows: &mut Vec<Row>,
row: &Row,
) -> bool {
if &row.date != date
|| !(row.class.contains(&"IGD21".to_string()) || row.class.contains(&"IGD 21".to_string()))
{
return true;
}

match row.change.apply(&mut day) {
Ok(applied) => {
if applied {
return true;
}
}
Err(err) => error!("Could not apply row: {}", err),
}

{
let uuid = Uuid::new_v4();
let event = Event {
event_id: uuid,
message: Some(format!("Unable to apply change: {row:?}")),
level: sentry::protocol::Level::Warning,
..Default::default()
};

sentry::capture_event(event);
}

relevant_rows.push(row.clone());

false
}