diff --git a/cookbook/src/lib.rs b/cookbook/src/lib.rs index 1a9b7cc..755c3e2 100644 --- a/cookbook/src/lib.rs +++ b/cookbook/src/lib.rs @@ -5,7 +5,6 @@ extern crate dotenv; pub mod schema; pub mod models; -mod recipe; mod importer; use diesel::prelude::*; diff --git a/cookbook/src/recipe.rs b/cookbook/src/recipe.rs deleted file mode 100644 index 1ecc7c5..0000000 --- a/cookbook/src/recipe.rs +++ /dev/null @@ -1,36 +0,0 @@ - -/// Tag associated with ingredients -#[allow(dead_code)] -pub enum FoodTag { - Viande, - Poisson, - Legume, -} - -/// Categories for recipe, to organize them for navigation and planning -#[allow(dead_code)] -pub enum RecipeCategory { - PetitDejeuner, - Entree, - Plat, - Dessert, -} - -/// A collection of tags, to be improved -type FoodTags = Vec; - -/// Nutritionnal values per 100g, to be improved -#[derive(Default)] -struct NutritionnalValues; - -/// An individual ingredient -#[derive(Default)] -#[allow(dead_code)] -pub struct Ingredient { - /// All known alias of a same ingredient - alias: Vec, - /// Nutrionnal values per 100g - nutrition: NutritionnalValues, - /// Associated tags to constraint planning - tags: FoodTags, -} diff --git a/planner/src/bin/weekly.rs b/planner/src/bin/weekly.rs index e6d4d2a..1e9fab3 100644 --- a/planner/src/bin/weekly.rs +++ b/planner/src/bin/weekly.rs @@ -12,6 +12,7 @@ use self::planner::solver::{Variables, Domain, Problem, Constraint}; /// Lunch => RecipeCategory::MainCourse /// Dinner => RecipeCategory::MainCourse type Day = String; +const DAYS: &[&str] = &["Lundi", "Mardi", "Mercredi"]; enum Meals { Breakfast(Day), @@ -36,7 +37,7 @@ enum RecipeCategory { /// It may also contains an initial value for each variable fn generate_variables(domain: &Domain) -> Vec<(String, &Domain, Option<&V>)> { let mut vars = Vec::new(); - for day in &["Lundi", "Mardi", "Mercredi"] { + for day in DAYS { vars.push((Meals::Lunch(day.to_string()).into(), domain, None)); vars.push((Meals::Dinner(day.to_string()).into(), domain, None)); } @@ -48,6 +49,19 @@ fn ingredients_contains<'a>(assign: &Variables<'a,Recipe>) -> bool { && !assign.get("Mardi_Lunch").unwrap().unwrap().ingredients.contains("Patates") } + +fn pretty_output(res: &Variables) -> String { + let mut repr = String::new(); + for (var,value) in res { + let value = match value { + Some(rec) => &rec.title, + None => "---", + }; + repr.push_str(&format!("{} => {}\n", var, value)); + } + repr +} + fn get_planning_all_results() -> String { let conn = establish_connection(); let possible_values = recipes::load_all(&conn); @@ -56,10 +70,13 @@ fn get_planning_all_results() -> String { for (var, dom, ini) in generate_variables(&domain) { problem = problem.add_variable(var, dom, ini); } - let mut problem = problem.add_constraint(ingredients_contains) - .finish(); + let mut problem = problem + .add_constraint( + ingredients_contains + ) + .finish(); let results = problem.solve_all(); - format!("{:#?}\nTotal = {}", &results.first(), results.len()) + format!("{}\nTotal = {}", pretty_output(&results.first().unwrap()), results.len()) } fn main() {