oca_conductor/data_set/
mod.rs1pub mod csv_data_set;
2pub mod json_data_set;
3
4use crate::errors::GenericError;
5#[cfg(feature = "transformer")]
6use crate::transformer::data_set_transformer::{OpType, Operation};
7pub use csv_data_set::CSVDataSet;
8pub use json_data_set::JSONDataSet;
9#[cfg(feature = "transformer")]
10use oca_rs::state::oca::OCA;
11use serde_json::Value;
12use std::collections::BTreeMap;
13
14erased_serde::serialize_trait_object!(DataSet);
15dyn_clone::clone_trait_object!(DataSet);
16
17pub trait DataSet: erased_serde::Serialize + dyn_clone::DynClone {
18 fn new(raw: String) -> Box<Self>
19 where
20 Self: Sized;
21 fn load(
22 &self,
23 attribute_types: BTreeMap<String, String>,
24 ) -> Result<Vec<Value>, Vec<GenericError>>;
25 #[cfg(feature = "transformer")]
26 fn transform_schema(
27 &self,
28 mappings: BTreeMap<String, String>,
29 subset_attributes_op: Option<Vec<String>>,
30 ) -> Result<Box<dyn DataSet + Sync + Send>, GenericError>;
31 #[cfg(feature = "transformer")]
32 fn transform_data(
33 &self,
34 oca: &OCA,
35 entry_code_mappings: BTreeMap<String, BTreeMap<String, String>>,
36 unit_transformation_operations: BTreeMap<String, Vec<Operation>>,
37 ) -> Result<Box<dyn DataSet + Sync + Send>, Vec<GenericError>>;
38
39 fn get_raw(&self) -> String;
40
41 #[cfg(feature = "transformer")]
42 fn calculate_value_units(&self, value: f64, operations: &[Operation]) -> f64 {
43 let mut result = value;
44 for operation in operations {
45 result = self.apply_operation(result, operation);
46 }
47
48 result
49 }
50
51 #[cfg(feature = "transformer")]
52 fn apply_operation(&self, value: f64, operation: &Operation) -> f64 {
53 match operation.op {
54 OpType::Multiply => value * operation.value,
55 OpType::Divide => value / operation.value,
56 OpType::Add => value + operation.value,
57 OpType::Subtract => value - operation.value,
58 }
59 }
60}