Use maps to track workload progress instead of recalculating them at every step of the search, calculate total days/slots once, add integration tests, add log folder
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
use docx_rs::{Docx, Paragraph, Run, RunFonts, Table, TableCell, TableRow};
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
config::UserConfig,
|
||||
schedule::MonthlySchedule,
|
||||
slot::{month_to_greek, weekday_to_greek, Day, ShiftPosition, Slot},
|
||||
workload::WorkloadTracker,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -16,13 +16,13 @@ pub enum FileType {
|
||||
}
|
||||
|
||||
pub trait Export {
|
||||
fn export(&self, file_type: FileType, config: &UserConfig);
|
||||
fn export(&self, file_type: FileType, config: &UserConfig, tracker: &WorkloadTracker);
|
||||
}
|
||||
|
||||
impl Export for MonthlySchedule {
|
||||
fn export(&self, file_type: FileType, config: &UserConfig) {
|
||||
fn export(&self, file_type: FileType, config: &UserConfig, tracker: &WorkloadTracker) {
|
||||
match file_type {
|
||||
FileType::Txt => self.export_as_txt(config),
|
||||
FileType::Txt => self.export_as_txt(config, tracker),
|
||||
FileType::Docx => self.export_as_doc(config),
|
||||
};
|
||||
|
||||
@@ -36,19 +36,19 @@ impl Export for MonthlySchedule {
|
||||
}
|
||||
|
||||
impl MonthlySchedule {
|
||||
pub fn export_as_txt(&self, config: &UserConfig) -> String {
|
||||
pub fn export_as_txt(&self, config: &UserConfig, tracker: &WorkloadTracker) -> String {
|
||||
let file = File::create("schedule.txt").unwrap();
|
||||
let mut writer = std::io::BufWriter::new(file);
|
||||
|
||||
writer
|
||||
.write_all(self.pretty_print(config).as_bytes())
|
||||
.expect("Failed to write to buffer");
|
||||
.expect("Failed to write schedule");
|
||||
|
||||
writer
|
||||
.write_all(self.report(config).as_bytes())
|
||||
.expect("Failed to write to buffer");
|
||||
.write_all(self.report(config, tracker).as_bytes())
|
||||
.expect("Failed to write report");
|
||||
|
||||
writer.flush().expect("Failed to flush buffer");
|
||||
info!("im here");
|
||||
"ok".to_string()
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ impl MonthlySchedule {
|
||||
|
||||
let mut residents_table = Table::new(vec![]);
|
||||
|
||||
for d in 1..=config.total_days() {
|
||||
for d in 1..=config.total_days {
|
||||
let day = Day(d);
|
||||
let is_weekend = day.is_weekend(config.month.number_from_month(), config.year);
|
||||
let slot_first = Slot::new(Day(d), ShiftPosition::First);
|
||||
@@ -164,8 +164,11 @@ mod tests {
|
||||
use rstest::{fixture, rstest};
|
||||
|
||||
use crate::{
|
||||
bounds::WorkloadBounds, config::UserConfig, resident::Resident, schedule::MonthlySchedule,
|
||||
config::UserConfig,
|
||||
resident::Resident,
|
||||
schedule::MonthlySchedule,
|
||||
scheduler::Scheduler,
|
||||
workload::{WorkloadBounds, WorkloadTracker},
|
||||
};
|
||||
|
||||
#[fixture]
|
||||
@@ -195,9 +198,18 @@ mod tests {
|
||||
Scheduler::new(config, bounds)
|
||||
}
|
||||
|
||||
#[fixture]
|
||||
fn tracker() -> WorkloadTracker {
|
||||
WorkloadTracker::default()
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
pub fn test_export_as_doc(mut schedule: MonthlySchedule, scheduler: Scheduler) {
|
||||
scheduler.run(&mut schedule);
|
||||
pub fn test_export_as_doc(
|
||||
mut schedule: MonthlySchedule,
|
||||
mut tracker: WorkloadTracker,
|
||||
scheduler: Scheduler,
|
||||
) {
|
||||
scheduler.run(&mut schedule, &mut tracker);
|
||||
schedule.export_as_doc(&scheduler.config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user