No description
Find a file
Pakin 8eeed983f0 Fix bug list group id wrong type
Signed-off-by: Pakin <pakin.t@forth.co.th>
2025-11-03 14:57:42 +07:00
lib update gitignore and sync_file_list doc 2025-09-09 15:19:50 +07:00
src Fix bug list group id wrong type 2025-11-03 14:57:42 +07:00
.gitignore update gitignore and sync_file_list doc 2025-09-09 15:19:50 +07:00
Cargo.lock add copy function 2025-09-10 10:25:21 +07:00
Cargo.toml add copy function 2025-09-10 10:25:21 +07:00
libfilesGuide.png add deps and some guide 2025-09-09 15:26:00 +07:00
README.md Update README.md 2025-10-16 15:56:46 +07:00

libtbr

libtbr is swiss-knife toolbox for Taobin project.

cargo add --git https://gitlab.forthrd.io/Pakin/libtbr.git
cargo update

Examples

Initialize Config

use libtbr::recipe_functions::common;

// this read file `.tbcfg` in the current directory
let cfg = common::get_config();

let recipe_dir = cfg.get("RECIPE_DIR").unwrap();

Get recipe from specific country (latest)

...
let latest_versions = grep_latest_versions(recipe_dir).unwrap();

// try get malaysia recipe, may fail if country does not exist
let mys_version = latest_versions.get("mys");
// try to create malaysia recipe model
let mys_recipe_model = common::create_recipe_model_from_file(common::create_recipe_path(
    "mys",
    *mys_version.unwrap(),
));

...

Get list of material settings

// get current material settings including empty (0)
let mut used_in_mys = mys_recipe_model.list_material_settings();
used_in_mys.push("0".to_string());

Get all recipe of expected material id

let aus_latest = common::create_recipe_model_from_file(common::create_recipe_path(
    "aus",
    *aus_version.unwrap(),
));

let prod_list = aus_latest.find_recipe_by_material_path_id("511214");

Generate google sheet style table of recipe from file

// Experimental: expect current execution path to have `./test_result` folder first, and `config.RECIPE_DIR/{country}/{version_file_format}` must exist.
import::generate_recipe_sheet_table("mys", 626);

Notes

Simple Snippet Patterns

// =============================================
//  Get current material and convert to thai id
// =============================================
let curr_rpl_mat_id = rpl.materialPathId.as_i64().unwrap_or(0);

// strip off first 2
let pure_mat_id = if curr_rpl_mat_id > 300000 {
    //
    curr_rpl_mat_id.to_string()[2..]
        .parse::<i64>()
        .expect("not a number")
} else {
    curr_rpl_mat_id
};