Skip to content

Commit

Permalink
Fix clippy, build wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
tijlleenders committed Feb 8, 2025
1 parent 18f5920 commit 04d285e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 68 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ dhat-heap = ["dhat"]

[lib]
#see https://github.com/rust-lang/cargo/issues/6659#issuecomment-463335095
crate-type = ['cdylib', 'lib']
crate-type = ['cdylib', 'rlib']
name = 'scheduler'
path = "src/lib.rs"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }

[profile.release]
lto = true
debug = false
Expand Down
14 changes: 7 additions & 7 deletions pkg/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ function __wbg_get_imports() {
const ret = +arg0;
return ret;
};
imports.wbg.__wbg_String_b9412f8799faab3e = function(arg0, arg1) {
const ret = String(arg1);
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
};
imports.wbg.__wbindgen_number_new = function(arg0) {
const ret = arg0;
return ret;
Expand All @@ -305,13 +312,6 @@ function __wbg_get_imports() {
const ret = getStringFromWasm0(arg0, arg1);
return ret;
};
imports.wbg.__wbg_String_b9412f8799faab3e = function(arg0, arg1) {
const ret = String(arg1);
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
};
imports.wbg.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) {
const ret = arg0[arg1];
return ret;
Expand Down
Binary file modified pkg/scheduler_bg.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn run_scheduler(
add_tasks_completed_today(
&calendar,
&goal_map,
&*tasks_completed_today,
&tasks_completed_today,
&mut activities,
);
place(&mut calendar, &mut activities);
Expand All @@ -133,7 +133,7 @@ pub fn run_scheduler(
place(&mut calendar, &mut activities);

dbg!(&calendar); //before get_budget_min
add_budget_min_week_activities(&mut calendar, &goal_map, &mut activities);
add_budget_min_week_activities(&calendar, &goal_map, &mut activities);
place(&mut calendar, &mut activities);

dbg!(&calendar); //before get_budget_top_up_week
Expand Down
5 changes: 4 additions & 1 deletion src/models/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{
ops::{Add, Sub},
};

use chrono::{Datelike, Duration, NaiveTime};
#[cfg(debug_assertions)]
use chrono::NaiveTime;
use chrono::{Datelike, Duration};

use serde::Deserialize;

use super::{
Expand Down
63 changes: 34 additions & 29 deletions src/models/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,11 @@ impl Calendar {
"can't request an index more than 1 day outside of calendar bounds for date {:?}\nCalendar starts at {:?} and ends at {:?}", date_time, self.start_date_time, self.end_date_time
)
}
let index =
(date_time.add(Duration::hours(24)) - self.start_date_time).num_hours() as usize;
// let index =
// (date_time.add(Duration::hours(24)) - self.start_date_time).num_hours() as usize;
// println!("got index of {}: {}", date_time, index);
index
// index
(date_time.add(Duration::hours(24)) - self.start_date_time).num_hours() as usize
}
pub fn print_new(&mut self, activities: &Vec<Activity>) -> FinalTasks {
println!("Printing new calendar:");
Expand All @@ -457,34 +458,38 @@ impl Calendar {
//fill goal_map and budget_ids
let mut budget_ids: Vec<String> = vec![];
for goal in goal_map.values() {
if let Some(budget_config) = &goal.budget_config {
//Check if budget_config is realistic

//check 1
let mut min_per_day_sum = 0;
if let Some(filters) = &goal.filters {
for _ in &filters.on_days {
min_per_day_sum += budget_config.min_per_day;
#[cfg(debug_assertions)]
{
if let Some(budget_config) = &goal.budget_config {
//Check if budget_config is realistic

//check 1
let mut min_per_day_sum = 0;
if let Some(filters) = &goal.filters {
for _ in &filters.on_days {
min_per_day_sum += budget_config.min_per_day;
}
}
assert!(
min_per_day_sum <= budget_config.min_per_week,
"Sum of min_per_day {:?} is higher than min_per_week {:?} for goal {:?}",
min_per_day_sum,
budget_config.min_per_week,
goal.title
);

//check 2
#[cfg(debug_assertions)]
assert!(
budget_config.max_per_day <= budget_config.max_per_week,
"max_per_day {:?} is higher than max_per_week {:?} for goal {:?}",
budget_config.max_per_day,
budget_config.max_per_week,
goal.title
);
}
#[cfg(debug_assertions)]
assert!(
min_per_day_sum <= budget_config.min_per_week,
"Sum of min_per_day {:?} is higher than min_per_week {:?} for goal {:?}",
min_per_day_sum,
budget_config.min_per_week,
goal.title
);

//check 2
#[cfg(debug_assertions)]
assert!(
budget_config.max_per_day <= budget_config.max_per_week,
"max_per_day {:?} is higher than max_per_week {:?} for goal {:?}",
budget_config.max_per_day,
budget_config.max_per_week,
goal.title
);
}
if let Some(_budget_config) = &goal.budget_config {
budget_ids.push(goal.id.clone());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/activity_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ pub(crate) fn add_tasks_completed_today(
total_duration: activity_end_index - activity_start_index,
duration_left: activity_end_index - activity_start_index,
status: ActivityStatus::Unprocessed,
start: task.start.clone(),
deadline: Some(task.deadline.clone()),
start: task.start,
deadline: Some(task.deadline),
compatible_intervals: vec![Interval {
start: activity_start_index,
end: activity_end_index,
Expand Down
2 changes: 1 addition & 1 deletion src/services/activity_placer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct LeastConflict {

impl Debug for LeastConflict {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(
let _ = writeln!(
f,
"{:?} claims on {:?}-{:?} ({:?}:00-{:?}:00) day {:?}",
self.claims,
Expand Down
26 changes: 1 addition & 25 deletions src/services/interval_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ pub fn reduce(compatible_hours: &[bool]) -> Vec<Interval> {
result
}

fn normalize(intervals: &mut Vec<Interval>) {
intervals.sort_by_key(|i| i.start);
let mut result = Vec::new();
if let Some(first) = intervals.first().cloned() {
let mut current = first;
for interval in intervals.iter().skip(1) {
if interval.start <= current.end {
current.end = current.end.max(interval.end);
} else {
result.push(current);
current = interval.clone();
}
}
result.push(current);
}
*intervals = result;
}

fn add_intervals(mut a: Vec<Interval>, b: Vec<Interval>) -> Vec<Interval> {
a.extend(b);
normalize(&mut a);
a
}

fn subtract_intervals(a: Vec<Interval>, b: &Vec<Interval>) -> Vec<Interval> {
let mut result = Vec::new();
for interval in a {
Expand Down Expand Up @@ -110,7 +86,7 @@ pub(crate) fn get_compatible_intervals(
let mut intervals_to_remove: Vec<Interval> = vec![];
if let Some(filter) = filter {
let end = calendar.end_date_time;
let mut current = calendar.start_date_time.sub(Duration::days(1)).clone();
let mut current = calendar.start_date_time.sub(Duration::days(1));
let mut current_index_offset: usize = 0;

while current <= end {
Expand Down

0 comments on commit 04d285e

Please sign in to comment.