Skip to main content

fpm_rs/tabular/tables/
algorithm_metrics.rs

1use polars::prelude::*;
2
3use crate::{Result, reconstruction::ReconstructionTrace};
4
5/// Builds one row per algorithm-specific trace metric with stable identity columns.
6pub fn algorithm_metrics_dataframe(run_id: &str, trace: &ReconstructionTrace) -> Result<DataFrame> {
7    let length = trace.algorithm_metrics.len();
8    let mut run_ids = Vec::with_capacity(length);
9    let mut iterations = Vec::with_capacity(length);
10    let mut namespaces = Vec::with_capacity(length);
11    let mut metrics = Vec::with_capacity(length);
12    let mut values = Vec::with_capacity(length);
13    for record in &trace.algorithm_metrics {
14        run_ids.push(run_id);
15        iterations.push(record.iteration as u64);
16        namespaces.push(record.namespace.as_str());
17        metrics.push(record.metric.as_str());
18        values.push(record.value);
19    }
20    Ok(df!(
21        "run_id" => run_ids,
22        "iteration" => iterations,
23        "namespace" => namespaces,
24        "metric" => metrics,
25        "value" => values,
26    )?)
27}