Skip to content

Commit

Permalink
feat(refactor): inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Aug 13, 2024
1 parent 9a426f7 commit f6b8a01
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/inspector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::collections::HashMap;

use plotly::{Plot, Scatter};

/// Trait allowing custom behavior to be defined for logging and inspecting values.
pub trait Inspector<V> {
/// Log a value to state.
fn log(&mut self, value: V);

/// Inspect a value at a given time step.
fn inspect(&self, step: usize) -> Option<V>;

/// Save the inspector state.
fn save(&self);
}

// pub struct Plotter {
// values: Vecf64>,
// }

// impl Plotter {
// pub fn new() -> Self {
// Plotter {
// values: Vec::new(),
// }
// }
// }

// impl Inspector<f64> for Plotter {
// fn log(&mut self, value: f64) {
// self.values.push(value);
// }

// fn inspect(&self, step: usize) -> Option<f64> {
// Some(self.values[step])
// }

// fn save(&self) {
// let mut plot = Plot::new();

// let timesteps: Vec<usize> = (0..self.values.len()).collect();
// let values: Vec<f64> = timesteps.iter().map(|v| v).collect();

// let trace = Scatter::new(timesteps, values).mode(plotly::common::Mode::Markers);

// plot.add_trace(trace);
// plot.show();
// }
// }

0 comments on commit f6b8a01

Please sign in to comment.