Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test budget-with-subgoal #433

Merged
merged 31 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f108807
add test budget-with-subgoal
Jan 23, 2024
cb9eaa6
undo duplicating function
Feb 3, 2024
d41e998
add passing budget-and-one-goal test
Jan 23, 2024
e950aee
remove irrelevant code
thinkrapido Jan 23, 2024
9fdf886
remove multiple clone from filter_option
thinkrapido Jan 23, 2024
1c617c9
remove unnecessary match nesting
thinkrapido Jan 23, 2024
5495f60
remove code duplication
thinkrapido Jan 23, 2024
b620a4d
remove unwrap
thinkrapido Jan 23, 2024
be48fc3
refactor test setup
thinkrapido Jan 28, 2024
87aee54
refactor pattern matching
thinkrapido Jan 28, 2024
c388d8a
change the ordering of Concepts.md
thinkrapido Jan 29, 2024
a7c0031
change Algorithm-Overview.md
thinkrapido Jan 29, 2024
9e1a76d
remove all references of flamegraph
thinkrapido Jan 29, 2024
ce42ec4
get rid of Steps and Slots
thinkrapido Jan 29, 2024
d2883b4
fine-tune algorithm wording
Jan 29, 2024
d8dba77
fine-tune Concepts
Jan 29, 2024
24c23e6
update broken license reference
Jan 29, 2024
5695a4e
remove confusing deserialize from output structs
Jan 28, 2024
682e2e2
fix unwrap bug
Feb 4, 2024
5c7b135
correct expectation
Feb 4, 2024
2f7e668
update observed
Feb 4, 2024
bff07ee
bundle generate activities so conflicts are clear
Feb 4, 2024
56d2634
Merge branch 'main' into tijl/-/add-budget-with-subgoal-test
tijlleenders Feb 4, 2024
30b0d25
this was already fixed nicer :)
Feb 4, 2024
17fb43b
update observed
Feb 4, 2024
6b9fee8
Merge branch 'tijl/445/remove-confusing-function-name-duplication' in…
Feb 4, 2024
cb710f3
budget children should participate in budget
Feb 4, 2024
6c01152
add filters to calendar.budget so it can be used in overlay generation
Feb 4, 2024
faffdf1
don't skip a goal only because it has children
Feb 4, 2024
c241af4
Merge branch 'main' into tijl/-/add-budget-with-subgoal-test
tijlleenders Feb 17, 2024
360e2d1
cargo fmt
Feb 17, 2024
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
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ pub fn run_scheduler(
let simple_goal_activities =
activity_generator::generate_simple_goal_activities(&calendar, goals);
dbg!(&simple_goal_activities);
activity_placer::place(&mut calendar, simple_goal_activities);

//generate and place budget goal activities
let budget_goal_activities: Vec<Activity> =
activity_generator::generate_budget_goal_activities(&calendar, goals);
dbg!(&budget_goal_activities);
dbg!(&calendar);

activity_placer::place(&mut calendar, simple_goal_activities);
activity_placer::place(&mut calendar, budget_goal_activities);

calendar.log_impossible_min_day_budgets();
Expand Down
6 changes: 4 additions & 2 deletions src/models/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ impl Activity {
// or yield flex 1 or maximum of the set from activity.flex()?
};

let filters_option: Option<Filters> = calendar.get_filters_for(goal.id.clone());

let compatible_hours_overlay = Activity::get_compatible_hours_overlay(
calendar,
goal.filters.clone(),
filters_option,
adjusted_goal_start,
adjusted_goal_deadline,
goal.not_on.clone(),
Expand Down Expand Up @@ -227,7 +229,7 @@ impl Activity {
goal: &Goal,
calendar: &Calendar,
) -> Vec<Activity> {
if goal.children.is_some() || goal.filters.as_ref().is_none() {
if goal.filters.as_ref().is_none() {
tijlleenders marked this conversation as resolved.
Show resolved Hide resolved
return vec![];
}
if let Some(config) = &goal.budget_config {
Expand Down
7 changes: 6 additions & 1 deletion src/models/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ use std::{
use chrono::{Datelike, Duration};
use serde::Deserialize;

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

#[derive(Debug, Clone, Deserialize)]
pub struct Budget {
pub originating_goal_id: String,
pub participating_goals: Vec<String>,
pub time_budgets: Vec<TimeBudget>,
pub time_filters: Filters,
}
impl Budget {
pub fn reduce_for_(&mut self, goal: &str, duration_offset: usize) {
Expand Down
13 changes: 12 additions & 1 deletion src/models/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl Calendar {
originating_goal_id: budget_id.clone(),
participating_goals: descendants_added,
time_budgets: get_time_budgets_from(self, goal),
time_filters: goal.filters.clone().unwrap(),
tijlleenders marked this conversation as resolved.
Show resolved Hide resolved
});
continue;
}
Expand All @@ -258,6 +259,7 @@ impl Calendar {
originating_goal_id: budget_id.clone(),
participating_goals: descendants_added,
time_budgets: get_time_budgets_from(self, goal),
time_filters: goal.filters.clone().unwrap(),
tijlleenders marked this conversation as resolved.
Show resolved Hide resolved
});
break;
}
Expand All @@ -266,8 +268,8 @@ impl Calendar {
if let Some(goal) = goal_map.get(&descendant_of_which_to_add_children) {
if let Some(children) = &goal.children {
descendants.extend(children.clone());
descendants_added.push(descendant_of_which_to_add_children);
}
descendants_added.push(descendant_of_which_to_add_children);
}
}
}
Expand Down Expand Up @@ -317,6 +319,15 @@ impl Calendar {
}
impossible_activities
}

pub(crate) fn get_filters_for(&self, id: String) -> Option<super::goal::Filters> {
for budget in self.budgets.iter() {
if budget.participating_goals.contains(&id) {
return Some(budget.time_filters.clone());
}
}
None
}
}
impl Debug for Calendar {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
Expand Down
184 changes: 184 additions & 0 deletions tests/jsons/stable/budget-with-subgoal/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"scheduled": [
{
"day": "2024-01-08",
"tasks": [
{
"taskid": 0,
"goalid": "free",
"title": "free",
"duration": 6,
"start": "2024-01-08T00:00:00",
"deadline": "2024-01-08T06:00:00"
},
{
"taskid": 1,
"goalid": "103b2eff-6ba5-47b5-ad4f-81d8e8ef5998",
"title": "Plan my work week",
"duration": 1,
"start": "2024-01-08T06:00:00",
"deadline": "2024-01-08T07:00:00"
},
{
"taskid": 2,
"goalid": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"duration": 7,
"start": "2024-01-08T07:00:00",
"deadline": "2024-01-08T14:00:00"
},
{
"taskid": 3,
"goalid": "free",
"title": "free",
"duration": 10,
"start": "2024-01-08T14:00:00",
"deadline": "2024-01-09T00:00:00"
}
]
},
{
"day": "2024-01-09",
"tasks": [
{
"taskid": 4,
"goalid": "free",
"title": "free",
"duration": 6,
"start": "2024-01-09T00:00:00",
"deadline": "2024-01-09T06:00:00"
},
{
"taskid": 5,
"goalid": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"duration": 8,
"start": "2024-01-09T06:00:00",
"deadline": "2024-01-09T14:00:00"
},
{
"taskid": 6,
"goalid": "free",
"title": "free",
"duration": 10,
"start": "2024-01-09T14:00:00",
"deadline": "2024-01-10T00:00:00"
}
]
},
{
"day": "2024-01-10",
"tasks": [
{
"taskid": 7,
"goalid": "free",
"title": "free",
"duration": 6,
"start": "2024-01-10T00:00:00",
"deadline": "2024-01-10T06:00:00"
},
{
"taskid": 8,
"goalid": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"duration": 8,
"start": "2024-01-10T06:00:00",
"deadline": "2024-01-10T14:00:00"
},
{
"taskid": 9,
"goalid": "free",
"title": "free",
"duration": 10,
"start": "2024-01-10T14:00:00",
"deadline": "2024-01-11T00:00:00"
}
]
},
{
"day": "2024-01-11",
"tasks": [
{
"taskid": 10,
"goalid": "free",
"title": "free",
"duration": 6,
"start": "2024-01-11T00:00:00",
"deadline": "2024-01-11T06:00:00"
},
{
"taskid": 11,
"goalid": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"duration": 8,
"start": "2024-01-11T06:00:00",
"deadline": "2024-01-11T14:00:00"
},
{
"taskid": 12,
"goalid": "free",
"title": "free",
"duration": 10,
"start": "2024-01-11T14:00:00",
"deadline": "2024-01-12T00:00:00"
}
]
},
{
"day": "2024-01-12",
"tasks": [
{
"taskid": 13,
"goalid": "free",
"title": "free",
"duration": 6,
"start": "2024-01-12T00:00:00",
"deadline": "2024-01-12T06:00:00"
},
{
"taskid": 14,
"goalid": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"duration": 8,
"start": "2024-01-12T06:00:00",
"deadline": "2024-01-12T14:00:00"
},
{
"taskid": 15,
"goalid": "free",
"title": "free",
"duration": 10,
"start": "2024-01-12T14:00:00",
"deadline": "2024-01-13T00:00:00"
}
]
},
{
"day": "2024-01-13",
"tasks": [
{
"taskid": 16,
"goalid": "free",
"title": "free",
"duration": 24,
"start": "2024-01-13T00:00:00",
"deadline": "2024-01-14T00:00:00"
}
]
},
{
"day": "2024-01-14",
"tasks": [
{
"taskid": 17,
"goalid": "free",
"title": "free",
"duration": 24,
"start": "2024-01-14T00:00:00",
"deadline": "2024-01-15T00:00:00"
}
]
}
],
"impossible": []
}
37 changes: 37 additions & 0 deletions tests/jsons/stable/budget-with-subgoal/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"startDate": "2024-01-08T00:00:00",
"endDate": "2024-01-15T00:00:00",
"goals": [
{
"id": "678eab49-960e-4519-ad0b-031a2f22aaba",
"title": "Work 💪🏽",
"filters": {
"afterTime": 6,
"beforeTime": 18,
"onDays": [
"mon",
"tue",
"wed",
"thu",
"fri"
]
},
"createdAt": "2024-01-08T10:59:47.133Z",
"children": [
"103b2eff-6ba5-47b5-ad4f-81d8e8ef5998"
],
"budget": {
"minPerDay": 6,
"maxPerDay": 10,
"minPerWeek": 40,
"maxPerWeek": 40
}
},
{
"id": "103b2eff-6ba5-47b5-ad4f-81d8e8ef5998",
"title": "Plan my work week",
"createdAt": "2024-01-08T10:59:47.137Z",
"minDuration": 1
}
]
}
Loading
Loading