Skip to content

Commit

Permalink
done: choose budget limit according to activity_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tijl Leenders committed Jan 14, 2024
1 parent 0556244 commit 5d21b14
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 163 deletions.
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub fn run_scheduler(
activity_placer::place(&mut calendar, simple_goal_activities);

//generate and place budget goal activities
//TODO: now only limiting when reaching max/week - it should limit when it reaches min/week
let budget_goal_activities: Vec<Activity> =
activity_generator::generate_budget_goal_activities(&calendar, &goals);
dbg!(&calendar);
Expand Down
9 changes: 6 additions & 3 deletions src/models/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ impl Activity {
return ();
}
for budget in budgets {
//check if activity goal id is in the budget - else don't bother
if budget.participating_goals.contains(&self.goal_id) {
// great, process it
} else {
// budget not relevant to this activity
continue;
}
//check if activity goal id is in the budget - else don't bother
//check my overlay for valid placing options, with a loop like get_best_scheduling_index
for hour_index in 0..self.calendar_overlay.len() {
match &self.calendar_overlay[hour_index] {
Expand All @@ -308,8 +308,11 @@ impl Activity {
//if last position check if best so far - or so little we can break
if offset == self.min_block_size - 1 {
//check if not allowed by budgets
let is_allowed =
budget.is_within_budget(hour_index, offset);
let is_allowed = budget.is_within_budget(
hour_index,
offset,
self.activity_type.clone(),
);
if is_allowed {
// Cool!
} else {
Expand Down
20 changes: 17 additions & 3 deletions src/models/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{Debug, Formatter};

use serde::Deserialize;

use super::{calendar::Calendar, goal::Goal};
use super::{activity::ActivityType, calendar::Calendar, goal::Goal};

#[derive(Debug, Clone, Deserialize)]
pub struct Budget {
Expand All @@ -25,9 +25,23 @@ impl Budget {
}
}

pub(crate) fn is_within_budget(&self, hour_index: usize, offset: usize) -> bool {
pub(crate) fn is_within_budget(
&self,
hour_index: usize,
offset: usize,
activity_type: ActivityType,
) -> bool {
let mut budget_cut_off_number = 0;
let mut is_allowed = true;
for time_budget in &self.time_budgets {
match activity_type {
ActivityType::SimpleGoal => {
budget_cut_off_number = time_budget.min_scheduled;
}
ActivityType::Budget => {
budget_cut_off_number = time_budget.min_scheduled;
}
}
//figure out how many of the hours in hour_index till hour_index + offset are in the time_budget window
let mut hours_in_time_budget_window = 0;
for local_offset in 0..offset {
Expand All @@ -39,7 +53,7 @@ impl Budget {
}
if (hour_index + offset) >= time_budget.calendar_start_index
&& (hour_index + offset) < time_budget.calendar_end_index
&& time_budget.scheduled + hours_in_time_budget_window >= time_budget.max_scheduled
&& time_budget.scheduled + hours_in_time_budget_window >= budget_cut_off_number
{
is_allowed = false;
}
Expand Down
Loading

0 comments on commit 5d21b14

Please sign in to comment.