Skip to content

Commit

Permalink
check if impossible based on activity.deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
Tijl Leenders committed Mar 22, 2024
1 parent 546fb70 commit 533f658
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ pub fn run_scheduler(
dbg!(&budget_goal_activities);
dbg!(&calendar);

let activities: Vec<Activity> = [
let mut activities: Vec<Activity> = [
simple_goal_activities,
simple_filler_activities,
budget_goal_activities,
]
.concat();
activity_placer::place(&mut calendar, activities);
activities = activity_placer::place(&mut calendar, activities)
.expect("should get activities back from placer");

calendar.log_impossible_min_day_budgets();

Expand All @@ -133,5 +134,7 @@ pub fn run_scheduler(
activity_placer::place(&mut calendar, top_up_week_budget_activities);
//TODO: Test that day stays below min or max when week max being reachd

calendar.log_impossible_simple_activities(activities);

calendar.print()
}
6 changes: 6 additions & 0 deletions src/models/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct Activity {
pub total_duration: usize,
pub duration_left: usize,
pub status: Status,
pub deadline: NaiveDateTime,
}
impl Activity {
pub fn get_compatible_hours_overlay(
Expand Down Expand Up @@ -220,6 +221,7 @@ impl Activity {
total_duration: activity_total_duration,
duration_left: activity_total_duration,
status: Status::Unprocessed,
deadline: goal.deadline,
};
dbg!(&activity);
activities.push(activity);
Expand Down Expand Up @@ -286,6 +288,7 @@ impl Activity {
total_duration: adjusted_min_block_size,
duration_left: config.min_per_day,
status: Status::Unprocessed,
deadline: goal.deadline,
};
dbg!(&activity);
activities.push(activity);
Expand Down Expand Up @@ -328,6 +331,7 @@ impl Activity {
total_duration: max_hours,
duration_left: max_hours,
status: Status::Unprocessed,
deadline: goal_to_use.deadline,
});

activities
Expand Down Expand Up @@ -367,6 +371,7 @@ impl Activity {
total_duration: max_hours,
duration_left: max_hours,
status: Status::Unprocessed,
deadline: goal_to_use.deadline,
});

activities
Expand Down Expand Up @@ -518,6 +523,7 @@ impl Activity {
total_duration: activity_total_duration,
duration_left: activity_total_duration,
status: Status::Unprocessed,
deadline: goal.deadline,
};
dbg!(&activity);
activities.push(activity);
Expand Down
16 changes: 16 additions & 0 deletions src/models/calendar.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::activity::Activity;
use super::budget::{get_time_budgets_from, Budget, TimeBudgetType};
use super::goal::Goal;
use super::task::{DayTasks, FinalTasks, Task};
Expand Down Expand Up @@ -294,6 +295,21 @@ impl Calendar {
self.impossible_activities.extend(impossible_activities);
}

pub fn log_impossible_simple_activities(&mut self, activities: Vec<Activity>) {
for activity in activities {
if activity.status == super::activity::Status::Impossible
&& activity.deadline.year() != 1970
{
self.impossible_activities.push(ImpossibleActivity {
id: activity.goal_id.clone(),
hours_missing: activity.duration_left,
period_start_date_time: self.start_date_time,
period_end_date_time: self.end_date_time,
})
}
}
}

fn impossible_activities(&mut self) -> Vec<ImpossibleActivity> {
let mut impossible_activities = vec![];
for budget in &self.budgets {
Expand Down
4 changes: 2 additions & 2 deletions src/services/activity_placer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::models::{
calendar::{Calendar, Hour, ImpossibleActivity},
};

pub fn place(calendar: &mut Calendar, mut activities: Vec<Activity>) -> Option<()> {
pub fn place(calendar: &mut Calendar, mut activities: Vec<Activity>) -> Option<Vec<Activity>> {
loop {
for activity in activities.iter_mut() {
activity.update_overlay_with(&calendar.budgets);
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn place(calendar: &mut Calendar, mut activities: Vec<Activity>) -> Option<(
dbg!(&calendar);
}
dbg!(&calendar);
Some(())
Some(activities)
}

fn find_act_index_to_schedule(activities: &[Activity]) -> Option<usize> {
Expand Down
9 changes: 8 additions & 1 deletion tests/jsons/stable/simple-without-deadline/observed.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
]
}
],
"impossible": []
"impossible": [
{
"id": "3",
"hoursMissing": 1,
"periodStartDateTime": "2022-01-01T00:00:00",
"periodEndDateTime": "2022-01-02T00:00:00"
}
]
}

0 comments on commit 533f658

Please sign in to comment.