WIP: fix: correct display of the timetable #13

Draft
Anri wants to merge 4 commits from display-timetable into main
2 changed files with 34 additions and 3 deletions
Showing only changes of commit 0d8e802db7 - Show all commits

View file

@ -6,7 +6,7 @@ use scraper::Selector;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use crate::utils::{ use crate::utils::{
get_hours, get_semester, get_webpage, get_year, format_time_slot, get_hours, get_semester, get_webpage, get_year,
models::{Info, InfoList}, models::{Info, InfoList},
Capitalize, Capitalize,
}; };
@ -271,6 +271,28 @@ fn add_courses(
} }
/// Display the timetable /// Display the timetable
pub fn display(timetable: &(Arc<[String]>, (usize, Vec<models::Day>))) { pub fn display(timetable: &(Arc<[String]>, (usize, Vec<Day>))) {
todo!("{:#?}", timetable) for day in &timetable.1 .1 {
for (index, course_option) in day.courses.iter().enumerate() {
if let Some(course) = course_option {
if index == 0 {
println!("\n{}:", day.name);
}
println!(
" {} - {} : {} ({}) // {}",
format_time_slot(course.start, course.size),
course
.category
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(", "),
course.name,
course.room,
course.professor.as_deref().unwrap_or("N/A"),
);
}
}
}
} }

View file

@ -161,3 +161,12 @@ pub fn get_count<'a>(
(courses, counts) (courses, counts)
} }
pub fn format_time_slot(start: usize, size: usize) -> String {
let start_hour = 8 + (start * 15) / 60;
let start_minute = (start * 15) % 60;
let end_hour = start_hour + (size * 15) / 60;
let end_minute = (start_minute + (size * 15)) % 60;
format!("{start_hour:02}h{start_minute:02}-{end_hour:02}h{end_minute:02}")
}