option to not differentiate TD from TP (#5)
This commit is contained in:
parent
e0afc9414f
commit
6bc3a5643c
3 changed files with 27 additions and 11 deletions
|
@ -4,12 +4,13 @@ use crate::timetable::models::Category;
|
||||||
use crate::timetable::models::Timetable;
|
use crate::timetable::models::Timetable;
|
||||||
use crate::utils::get_count;
|
use crate::utils::get_count;
|
||||||
use crate::utils::get_entry;
|
use crate::utils::get_entry;
|
||||||
|
use crate::utils::get_entry_nocat;
|
||||||
use crate::utils::get_selection;
|
use crate::utils::get_selection;
|
||||||
|
|
||||||
const DISCLAIMER: &str = "(selection avec ESPACE, ENTRER pour valider)";
|
const DISCLAIMER: &str = "(selection avec ESPACE, ENTRER pour valider)";
|
||||||
|
|
||||||
/// Filter the timetable
|
/// Filter the timetable
|
||||||
pub fn timetable(timetable: Timetable) -> Timetable {
|
pub fn timetable(timetable: Timetable, merge_td_tp: bool) -> Timetable {
|
||||||
let mut my_timetable = timetable;
|
let mut my_timetable = timetable;
|
||||||
|
|
||||||
/* Note on Cours/TD:
|
/* Note on Cours/TD:
|
||||||
|
@ -21,7 +22,7 @@ pub fn timetable(timetable: Timetable) -> Timetable {
|
||||||
|
|
||||||
choice(&mut my_timetable);
|
choice(&mut my_timetable);
|
||||||
courses(&mut my_timetable);
|
courses(&mut my_timetable);
|
||||||
tdtp(&mut my_timetable);
|
tdtp(&mut my_timetable, merge_td_tp);
|
||||||
|
|
||||||
my_timetable
|
my_timetable
|
||||||
}
|
}
|
||||||
|
@ -65,12 +66,14 @@ fn choice(timetable: &mut Timetable) {
|
||||||
|
|
||||||
/// Filter the multiple courses
|
/// Filter the multiple courses
|
||||||
fn courses(timetable: &mut Timetable) {
|
fn courses(timetable: &mut Timetable) {
|
||||||
|
let entry_getter = get_entry;
|
||||||
|
|
||||||
// List of courses and Counter of how much they appears
|
// List of courses and Counter of how much they appears
|
||||||
// to know if multiples slots are available
|
// to know if multiples slots are available
|
||||||
let (mut courses, counts) = get_count(timetable, &[Category::Cours]);
|
let (mut courses, counts) = get_count(timetable, &[Category::Cours], entry_getter);
|
||||||
|
|
||||||
// Keep only elements who have multiples slots
|
// Keep only elements who have multiples slots
|
||||||
courses.retain(|course| *counts.get(&get_entry(course.0)).unwrap() > 1);
|
courses.retain(|course| *counts.get(&entry_getter(course.0)).unwrap() > 1);
|
||||||
|
|
||||||
let mut multiselected: Vec<String> = courses.iter().map(get_selection).collect();
|
let mut multiselected: Vec<String> = courses.iter().map(get_selection).collect();
|
||||||
multiselected.sort();
|
multiselected.sort();
|
||||||
|
@ -98,7 +101,7 @@ fn courses(timetable: &mut Timetable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep if only one slot is available
|
// Keep if only one slot is available
|
||||||
if *counts.get(&get_entry(course)).unwrap() == 1 {
|
if *counts.get(&entry_getter(course)).unwrap() == 1 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,13 +119,16 @@ fn courses(timetable: &mut Timetable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filter the multiples TD/TP
|
/// Filter the multiples TD/TP
|
||||||
fn tdtp(timetable: &mut Timetable) {
|
fn tdtp(timetable: &mut Timetable, merge: bool) {
|
||||||
|
// If we differentiate TD from TP
|
||||||
|
let entry_getter = if merge { get_entry_nocat } else { get_entry };
|
||||||
|
|
||||||
// List of TP/TD and Counter of how much they appears
|
// List of TP/TD and Counter of how much they appears
|
||||||
// to know if multiples slots are available
|
// to know if multiples slots are available
|
||||||
let (mut td_or_tp, counts) = get_count(timetable, &[Category::TD, Category::TP]);
|
let (mut td_or_tp, counts) = get_count(timetable, &[Category::TD, Category::TP], entry_getter);
|
||||||
|
|
||||||
// Keep only elements who have multiples TD/TP
|
// Keep only elements who have multiples TD/TP
|
||||||
td_or_tp.retain(|course| *counts.get(&get_entry(course.0)).unwrap() > 1);
|
td_or_tp.retain(|course| *counts.get(&entry_getter(course.0)).unwrap() > 1);
|
||||||
|
|
||||||
let mut multiselected: Vec<String> = td_or_tp.iter().map(get_selection).collect();
|
let mut multiselected: Vec<String> = td_or_tp.iter().map(get_selection).collect();
|
||||||
multiselected.sort();
|
multiselected.sort();
|
||||||
|
@ -148,7 +154,7 @@ fn tdtp(timetable: &mut Timetable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep if only one slot is available of the TD/TP
|
// Keep if only one slot is available of the TD/TP
|
||||||
if *counts.get(&get_entry(course)).unwrap() == 1 {
|
if *counts.get(&entry_getter(course)).unwrap() == 1 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ struct Args {
|
||||||
/// Size of cell of the timetable (irrelevant when exporting the timetable)
|
/// Size of cell of the timetable (irrelevant when exporting the timetable)
|
||||||
#[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)]
|
#[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)]
|
||||||
cl: usize,
|
cl: usize,
|
||||||
|
|
||||||
|
/// Doesn't distinguish TD from TP
|
||||||
|
#[clap(short, long)]
|
||||||
|
td_are_tp: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -52,7 +56,7 @@ async fn main() {
|
||||||
println!("Récupération de l'emploi du temps des M{}...", level,);
|
println!("Récupération de l'emploi du temps des M{}...", level,);
|
||||||
let mut timetable = timetable::timetable(level, args.semester, args.year, &user_agent).await;
|
let mut timetable = timetable::timetable(level, args.semester, args.year, &user_agent).await;
|
||||||
|
|
||||||
timetable = filter::timetable(timetable);
|
timetable = filter::timetable(timetable, args.td_are_tp);
|
||||||
|
|
||||||
println!("Récupération des informations par rapport à l'année...");
|
println!("Récupération des informations par rapport à l'année...");
|
||||||
let info = info::info(level, args.semester, args.year, &user_agent).await;
|
let info = info::info(level, args.semester, args.year, &user_agent).await;
|
||||||
|
|
|
@ -224,10 +224,16 @@ pub fn get_entry(course: &Course) -> String {
|
||||||
format!("{} - {:?}", course.name, course.category)
|
format!("{} - {:?}", course.name, course.category)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Entry's name used for finding duplicates, ignoring categories
|
||||||
|
pub fn get_entry_nocat(course: &Course) -> String {
|
||||||
|
course.name.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a couple of (list of courses) and (a hashmap of how much they appears in the vector)
|
/// Returns a couple of (list of courses) and (a hashmap of how much they appears in the vector)
|
||||||
pub fn get_count<'a>(
|
pub fn get_count<'a>(
|
||||||
timetable: &'a mut Timetable,
|
timetable: &'a mut Timetable,
|
||||||
allowed_list: &'a [Category],
|
allowed_list: &'a [Category],
|
||||||
|
getter: fn(&Course) -> String,
|
||||||
) -> (Vec<(&'a Course, String)>, HashMap<String, i32>) {
|
) -> (Vec<(&'a Course, String)>, HashMap<String, i32>) {
|
||||||
// List of courses who will be courses
|
// List of courses who will be courses
|
||||||
let mut courses = vec![];
|
let mut courses = vec![];
|
||||||
|
@ -242,7 +248,7 @@ pub fn get_count<'a>(
|
||||||
.any(|category| allowed_list.contains(category))
|
.any(|category| allowed_list.contains(category))
|
||||||
{
|
{
|
||||||
courses.push((course, day.name.to_owned()));
|
courses.push((course, day.name.to_owned()));
|
||||||
let count = counts.entry(get_entry(course)).or_insert(0);
|
let count = counts.entry(getter(course)).or_insert(0);
|
||||||
*count += 1;
|
*count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue