Skip to content

Commit

Permalink
MetricSelect test | nested fn Var
Browse files Browse the repository at this point in the history
  • Loading branch information
a-givertzman committed Oct 20, 2023
1 parent e666980 commit 141c40c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
24 changes: 18 additions & 6 deletions src/services/task/nested_function/fn_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ use super::fn_::FnInOut;
/// A container for storing FnInput by name
#[derive(Debug)]
pub struct FnInputs {
refs: HashMap<String, Rc<RefCell<Box<dyn FnInOut>>>>,
inputs: HashMap<String, Rc<RefCell<Box<dyn FnInOut>>>>,
vars: HashMap<String, Rc<RefCell<Box<dyn FnInOut>>>>,
}
impl FnInputs {
///
/// Creates new container for storing FnInput
pub fn new() -> Self {
Self {
refs: HashMap::new()
inputs: HashMap::new(),
vars: HashMap::new(),
}
}
///
/// Adding new input refeerence
pub fn add(&mut self, name: impl Into<String>, input: Rc<RefCell<Box<dyn FnInOut>>>) {
self.refs.insert(name.into(), input);
pub fn addInput(&mut self, name: impl Into<String>, input: Rc<RefCell<Box<dyn FnInOut>>>) {
self.inputs.insert(name.into(), input);
}
///
/// Adding new variable refeerence
pub fn addVar(&mut self, name: impl Into<String>, input: Rc<RefCell<Box<dyn FnInOut>>>) {
self.vars.insert(name.into(), input);
}
// ///
// /// Adding new Bool input refeerence
Expand All @@ -40,8 +47,13 @@ impl FnInputs {
// }
///
/// Returns input by it's name
pub fn get(&self, name: &str) -> Option<&Rc<RefCell<Box<dyn FnInOut>>>> {
self.refs.get(name.into())
pub fn getInput(&self, name: &str) -> Option<&Rc<RefCell<Box<dyn FnInOut>>>> {
self.inputs.get(name.into())
}
///
/// Returns variable by it's name
pub fn getVar(&self, name: &str) -> Option<&Rc<RefCell<Box<dyn FnInOut>>>> {
self.vars.get(name.into())
}
// ///
// /// Returns input::Bool by it's name
Expand Down
25 changes: 17 additions & 8 deletions src/services/task/nested_function/nested_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,48 @@ pub struct NestedFn {}
impl NestedFn {
///
/// Creates nested functions tree from it config
pub fn new(conf: &mut FnConfig, inputs: &mut FnInputs) -> Rc<RefCell<Box<dyn FnInOut>>> {
Self::function("", conf, inputs)
pub fn new(conf: &mut FnConfig, taskStuff: &mut FnInputs) -> Rc<RefCell<Box<dyn FnInOut>>> {
Self::function("", conf, taskStuff)
}
///
///
fn function(inputName: &str, conf: &mut FnConfig, inputs: &mut FnInputs) -> Rc<RefCell<Box<dyn FnInOut>>> {
fn function(inputName: &str, conf: &mut FnConfig, taskStuff: &mut FnInputs) -> Rc<RefCell<Box<dyn FnInOut>>> {
match conf.fnKind {
FnConfKind::Fn => {
match conf.name.as_str() {
"sum" => {
println!("NestedFn.function | function sum");
let name = "input1";
let conf = conf.inputs.get_mut(name).unwrap();
let input1 = Self::function(name, conf, inputs);
let input1 = Self::function(name, conf, taskStuff);
let name = "input1";
let conf = conf.inputs.get_mut(name).unwrap();
let input2 = Self::function(name, conf, inputs);
let input2 = Self::function(name, conf, taskStuff);
let func = Self::fnSum(inputName, input1, input2);
func
}
"timer" => {
println!("NestedFn.function | function timer");
let name = "input1";
let conf = conf.inputs.get_mut(name).unwrap();
let input = Self::function(name, conf, inputs);
let input = Self::function(name, conf, taskStuff);
let func = Self::fnTimer(inputName, 0.0, input, true);
func
},
_ => panic!("NestedFn.function | Unknown function name: {:?}", conf.name)
}
},
FnConfKind::Var => {
panic!("NestedFn.function | Var not implemented yet")
let varName = conf.name.clone();
let (inputConfName, inputConf) = match conf.inputs.iter_mut().next() {
Some(inputConf) => inputConf,
None => panic!("NestedFn.function | Var {:?} must have exact one input", &varName),
};
let input = Self::function(&inputConfName, inputConf, taskStuff);
taskStuff.addVar(inputName, input.clone());
println!("NestedFn.function | function input: {:?}", input);
input
// panic!("NestedFn.function | Var not implemented yet")
},
FnConfKind::Const => {
panic!("NestedFn.function | Const not implemented yet")
Expand All @@ -62,7 +71,7 @@ impl NestedFn {
FnConfPointType::Unknown => panic!("NestedFn.function | Point type required"),
};
let input = Self::fnInput(inputName, initial);
inputs.add(inputName, input.clone());
taskStuff.addInput(inputName, input.clone());
println!("NestedFn.function | function input: {:?}", input);
input
},
Expand Down

0 comments on commit 141c40c

Please sign in to comment.