Update material types
Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
parent
669f789903
commit
d9f0ddf0ca
2 changed files with 395 additions and 304 deletions
|
|
@ -1,4 +1,8 @@
|
|||
use std::{collections::HashMap, fs::File, io};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
fs::File,
|
||||
io,
|
||||
};
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime};
|
||||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
|
|
@ -11,6 +15,11 @@ pub trait CommonRecipeTrait {
|
|||
fn compare(&self, another_setting: &Self) -> Vec<String>;
|
||||
}
|
||||
|
||||
pub trait CommonCompressTrait {
|
||||
fn flatten(&mut self) -> BTreeMap<String, Value>;
|
||||
fn unflatten(&mut self, flatted: BTreeMap<String, Value>) -> BTreeMap<String, Value>;
|
||||
}
|
||||
|
||||
macro_rules! compare_field {
|
||||
($self: ident, $another_setting: ident, $list: ident, $field: ident) => {
|
||||
if $self.$field != $another_setting.$field {
|
||||
|
|
@ -686,9 +695,30 @@ impl Recipe {
|
|||
//
|
||||
//
|
||||
|
||||
#[deprecated]
|
||||
pub fn add_prefix_country_code(&mut self) {}
|
||||
|
||||
pub fn get_prefix_country_code(&mut self) -> String {
|
||||
// get by first recipe as sample
|
||||
let rp_clone = self.Recipe01.clone();
|
||||
let first_recipe = rp_clone.first().unwrap();
|
||||
let product_code_split = first_recipe.productCode.split("-").collect::<Vec<&str>>();
|
||||
|
||||
product_code_split.first().unwrap().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
// impl CommonCompressTrait for Recipe {
|
||||
// fn flatten(&mut self) -> BTreeMap<String, Value> {
|
||||
// let mut result = BTreeMap::new();
|
||||
// let mut map = serde_json::json!(*self);
|
||||
|
||||
// result
|
||||
// }
|
||||
|
||||
// fn unflatten(&mut self, flatted: BTreeMap<String, Value>) -> BTreeMap<String, Value> {}
|
||||
// }
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
fn StrShowTextErrorDefault() -> Option<Vec<Value>> {
|
||||
Some(vec![
|
||||
|
|
@ -1594,6 +1624,7 @@ pub struct RecipeList {
|
|||
|
||||
pub enum MaterialType {
|
||||
Bean,
|
||||
Brew,
|
||||
Syrup,
|
||||
Soda,
|
||||
Powder,
|
||||
|
|
@ -1606,11 +1637,52 @@ pub enum MaterialType {
|
|||
Leaves,
|
||||
Clean,
|
||||
CleanV2,
|
||||
IceScreamBingsu,
|
||||
FreshSyrup,
|
||||
FrozenFruit,
|
||||
// esp module
|
||||
// check
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl RecipeList {
|
||||
pub fn get_material_type(&mut self) {}
|
||||
pub fn get_material_type(&mut self, country_code: Option<String>) -> MaterialType {
|
||||
let pure_mat_id = if country_code.is_some() {
|
||||
let cc = country_code.unwrap().parse::<i64>().expect("not a number");
|
||||
let mat_num = self.materialPathId.clone().as_i64().unwrap();
|
||||
|
||||
let check_if_start_with_cc = mat_num.to_string().starts_with(&format!("{cc}"));
|
||||
|
||||
if check_if_start_with_cc {
|
||||
mat_num - (cc * 10000)
|
||||
} else {
|
||||
mat_num
|
||||
}
|
||||
} else {
|
||||
self.materialPathId.clone().as_i64().expect("not a number")
|
||||
};
|
||||
|
||||
return match pure_mat_id {
|
||||
8000 => MaterialType::Brew,
|
||||
8001 => MaterialType::Clean,
|
||||
8002 => MaterialType::CleanV2,
|
||||
1031 => MaterialType::Soda,
|
||||
1 => MaterialType::Water,
|
||||
9100 => MaterialType::Ice,
|
||||
8102..8104 => MaterialType::Whipper,
|
||||
1001..1009 | 1100..1200 => MaterialType::Bean,
|
||||
1600..1800 => MaterialType::Leaves,
|
||||
1032..1040 | 1020..1031 | 1200..1300 | 1400..1500 => MaterialType::Syrup,
|
||||
1040..1081 | 1300..1400 => MaterialType::Powder,
|
||||
9500..9550 => MaterialType::Cup,
|
||||
9600..9650 => MaterialType::Lid,
|
||||
9700..9750 => MaterialType::Straw,
|
||||
2100..2201 => MaterialType::IceScreamBingsu,
|
||||
2201..2301 => MaterialType::FreshSyrup,
|
||||
2301..2501 => MaterialType::FrozenFruit,
|
||||
_ => MaterialType::Unknown,
|
||||
};
|
||||
}
|
||||
|
||||
// grep data fn
|
||||
pub fn get_data_used_in_brew(&mut self) -> Value {
|
||||
|
|
@ -1770,26 +1842,42 @@ impl CommonRecipeTrait for MaterialSetting {
|
|||
}
|
||||
|
||||
impl MaterialSetting {
|
||||
pub fn get_definition_type(&mut self) -> MaterialType {
|
||||
match self.id.as_i64().unwrap() {
|
||||
8102..8103 => MaterialType::Whipper,
|
||||
9100 => MaterialType::Ice,
|
||||
pub fn get_definition_type(&mut self, country_code: Option<String>) -> MaterialType {
|
||||
let pure_mat_id = if country_code.is_some() {
|
||||
let cc = country_code.unwrap().parse::<i64>().expect("not a number");
|
||||
let mat_num = self.id.clone().as_i64().unwrap();
|
||||
|
||||
let check_if_start_with_cc = mat_num.to_string().starts_with(&format!("{cc}"));
|
||||
|
||||
if check_if_start_with_cc {
|
||||
mat_num - (cc * 10000)
|
||||
} else {
|
||||
mat_num
|
||||
}
|
||||
} else {
|
||||
self.id.clone().as_i64().expect("not a number")
|
||||
};
|
||||
|
||||
return match pure_mat_id {
|
||||
8000 => MaterialType::Brew,
|
||||
8001 => MaterialType::Clean,
|
||||
8002 => MaterialType::CleanV2,
|
||||
_ => {
|
||||
if self.BeanChannel {
|
||||
MaterialType::Bean
|
||||
} else if self.PowderChannel {
|
||||
MaterialType::Powder
|
||||
} else if self.SyrupChannel {
|
||||
MaterialType::Syrup
|
||||
} else if self.SodaChannel {
|
||||
MaterialType::Soda
|
||||
} else {
|
||||
MaterialType::Unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
1031 => MaterialType::Soda,
|
||||
1 => MaterialType::Water,
|
||||
9100 => MaterialType::Ice,
|
||||
8102..8104 => MaterialType::Whipper,
|
||||
1001..1009 | 1100..1200 => MaterialType::Bean,
|
||||
1600..1800 => MaterialType::Leaves,
|
||||
1032..1040 | 1020..1031 | 1200..1300 | 1400..1500 => MaterialType::Syrup,
|
||||
1040..1081 | 1300..1400 => MaterialType::Powder,
|
||||
9500..9550 => MaterialType::Cup,
|
||||
9600..9650 => MaterialType::Lid,
|
||||
9700..9750 => MaterialType::Straw,
|
||||
2100..2201 => MaterialType::IceScreamBingsu,
|
||||
2201..2301 => MaterialType::FreshSyrup,
|
||||
2301..2501 => MaterialType::FrozenFruit,
|
||||
_ => MaterialType::Unknown,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,334 +10,335 @@ use crate::{
|
|||
previews::{csvf::*, header::Headers},
|
||||
};
|
||||
|
||||
pub fn import_menu(main_version: usize, country_name: &str, into_version: usize) {
|
||||
let latest_recipe_thai = create_recipe_model_from_file(create_recipe_path("tha", main_version));
|
||||
// #[deprecated]
|
||||
// pub fn import_menu(main_version: usize, country_name: &str, into_version: usize) {
|
||||
// let latest_recipe_thai = create_recipe_model_from_file(create_recipe_path("tha", main_version));
|
||||
|
||||
// let mut latest_recipe_mys =
|
||||
// create_recipe_model_from_file(create_recipe_path("mys", *mys_version.unwrap()));
|
||||
// // let mut latest_recipe_mys =
|
||||
// // create_recipe_model_from_file(create_recipe_path("mys", *mys_version.unwrap()));
|
||||
|
||||
let mut latest_recipe_sgp =
|
||||
create_recipe_model_from_file(create_recipe_path(country_name, into_version));
|
||||
// let mut latest_recipe_sgp =
|
||||
// create_recipe_model_from_file(create_recipe_path(country_name, into_version));
|
||||
|
||||
let diff_list = latest_recipe_thai.list_diff_pd_ignore_country_code(&latest_recipe_sgp);
|
||||
// let diff_list = latest_recipe_thai.list_diff_pd_ignore_country_code(&latest_recipe_sgp);
|
||||
|
||||
let mut menu_no_sugar_table = Table::new();
|
||||
let insert_later_config = TableConfig {
|
||||
allow_row_length_exceeds_header: false,
|
||||
auto_fix_size: true,
|
||||
auto_fix_size_strategy: AutoFixSizeStrategy::FillRowToMatchHeader {
|
||||
default_value: "".to_string(),
|
||||
},
|
||||
};
|
||||
// let mut menu_no_sugar_table = Table::new();
|
||||
// let insert_later_config = TableConfig {
|
||||
// allow_row_length_exceeds_header: false,
|
||||
// auto_fix_size: true,
|
||||
// auto_fix_size_strategy: AutoFixSizeStrategy::FillRowToMatchHeader {
|
||||
// default_value: "".to_string(),
|
||||
// },
|
||||
// };
|
||||
|
||||
let mut sg_price_table = menu_no_sugar_table.clone();
|
||||
let mut recipe_table = menu_no_sugar_table.clone();
|
||||
// let mut sg_price_table = menu_no_sugar_table.clone();
|
||||
// let mut recipe_table = menu_no_sugar_table.clone();
|
||||
|
||||
menu_no_sugar_table.set_config(insert_later_config.clone());
|
||||
sg_price_table.set_config(insert_later_config.clone());
|
||||
recipe_table.set_config(insert_later_config.clone());
|
||||
// menu_no_sugar_table.set_config(insert_later_config.clone());
|
||||
// sg_price_table.set_config(insert_later_config.clone());
|
||||
// recipe_table.set_config(insert_later_config.clone());
|
||||
|
||||
menu_no_sugar_table.set_header(["Product Code", "Name"].to_vec());
|
||||
sg_price_table.set_header(["SKU", "English Name", "Thai Name"].to_vec());
|
||||
// menu_no_sugar_table.set_header(["Product Code", "Name"].to_vec());
|
||||
// sg_price_table.set_header(["SKU", "English Name", "Thai Name"].to_vec());
|
||||
|
||||
recipe_table.set_header(Headers::get_recipe_table_sgp_24022025());
|
||||
// recipe_table.set_header(Headers::get_recipe_table_sgp_24022025());
|
||||
|
||||
let modified_recipes = change_prefix_by_country(
|
||||
country_name,
|
||||
latest_recipe_thai.search_multi_in_parallel(diff_list),
|
||||
);
|
||||
// let modified_recipes = change_prefix_by_country(
|
||||
// country_name,
|
||||
// latest_recipe_thai.search_multi_in_parallel(diff_list),
|
||||
// );
|
||||
|
||||
// also clone mat setting
|
||||
// ** Will removed this
|
||||
let from_tha_mat_settings = [
|
||||
latest_recipe_thai.search_material_settings("2201".to_string()),
|
||||
latest_recipe_thai.search_material_settings("1217".to_string()),
|
||||
latest_recipe_thai.search_material_settings("1038".to_string()),
|
||||
latest_recipe_thai.search_material_settings("1037".to_string()),
|
||||
];
|
||||
// // also clone mat setting
|
||||
// // ** Will removed this
|
||||
// let from_tha_mat_settings = [
|
||||
// latest_recipe_thai.search_material_settings("2201".to_string()),
|
||||
// latest_recipe_thai.search_material_settings("1217".to_string()),
|
||||
// latest_recipe_thai.search_material_settings("1038".to_string()),
|
||||
// latest_recipe_thai.search_material_settings("1037".to_string()),
|
||||
// ];
|
||||
|
||||
let mut formatted_mat_settings = Vec::new();
|
||||
from_tha_mat_settings.iter().for_each(|mat_smth| {
|
||||
let new_mat_smth = *mat_smth;
|
||||
if let Some(x) = new_mat_smth {
|
||||
let mut cl_x = x.clone();
|
||||
let mut new_mat_id = cl_x.id.clone().as_i64().unwrap().to_string();
|
||||
// new_product_code = format!("{}-{}", "sgp", new_product_code.split_once('-').unwrap().1);
|
||||
new_mat_id = format!("{}{}", get_mat_prefix(country_name), new_mat_id);
|
||||
cl_x.id = Value::Number(Number::from_str(&new_mat_id).unwrap()).clone();
|
||||
// debug!("new formatted mat settings [SGP] -> {:?}", cl_x);
|
||||
formatted_mat_settings.push(cl_x);
|
||||
}
|
||||
});
|
||||
// let mut formatted_mat_settings = Vec::new();
|
||||
// from_tha_mat_settings.iter().for_each(|mat_smth| {
|
||||
// let new_mat_smth = *mat_smth;
|
||||
// if let Some(x) = new_mat_smth {
|
||||
// let mut cl_x = x.clone();
|
||||
// let mut new_mat_id = cl_x.id.clone().as_i64().unwrap().to_string();
|
||||
// // new_product_code = format!("{}-{}", "sgp", new_product_code.split_once('-').unwrap().1);
|
||||
// new_mat_id = format!("{}{}", get_mat_prefix(country_name), new_mat_id);
|
||||
// cl_x.id = Value::Number(Number::from_str(&new_mat_id).unwrap()).clone();
|
||||
// // debug!("new formatted mat settings [SGP] -> {:?}", cl_x);
|
||||
// formatted_mat_settings.push(cl_x);
|
||||
// }
|
||||
// });
|
||||
|
||||
latest_recipe_sgp
|
||||
.MaterialSetting
|
||||
.extend(formatted_mat_settings.clone());
|
||||
// latest_recipe_sgp
|
||||
// .MaterialSetting
|
||||
// .extend(formatted_mat_settings.clone());
|
||||
|
||||
// debug!("modified recipes: {:#?}", modified_recipes);
|
||||
// // debug!("modified recipes: {:#?}", modified_recipes);
|
||||
|
||||
// process: generate table
|
||||
modified_recipes.iter().enumerate().for_each(|mr| {
|
||||
menu_no_sugar_table.add_row(vec![
|
||||
mr.1.productCode.clone(),
|
||||
mr.1.name.clone().unwrap().to_string().replace("\n", "\\n"),
|
||||
]);
|
||||
sg_price_table.add_row(vec![
|
||||
mr.1.productCode.clone(),
|
||||
mr.1.otherName
|
||||
.clone()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.replace("\n", "\\n"),
|
||||
mr.1.name.clone().unwrap().to_string().replace("\n", "\\n"),
|
||||
]);
|
||||
// // process: generate table
|
||||
// modified_recipes.iter().enumerate().for_each(|mr| {
|
||||
// menu_no_sugar_table.add_row(vec![
|
||||
// mr.1.productCode.clone(),
|
||||
// mr.1.name.clone().unwrap().to_string().replace("\n", "\\n"),
|
||||
// ]);
|
||||
// sg_price_table.add_row(vec![
|
||||
// mr.1.productCode.clone(),
|
||||
// mr.1.otherName
|
||||
// .clone()
|
||||
// .unwrap()
|
||||
// .to_string()
|
||||
// .replace("\n", "\\n"),
|
||||
// mr.1.name.clone().unwrap().to_string().replace("\n", "\\n"),
|
||||
// ]);
|
||||
|
||||
// Pre process for recipe table
|
||||
// // Pre process for recipe table
|
||||
|
||||
// let mut missing_support_mats = Vec::new();
|
||||
let binding = mr.1.clone();
|
||||
let mat_list = binding
|
||||
.recipes
|
||||
.iter()
|
||||
.filter(|r| r.isUse)
|
||||
.map(|r| {
|
||||
// debug!(
|
||||
// "r->{:?}",
|
||||
// r.materialPathId
|
||||
// .clone()
|
||||
// .as_number()
|
||||
// .unwrap()
|
||||
// .as_i64()
|
||||
// .unwrap()
|
||||
// .to_string()
|
||||
// );
|
||||
// // let mut missing_support_mats = Vec::new();
|
||||
// let binding = mr.1.clone();
|
||||
// let mat_list = binding
|
||||
// .recipes
|
||||
// .iter()
|
||||
// .filter(|r| r.isUse)
|
||||
// .map(|r| {
|
||||
// // debug!(
|
||||
// // "r->{:?}",
|
||||
// // r.materialPathId
|
||||
// // .clone()
|
||||
// // .as_number()
|
||||
// // .unwrap()
|
||||
// // .as_i64()
|
||||
// // .unwrap()
|
||||
// // .to_string()
|
||||
// // );
|
||||
|
||||
r.materialPathId
|
||||
.as_number()
|
||||
.unwrap()
|
||||
.as_i64()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
})
|
||||
.collect::<Vec<String>>();
|
||||
// r.materialPathId
|
||||
// .as_number()
|
||||
// .unwrap()
|
||||
// .as_i64()
|
||||
// .unwrap()
|
||||
// .to_string()
|
||||
// })
|
||||
// .collect::<Vec<String>>();
|
||||
|
||||
let mut mapping_mats = Vec::new();
|
||||
// let mut missing_header = Vec::new();
|
||||
// let mut mapping_mats = Vec::new();
|
||||
// // let mut missing_header = Vec::new();
|
||||
|
||||
mat_list.iter().enumerate().for_each(|(idx, mat)| {
|
||||
// if (!mat.parse::<i64>().unwrap().eq(&0i64)
|
||||
// && !recipe_table
|
||||
// .clone()
|
||||
// .get_current_header()
|
||||
// .contains(&mat.to_string()))
|
||||
// {
|
||||
// // missing_support_mats.push((idx, mat.to_string()));
|
||||
// // add to header
|
||||
// mat_list.iter().enumerate().for_each(|(idx, mat)| {
|
||||
// // if (!mat.parse::<i64>().unwrap().eq(&0i64)
|
||||
// // && !recipe_table
|
||||
// // .clone()
|
||||
// // .get_current_header()
|
||||
// // .contains(&mat.to_string()))
|
||||
// // {
|
||||
// // // missing_support_mats.push((idx, mat.to_string()));
|
||||
// // // add to header
|
||||
|
||||
// // recipe_table.add_header(mat);
|
||||
// missing_header.push(mat);
|
||||
// }
|
||||
// // // recipe_table.add_header(mat);
|
||||
// // missing_header.push(mat);
|
||||
// // }
|
||||
|
||||
// skip zero
|
||||
if !mat.eq("0") {
|
||||
mapping_mats.push((idx, mat));
|
||||
}
|
||||
});
|
||||
// // skip zero
|
||||
// if !mat.eq("0") {
|
||||
// mapping_mats.push((idx, mat));
|
||||
// }
|
||||
// });
|
||||
|
||||
// if (!missing_header.is_empty()) {
|
||||
// missing_header.iter().for_each(|mh| {
|
||||
// if (!recipe_table
|
||||
// .clone()
|
||||
// .get_current_header()
|
||||
// .contains(mh.clone()))
|
||||
// {
|
||||
// recipe_table.add_header(mh);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
let inter_name_empty = mr.1.otherName.clone().unwrap().is_empty();
|
||||
let used_name = if inter_name_empty {
|
||||
mr.1.name.clone().unwrap().to_string().replace("\n", "\\n")
|
||||
} else {
|
||||
mr.1.otherName
|
||||
.clone()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.replace("\n", "\\n")
|
||||
};
|
||||
let mut used_mats = vec![used_name, mr.1.productCode.clone()];
|
||||
// // if (!missing_header.is_empty()) {
|
||||
// // missing_header.iter().for_each(|mh| {
|
||||
// // if (!recipe_table
|
||||
// // .clone()
|
||||
// // .get_current_header()
|
||||
// // .contains(mh.clone()))
|
||||
// // {
|
||||
// // recipe_table.add_header(mh);
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
// let inter_name_empty = mr.1.otherName.clone().unwrap().is_empty();
|
||||
// let used_name = if inter_name_empty {
|
||||
// mr.1.name.clone().unwrap().to_string().replace("\n", "\\n")
|
||||
// } else {
|
||||
// mr.1.otherName
|
||||
// .clone()
|
||||
// .unwrap()
|
||||
// .to_string()
|
||||
// .replace("\n", "\\n")
|
||||
// };
|
||||
// let mut used_mats = vec![used_name, mr.1.productCode.clone()];
|
||||
|
||||
// add by using mat
|
||||
// // add by using mat
|
||||
|
||||
// let mut reorder1 = Vec::new();
|
||||
// let mut add_last = Vec::new();
|
||||
// // let mut reorder1 = Vec::new();
|
||||
// // let mut add_last = Vec::new();
|
||||
|
||||
// reorder by header
|
||||
// recipe_table.clone().get_current_header().iter().for_each(|h| {
|
||||
// let mut found = false;
|
||||
// mapping_mats.iter().for_each(|(idx, mat)| {
|
||||
// if (h.eq(mat)) {
|
||||
// found = true;
|
||||
// reorder1.push((idx, mat));
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// // reorder by header
|
||||
// // recipe_table.clone().get_current_header().iter().for_each(|h| {
|
||||
// // let mut found = false;
|
||||
// // mapping_mats.iter().for_each(|(idx, mat)| {
|
||||
// // if (h.eq(mat)) {
|
||||
// // found = true;
|
||||
// // reorder1.push((idx, mat));
|
||||
// // }
|
||||
// // });
|
||||
// // });
|
||||
|
||||
// recipe
|
||||
let mut recipe_brew_values_only = vec![0; recipe_table.clone().get_current_header().len()];
|
||||
let recipe_list = mr.1.clone().recipes;
|
||||
// // recipe
|
||||
// let mut recipe_brew_values_only = vec![0; recipe_table.clone().get_current_header().len()];
|
||||
// let recipe_list = mr.1.clone().recipes;
|
||||
|
||||
let mut add_more_to_blender = 0i64;
|
||||
// let mut add_more_to_blender = 0i64;
|
||||
|
||||
for repl in recipe_list.iter() {
|
||||
let current_mat = repl.materialPathId.as_number().unwrap().as_i64().unwrap();
|
||||
if repl.isUse {
|
||||
recipe_table
|
||||
.clone()
|
||||
.get_current_header()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.for_each(|(header_idx, header)| {
|
||||
if header_idx > 1 && header.eq(¤t_mat.to_string()) {
|
||||
// search mat settings for further info
|
||||
let mat_setting =
|
||||
latest_recipe_sgp.search_material_settings(current_mat.to_string());
|
||||
// for repl in recipe_list.iter() {
|
||||
// let current_mat = repl.materialPathId.as_number().unwrap().as_i64().unwrap();
|
||||
// if repl.isUse {
|
||||
// recipe_table
|
||||
// .clone()
|
||||
// .get_current_header()
|
||||
// .iter()
|
||||
// .enumerate()
|
||||
// .for_each(|(header_idx, header)| {
|
||||
// if header_idx > 1 && header.eq(¤t_mat.to_string()) {
|
||||
// // search mat settings for further info
|
||||
// let mat_setting =
|
||||
// latest_recipe_sgp.search_material_settings(current_mat.to_string());
|
||||
|
||||
if let Some(mat_s) = mat_setting {
|
||||
match mat_s.clone().get_definition_type() {
|
||||
recipe::MaterialType::Bean => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.powderGram.as_i64().unwrap();
|
||||
// if let Some(mat_s) = mat_setting {
|
||||
// match mat_s.clone().get_definition_type() {
|
||||
// recipe::MaterialType::Bean => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.powderGram.as_i64().unwrap();
|
||||
|
||||
// check if there is mix order
|
||||
if repl
|
||||
.MixOrder
|
||||
.as_number()
|
||||
.unwrap()
|
||||
.as_i64()
|
||||
.unwrap()
|
||||
.eq(&0i64)
|
||||
{
|
||||
// add to blender index
|
||||
add_more_to_blender = repl.waterYield.as_i64().unwrap();
|
||||
}
|
||||
}
|
||||
recipe::MaterialType::Syrup => {
|
||||
// debug
|
||||
println!(
|
||||
"SYRUP [{}]: {} --> {} = {:?}",
|
||||
mr.1.productCode.clone(),
|
||||
header_idx,
|
||||
repl.materialPathId.clone(),
|
||||
repl.syrupGram
|
||||
);
|
||||
// // check if there is mix order
|
||||
// if repl
|
||||
// .MixOrder
|
||||
// .as_number()
|
||||
// .unwrap()
|
||||
// .as_i64()
|
||||
// .unwrap()
|
||||
// .eq(&0i64)
|
||||
// {
|
||||
// // add to blender index
|
||||
// add_more_to_blender = repl.waterYield.as_i64().unwrap();
|
||||
// }
|
||||
// }
|
||||
// recipe::MaterialType::Syrup => {
|
||||
// // debug
|
||||
// println!(
|
||||
// "SYRUP [{}]: {} --> {} = {:?}",
|
||||
// mr.1.productCode.clone(),
|
||||
// header_idx,
|
||||
// repl.materialPathId.clone(),
|
||||
// repl.syrupGram
|
||||
// );
|
||||
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.syrupGram.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Soda => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.syrupGram.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Powder => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.powderGram.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Water => todo!(),
|
||||
recipe::MaterialType::Ice => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.waterCold.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Cup => {
|
||||
recipe_brew_values_only[header_idx] += 1;
|
||||
}
|
||||
recipe::MaterialType::Lid => {}
|
||||
recipe::MaterialType::Straw => {}
|
||||
recipe::MaterialType::Whipper => {
|
||||
let water_yield = repl.waterYield.as_i64().unwrap();
|
||||
let water_cold = repl.waterCold.as_i64().unwrap();
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.syrupGram.as_i64().unwrap();
|
||||
// }
|
||||
// recipe::MaterialType::Soda => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.syrupGram.as_i64().unwrap();
|
||||
// }
|
||||
// recipe::MaterialType::Powder => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.powderGram.as_i64().unwrap();
|
||||
// }
|
||||
// recipe::MaterialType::Water => todo!(),
|
||||
// recipe::MaterialType::Ice => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.waterCold.as_i64().unwrap();
|
||||
// }
|
||||
// recipe::MaterialType::Cup => {
|
||||
// recipe_brew_values_only[header_idx] += 1;
|
||||
// }
|
||||
// recipe::MaterialType::Lid => {}
|
||||
// recipe::MaterialType::Straw => {}
|
||||
// recipe::MaterialType::Whipper => {
|
||||
// let water_yield = repl.waterYield.as_i64().unwrap();
|
||||
// let water_cold = repl.waterCold.as_i64().unwrap();
|
||||
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
water_yield + water_cold;
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// water_yield + water_cold;
|
||||
|
||||
if add_more_to_blender > 0i64 {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
add_more_to_blender;
|
||||
add_more_to_blender = 0i64;
|
||||
}
|
||||
}
|
||||
recipe::MaterialType::Leaves => {}
|
||||
recipe::MaterialType::Clean => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.waterYield.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::CleanV2 => {
|
||||
recipe_brew_values_only[header_idx] +=
|
||||
repl.waterYield.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Unknown => {
|
||||
recipe_brew_values_only[header_idx] += 0i64;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// suspect new mat or not found
|
||||
debug!("mat error [NotFound/Unknown] ==> {}", repl.materialPathId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// if add_more_to_blender > 0i64 {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// add_more_to_blender;
|
||||
// add_more_to_blender = 0i64;
|
||||
// }
|
||||
// }
|
||||
// recipe::MaterialType::Leaves => {}
|
||||
// recipe::MaterialType::Clean => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.waterYield.as_i64().unwrap();
|
||||
// }
|
||||
// recipe::MaterialType::CleanV2 => {
|
||||
// recipe_brew_values_only[header_idx] +=
|
||||
// repl.waterYield.as_i64().unwrap();
|
||||
// }
|
||||
// _ => {
|
||||
// recipe_brew_values_only[header_idx] += 0i64;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // suspect new mat or not found
|
||||
// debug!("mat error [NotFound/Unknown] ==> {}", repl.materialPathId);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
for (vidx, val) in recipe_brew_values_only.iter().enumerate() {
|
||||
// skip first 2
|
||||
if vidx <= 1 {
|
||||
continue;
|
||||
}
|
||||
// for (vidx, val) in recipe_brew_values_only.iter().enumerate() {
|
||||
// // skip first 2
|
||||
// if vidx <= 1 {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if val > &0i64 {
|
||||
used_mats.push(val.to_string());
|
||||
} else {
|
||||
used_mats.push(String::from(""));
|
||||
}
|
||||
}
|
||||
// if val > &0i64 {
|
||||
// used_mats.push(val.to_string());
|
||||
// } else {
|
||||
// used_mats.push(String::from(""));
|
||||
// }
|
||||
// }
|
||||
|
||||
// debug!("Used Materials: \n{:?}", used_mats);
|
||||
// // debug!("Used Materials: \n{:?}", used_mats);
|
||||
|
||||
recipe_table.add_row(used_mats);
|
||||
});
|
||||
// recipe_table.add_row(used_mats);
|
||||
// });
|
||||
|
||||
// Exclusive only for SGP
|
||||
if country_name.eq_ignore_ascii_case("sgp") {
|
||||
menu_no_sugar_table.generate_save_file("./test_result/menu_no_sugar.csv");
|
||||
// // Exclusive only for SGP
|
||||
// if country_name.eq_ignore_ascii_case("sgp") {
|
||||
// menu_no_sugar_table.generate_save_file("./test_result/menu_no_sugar.csv");
|
||||
|
||||
// process: generate table for price
|
||||
sg_price_table.generate_save_file("./test_result/sg_price.csv");
|
||||
// // process: generate table for price
|
||||
// sg_price_table.generate_save_file("./test_result/sg_price.csv");
|
||||
|
||||
// process: generate table for recipe
|
||||
recipe_table.generate_save_file("./test_result/sg_recipe.csv");
|
||||
// // process: generate table for recipe
|
||||
// recipe_table.generate_save_file("./test_result/sg_recipe.csv");
|
||||
|
||||
// final process
|
||||
// // final process
|
||||
|
||||
let mut pr = PartialRecipe::default();
|
||||
pr.sync_new(modified_recipes, formatted_mat_settings.clone());
|
||||
// export file for recipe json
|
||||
pr.export("./test_result/grep_into_modified_new_recipe_for_sgp.json");
|
||||
} else {
|
||||
sg_price_table.generate_save_file("./test_result/o1_price.csv");
|
||||
// let mut pr = PartialRecipe::default();
|
||||
// pr.sync_new(modified_recipes, formatted_mat_settings.clone());
|
||||
// // export file for recipe json
|
||||
// pr.export("./test_result/grep_into_modified_new_recipe_for_sgp.json");
|
||||
// } else {
|
||||
// sg_price_table.generate_save_file("./test_result/o1_price.csv");
|
||||
|
||||
// process: generate table for recipe
|
||||
recipe_table.generate_save_file("./test_result/o1_recipe.csv");
|
||||
// // process: generate table for recipe
|
||||
// recipe_table.generate_save_file("./test_result/o1_recipe.csv");
|
||||
|
||||
// final process
|
||||
// // final process
|
||||
|
||||
let mut pr = PartialRecipe::default();
|
||||
pr.sync_new(modified_recipes, formatted_mat_settings.clone());
|
||||
// export file for recipe json
|
||||
pr.export("./test_result/grep_into_modified_new_recipe_for_o1.json");
|
||||
}
|
||||
// let mut pr = PartialRecipe::default();
|
||||
// pr.sync_new(modified_recipes, formatted_mat_settings.clone());
|
||||
// // export file for recipe json
|
||||
// pr.export("./test_result/grep_into_modified_new_recipe_for_o1.json");
|
||||
// }
|
||||
|
||||
// WIP other countries
|
||||
}
|
||||
// // WIP other countries
|
||||
// }
|
||||
|
||||
pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
|
||||
let latest_recipe =
|
||||
|
|
@ -416,6 +417,8 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
|
|||
.collect();
|
||||
let mut submenus = sub_menu_fetched.concat();
|
||||
let mut recipe_iter = latest_recipe.clone().Recipe01;
|
||||
let prefix_cc = latest_recipe.clone().get_prefix_country_code();
|
||||
|
||||
recipe_iter.append(&mut submenus);
|
||||
|
||||
recipe_iter.iter_mut().for_each(|rpl| {
|
||||
|
|
@ -474,7 +477,7 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
|
|||
.search_material_settings(current_material.to_string());
|
||||
|
||||
if let Some(mat_s) = mat_setting {
|
||||
match mat_s.clone().get_definition_type() {
|
||||
match mat_s.clone().get_definition_type(Some(prefix_cc.clone())) {
|
||||
recipe::MaterialType::Bean => {
|
||||
recipe_brewing_values_only[header_idx] +=
|
||||
repl.powderGram.as_i64().unwrap();
|
||||
|
|
@ -536,7 +539,7 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
|
|||
recipe_brewing_values_only[header_idx] +=
|
||||
repl.waterYield.as_i64().unwrap();
|
||||
}
|
||||
recipe::MaterialType::Unknown => {
|
||||
_ => {
|
||||
if rpl.productCode.clone().ends_with("0090") {
|
||||
println!(
|
||||
"UNK [{}]: {} --> {} = {:?}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue