feat: add crabrl-fork to workspace and fix taxonomy loading
- Add crabrl-fork to workspace Cargo.toml - Update fiscal-xbrl-core to use local crabrl-fork - Fix SurfaceFormulaOp enum: add Divide variant - Fix SurfaceSignTransform enum: add Absolute variant - Implement divide_formula_values function for SurfaceFormulaOp::Divide - Implement Absolute sign transform handler - Fix all taxonomy_loader and related tests to pass
This commit is contained in:
@@ -571,6 +571,7 @@ fn evaluate_formula_for_period(
|
||||
match formula.op {
|
||||
SurfaceFormulaOp::Sum => sum_formula_values(&values, formula.treat_null_as_zero),
|
||||
SurfaceFormulaOp::Subtract => subtract_formula_values(&values, formula.treat_null_as_zero),
|
||||
SurfaceFormulaOp::Divide => divide_formula_values(&values, formula.treat_null_as_zero),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,6 +613,33 @@ fn subtract_formula_values(values: &[Option<f64>], treat_null_as_zero: bool) ->
|
||||
Some(left - right)
|
||||
}
|
||||
|
||||
fn divide_formula_values(values: &[Option<f64>], treat_null_as_zero: bool) -> Option<f64> {
|
||||
if values.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let left = if treat_null_as_zero {
|
||||
values[0].unwrap_or(0.0)
|
||||
} else {
|
||||
values[0]?
|
||||
};
|
||||
let right = if treat_null_as_zero {
|
||||
values[1].unwrap_or(0.0)
|
||||
} else {
|
||||
values[1]?
|
||||
};
|
||||
|
||||
if right == 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
if !treat_null_as_zero && values.iter().all(|value| value.is_none()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(left / right)
|
||||
}
|
||||
|
||||
pub fn merge_mapping_assignments(
|
||||
primary: &mut HashMap<String, MappingAssignment>,
|
||||
secondary: HashMap<String, MappingAssignment>,
|
||||
@@ -831,6 +859,7 @@ fn transform_values(
|
||||
period_id.clone(),
|
||||
match sign_transform {
|
||||
Some(SurfaceSignTransform::Invert) => value.map(|amount| -amount),
|
||||
Some(SurfaceSignTransform::Absolute) => value.map(|amount| amount.abs()),
|
||||
None => *value,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user