try changing to latest as base instead
This commit is contained in:
parent
0cf5f63bd0
commit
2cd66711d6
2 changed files with 27 additions and 104 deletions
|
|
@ -2,98 +2,12 @@ use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterato
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::models::recipe::*;
|
||||
use crate::recipe_functions::common::{self, *};
|
||||
|
||||
/// Version 2 of `models::Recipe`, WIP
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct VersionRecipe {
|
||||
pub currentVersion: Value,
|
||||
pub knownVersions: Vec<Value>,
|
||||
pub recipesByCategory: HashMap<String, Vec<RecipeV2>>,
|
||||
}
|
||||
|
||||
impl VersionRecipe {
|
||||
// import - read all file with given format from directory and mixing them together as 1 recipe
|
||||
// pub fn create_versioning_by_country(country: &str) -> Self {
|
||||
// let mut path = String::from(get_config().get("RECIPE_DIR").unwrap());
|
||||
// path.push_str(country);
|
||||
// path.push('/');
|
||||
|
||||
// // read dir
|
||||
// let files = read_all_files_in_directory(&path.clone());
|
||||
// let expected_file_format = "coffeethai02";
|
||||
// let filtered = filter_files_by_pattern(files, expected_file_format);
|
||||
|
||||
// // create recipes vector
|
||||
// let mut recipes = Vec::new();
|
||||
// let mut known_versions = Vec::new();
|
||||
// for file in filtered {
|
||||
// // try create model
|
||||
// let mut source_path = path.clone();
|
||||
// source_path.push_str(&file);
|
||||
// let current_recipe_path = create_recipe_model_from_file(source_path);
|
||||
// known_versions.push(current_recipe_path.clone().MachineSetting.configNumber);
|
||||
// recipes.push(current_recipe_path.clone());
|
||||
// }
|
||||
|
||||
// // find current
|
||||
// //
|
||||
// let versions = grep_latest_versions(&path.clone()).unwrap();
|
||||
// let expected_version = versions.get(country).unwrap_or(&0);
|
||||
|
||||
// VersionRecipe {
|
||||
// currentVersion: serde_json::json!(format!("{}", expected_version)),
|
||||
// knownVersions: known_versions,
|
||||
// recipesByCategory: break_down_recipe_into_category(recipes),
|
||||
// }
|
||||
// }
|
||||
// export
|
||||
// export_full
|
||||
// export_full_with_history
|
||||
}
|
||||
|
||||
pub fn break_down_recipe_into_category(recipes: Vec<Recipe>) -> HashMap<String, Vec<RecipeV2>> {
|
||||
let mut result = HashMap::new();
|
||||
|
||||
// Steps
|
||||
// 1.
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Based on `models::Recipe`, this excluded some fields
|
||||
/// for more efficient serialization and deserialization.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RecipeV2 {
|
||||
pub Description: Option<String>,
|
||||
pub LastChange: Option<Value>,
|
||||
pub id: Value,
|
||||
pub isUse: bool,
|
||||
pub name: Option<String>,
|
||||
pub otherName: Option<String>,
|
||||
pub productCode: String,
|
||||
pub recipes: Vec<RecipeListWithHistory>,
|
||||
pub ToppingSet: Option<Vec<MenuToppingListWithHistory>>,
|
||||
pub total_time: Value,
|
||||
pub changeLog: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct RecipeListWithHistory {
|
||||
pub recipeList: RecipeList,
|
||||
pub history: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct MenuToppingListWithHistory {
|
||||
pub menuToppingList: MenuToppingList,
|
||||
pub history: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
use crate::recipe_functions::common::{self};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct RecipeListChange {
|
||||
|
|
@ -163,6 +77,14 @@ impl RecipeListChange {
|
|||
/// tracking diff between fields. (This does not compare other fields than Recipe01)
|
||||
pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
||||
let files = common::get_all_files_in_directory(source.as_path().to_str().unwrap());
|
||||
let known_latest_version = format!("{}/version", source.as_path().to_str().unwrap());
|
||||
let mut latest_version_string = String::new();
|
||||
std::fs::File::open(known_latest_version)
|
||||
.unwrap()
|
||||
.read_to_string(&mut latest_version_string)
|
||||
.unwrap();
|
||||
|
||||
let latest_version = latest_version_string.parse::<i64>().unwrap();
|
||||
|
||||
let mut recipes: Vec<Recipe> = files
|
||||
.par_iter()
|
||||
|
|
@ -188,21 +110,22 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
println!("recipes cnt = {}", recipes.len());
|
||||
}
|
||||
|
||||
println!(
|
||||
"first version from sorted = {:?}",
|
||||
recipes.first().unwrap().MachineSetting
|
||||
);
|
||||
|
||||
let base_version: i64 = recipes
|
||||
.first()
|
||||
.unwrap()
|
||||
.MachineSetting
|
||||
.get_config_number()
|
||||
.as_i64()
|
||||
.unwrap();
|
||||
let base_recipe = recipes.get(0).unwrap();
|
||||
let base_version: i64 = latest_version;
|
||||
let base_recipe: Vec<Recipe> = recipes
|
||||
.iter()
|
||||
.filter(|r| {
|
||||
r.MachineSetting
|
||||
.get_config_number()
|
||||
.as_i64()
|
||||
.unwrap()
|
||||
.eq(&base_version)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
shards = base_recipe
|
||||
.first()
|
||||
.unwrap()
|
||||
.Recipe01
|
||||
.par_iter()
|
||||
.map(|rp1| {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ pub fn get_config() -> HashMap<String, String> {
|
|||
}
|
||||
|
||||
pub fn create_recipe_model_from_file(path: String) -> models::recipe::Recipe {
|
||||
println!("create_recipe_model_from_file: {}", path);
|
||||
// println!("create_recipe_model_from_file: {}", path);
|
||||
let mut file = File::open(path).unwrap();
|
||||
println!("check file: {}", file.metadata().unwrap().is_file());
|
||||
// println!("check file: {}", file.metadata().unwrap().is_file());
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ pub fn get_all_files_in_directory(directory_path: &str) -> Vec<String> {
|
|||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
let npath = path.as_os_str().to_str().unwrap().to_string();
|
||||
println!("pushed {}", npath);
|
||||
// println!("pushed {}", npath);
|
||||
files.push(npath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue