use crate::fabric::GeneratedEntry;
use crate::models::{SolvingMethod, TransactionFlow};
#[derive(Debug, Clone)]
pub struct TransformationConfig {
pub block_size: u32,
pub max_batch_size: u32,
pub compute_confidence: bool,
}
impl Default for TransformationConfig {
fn default() -> Self {
Self {
block_size: 256,
max_batch_size: 65536,
compute_confidence: true,
}
}
}
#[derive(Debug, Clone)]
pub struct TransformationResult {
pub flows: Vec<TransactionFlow>,
pub methods: Vec<SolvingMethod>,
pub stats: TransformationStats,
}
#[derive(Debug, Clone, Default)]
pub struct TransformationStats {
pub entries_processed: usize,
pub flows_generated: usize,
pub method_a_count: usize,
pub method_b_count: usize,
pub method_c_count: usize,
pub method_d_count: usize,
pub method_e_count: usize,
pub avg_confidence: f64,
}
pub struct TransformationKernel {
#[allow(dead_code)]
config: TransformationConfig,
}
impl TransformationKernel {
pub fn new(config: TransformationConfig) -> Self {
Self { config }
}
pub fn transform(&self, entries: &[GeneratedEntry]) -> TransformationResult {
let mut flows = Vec::new();
let mut methods = Vec::new();
let mut stats = TransformationStats::default();
for entry in entries {
for &(source_idx, target_idx, amount) in &entry.expected_flows {
let flow = TransactionFlow::new(
source_idx,
target_idx,
amount,
entry.entry.id,
entry.entry.posting_date,
);
flows.push(flow);
}
let method = entry.entry.solving_method;
methods.push(method);
match method {
SolvingMethod::MethodA => stats.method_a_count += 1,
SolvingMethod::MethodB => stats.method_b_count += 1,
SolvingMethod::MethodC => stats.method_c_count += 1,
SolvingMethod::MethodD => stats.method_d_count += 1,
SolvingMethod::MethodE => stats.method_e_count += 1,
SolvingMethod::Pending => {}
}
}
stats.entries_processed = entries.len();
stats.flows_generated = flows.len();
stats.avg_confidence = if !flows.is_empty() {
flows.iter().map(|f| f.confidence as f64).sum::<f64>() / flows.len() as f64
} else {
0.0
};
TransformationResult {
flows,
methods,
stats,
}
}
}
impl Default for TransformationKernel {
fn default() -> Self {
Self::new(TransformationConfig::default())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_transformation_kernel_creation() {
let kernel = TransformationKernel::default();
assert_eq!(kernel.config.block_size, 256);
}
}