capability_grower_configuration/
node_variant_phase_range.rs1crate::ix!();
3
4#[derive(
6 SaveLoad,Debug, Clone, PartialEq, Serialize, Deserialize, AiJsonTemplate,
7 AiJsonTemplateWithJustification,
8 Builder, Default, Getters
9)]
10#[builder(pattern="owned", setter(into))]
11#[getset(get="pub")]
12pub struct NodeVariantPhaseRange {
13 #[serde(deserialize_with = "fuzzy_u8")]
15 start_level: u8,
16 aggregator_weight: f32,
18 dispatch_weight: f32,
20 leaf_weight: f32,
22}
23
24impl FuzzyFromJsonValue for JustifiedNodeVariantPhaseRange {
25 fn fuzzy_from_json_value(value: &JsonValue)
26 -> Result<Self, FuzzyFromJsonValueError>
27 {
28 trace!("(JustifiedNodeVariantPhaseRange) Entering fuzzy_from_json_value");
29
30 if value.is_null() {
32 debug!("(JustifiedNodeVariantPhaseRange) Null => returning defaults (start_level=0, aggregator_weight=0, etc.)");
33 return Ok(Self {
34 start_level: 0,
35 start_level_confidence: 0.0,
36 start_level_justification: String::new(),
37 aggregator_weight: 0.0,
38 aggregator_weight_confidence: 0.0,
39 aggregator_weight_justification: String::new(),
40 dispatch_weight: 0.0,
41 dispatch_weight_confidence: 0.0,
42 dispatch_weight_justification: String::new(),
43 leaf_weight: 0.0,
44 leaf_weight_confidence: 0.0,
45 leaf_weight_justification: String::new(),
46 });
47 }
48
49 let mut obj = match value.as_object() {
51 Some(m) => {
52 trace!("(JustifiedNodeVariantPhaseRange) Found object => flattening if needed.");
53 m.clone()
54 }
55 None => {
56 error!("(JustifiedNodeVariantPhaseRange) Not an object => fail!");
57 return Err(FuzzyFromJsonValueError::NotAnObject {
58 target_type: "JustifiedNodeVariantPhaseRange",
59 actual: value.clone(),
60 });
61 }
62 };
63
64 flatten_all_fields(&mut obj);
65
66 trace!("(JustifiedNodeVariantPhaseRange) Parsing 'start_level' => fuzzy_u8");
68 let start_val = match obj.get("start_level") {
69 Some(x) => {
70 match fuzzy_u8(x) {
71 Ok(u) => {
72 trace!("(JustifiedNodeVariantPhaseRange) start_level => {}", u);
73 u
74 }
75 Err(e) => {
76 error!("(JustifiedNodeVariantPhaseRange) start_level parse error => {:?}", e);
77 return Err(FuzzyFromJsonValueError::Other {
78 target_type: "JustifiedNodeVariantPhaseRange",
79 detail: format!("start_level parse error: {:?}", e),
80 });
81 }
82 }
83 }
84 None => 0,
85 };
86 let start_conf = get_f64_field(&obj, "start_level_confidence", "JustifiedNodeVariantPhaseRange")
87 .unwrap_or(0.0);
88 let start_just = get_string_field(&obj, "start_level_justification", "JustifiedNodeVariantPhaseRange")
89 .unwrap_or_default();
90
91 let agg_f64 = get_f64_field(&obj, "aggregator_weight", "JustifiedNodeVariantPhaseRange")
93 .unwrap_or(0.0);
94 let aggregator_weight = agg_f64 as f32;
95 let agg_conf = get_f64_field(&obj, "aggregator_weight_confidence", "JustifiedNodeVariantPhaseRange")
96 .unwrap_or(0.0);
97 let agg_just = get_string_field(&obj, "aggregator_weight_justification", "JustifiedNodeVariantPhaseRange")
98 .unwrap_or_default();
99
100 let disp_f64 = get_f64_field(&obj, "dispatch_weight", "JustifiedNodeVariantPhaseRange")
102 .unwrap_or(0.0);
103 let dispatch_weight = disp_f64 as f32;
104 let disp_conf = get_f64_field(&obj, "dispatch_weight_confidence", "JustifiedNodeVariantPhaseRange")
105 .unwrap_or(0.0);
106 let disp_just = get_string_field(&obj, "dispatch_weight_justification", "JustifiedNodeVariantPhaseRange")
107 .unwrap_or_default();
108
109 let leaf_f64 = get_f64_field(&obj, "leaf_weight", "JustifiedNodeVariantPhaseRange")
111 .unwrap_or(0.0);
112 let leaf_weight = leaf_f64 as f32;
113 let leaf_conf = get_f64_field(&obj, "leaf_weight_confidence", "JustifiedNodeVariantPhaseRange")
114 .unwrap_or(0.0);
115 let leaf_just = get_string_field(&obj, "leaf_weight_justification", "JustifiedNodeVariantPhaseRange")
116 .unwrap_or_default();
117
118 trace!("(JustifiedNodeVariantPhaseRange) Successfully parsed => returning final struct.");
119 Ok(Self {
120 start_level: start_val,
121 start_level_confidence: start_conf,
122 start_level_justification: start_just,
123 aggregator_weight,
124 aggregator_weight_confidence: agg_conf,
125 aggregator_weight_justification: agg_just,
126 dispatch_weight,
127 dispatch_weight_confidence: disp_conf,
128 dispatch_weight_justification: disp_just,
129 leaf_weight,
130 leaf_weight_confidence: leaf_conf,
131 leaf_weight_justification: leaf_just,
132 })
133 }
134}