Skip to main content

fpm_rs/tabular/tables/
history.rs

1use polars::prelude::*;
2
3use crate::{Result, reconstruction::ReconstructionTrace};
4
5/// Builds one run-ID/objective/elapsed-time row per completed iteration.
6pub fn history_dataframe(run_id: &str, trace: &ReconstructionTrace) -> Result<DataFrame> {
7    let length = trace.iterations.len();
8    let mut run_ids = Vec::with_capacity(length);
9    let mut iterations = Vec::with_capacity(length);
10    let mut objectives = Vec::with_capacity(length);
11    let mut elapsed_seconds = Vec::with_capacity(length);
12    for record in &trace.iterations {
13        run_ids.push(run_id);
14        iterations.push(record.iteration as u64);
15        objectives.push(record.objective);
16        elapsed_seconds.push(record.elapsed_seconds);
17    }
18    Ok(df!(
19        "run_id" => run_ids,
20        "iteration" => iterations,
21        "objective" => objectives,
22        "elapsed_seconds" => elapsed_seconds,
23    )?)
24}