adds mdi icons, improves recipe design

This commit is contained in:
2019-02-12 14:07:50 +01:00
parent 02bdbf0f2c
commit 8801596de7
9 changed files with 105 additions and 65 deletions

View File

@@ -3,6 +3,7 @@
extern crate planner;
extern crate cookbook;
use std::time;
use std::fmt::Debug;
use std::fmt::Display;
use std::hash::Hash;
@@ -30,6 +31,7 @@ fn pretty_output<K: Eq + Hash + Debug>(res: &Variables<Value, K>) -> String {
}
fn main() {
let start_time = time::Instant::now();
let conn = establish_connection();
let possible_values = recipes::load_all(&conn);
let domain = Domain::new(possible_values);
@@ -39,5 +41,6 @@ fn main() {
}
let mut problem = problem.finish();
let results = problem.solve_all();
println!("{:?}", pretty_output(results.first().unwrap()));
println!("Took {:?}", start_time.elapsed());
println!("{}", pretty_output(results.first().unwrap()));
}

View File

@@ -77,9 +77,10 @@ impl<'a,V, K: Eq + Hash + Clone> Problem<'a, V, K> {
ProblemBuilder::new()
}
pub fn from_template(_template: i32) -> Problem<'a, V, K> {
Self::build()
.finish()
pub fn from_template() -> Problem<'a, V, K> {
let mut builder = Self::build();
builder.finish()
}
/// Returns all possible Updates for next assignements, prepended with

View File

@@ -6,7 +6,6 @@ const DAYS: &[&str] = &[
"Dimanche"];
/// An enum to discriminate every meals
#[allow(dead_code)]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum Meal {
Breakfast,
@@ -16,7 +15,6 @@ pub enum Meal {
type Key<'a> = (&'a str, &'a Meal);
/// Options set on a meal
#[derive(Debug, Default)]
struct MealOpts<V> {
@@ -50,28 +48,32 @@ impl<'a> Template {
-> Vec<(Key, DomainValues<Value>, Option<&Value>)>
{
use cookbook::recipes::RecipeCategory;
let mut vars_opts = Vec::new();
for key in Self::keys().into_iter() {
//TODO: is key used ? MealOpts.is_used
//TODO: Initial values
let category_filter: fn(&Value) -> bool = match key {
(_, Meal::Breakfast) => |r: &Value| {
r.category == RecipeCategory::Breakfast // Breakfast
},
(_, Meal::Lunch) => |r: &Value| {
r.category == RecipeCategory::MainCourse // MainCourse
},
(_, Meal::Dinner) => |r: &Value| {
r.category == RecipeCategory::Starter // Starter
Self::keys()
.into_iter()
.filter(|key| {
match *key {
("Samedi", _) | ("Dimanche", _) => true,
(_, Meal::Breakfast) => false,
(_,_) => true,
}
};
// TODO: has initial ?
//let key_name = format!("{}_{:?}", key.0, key.1);
let initial = None;
vars_opts.push((key, domain.filter(category_filter), initial));
}
vars_opts
})
.map(|key| {
//TODO: is key used ? MealOpts.is_used
let category_filter: fn(&Value) -> bool = match key {
(_, Meal::Breakfast) => |r: &Value| {
r.category == RecipeCategory::Breakfast // Breakfast
},
(_, Meal::Lunch) => |r: &Value| {
r.category == RecipeCategory::MainCourse // MainCourse
},
(_, Meal::Dinner) => |r: &Value| {
r.category == RecipeCategory::Starter // Starter
}
};
// TODO: has initial ?
let initial = None;
(key, domain.filter(category_filter), initial)
})
.collect()
}
}