Skip to main content

SimulationDatabase

Struct SimulationDatabase 

Source
pub struct SimulationDatabase {
    pub records: Vec<SimulationRecord>,
    pub file_path: String,
}
Expand description

In-memory database of simulation records with CSV/JSON persistence.

Fields§

§records: Vec<SimulationRecord>

All stored simulation records.

§file_path: String

Path to the backing CSV file (informational; used by save/load helpers).

Implementations§

Source§

impl SimulationDatabase

Source

pub fn new(file_path: impl Into<String>) -> Self

Create a new, empty database associated with the given file path.

Source

pub fn add_record(&mut self, record: SimulationRecord)

Append a record to the database.

Source

pub fn find_by_id(&self, id: &str) -> Option<&SimulationRecord>

Find a record by its unique id, returning a reference or None.

Source

pub fn query_range( &self, param: &str, lo: f64, hi: f64, ) -> Vec<&SimulationRecord>

Return all records where param lies in the inclusive range [lo, hi].

Source

pub fn query_time_range(&self, t_lo: u64, t_hi: u64) -> Vec<&SimulationRecord>

Return all records whose timestamp falls in [t_lo, t_hi].

Source

pub fn delete_by_id(&mut self, id: &str) -> usize

Delete all records matching the given id. Returns the number of records removed.

Source

pub fn save_to_csv(&self) -> String

Serialize all records to a CSV string.

Format: id,timestamp,key=value;…,metakey=metaval;…

Source

pub fn load_from_csv(&mut self, s: &str)

Populate the database by parsing a CSV string produced by save_to_csv.

Clears existing records before loading.

Source

pub fn statistics(&self, param: &str) -> (f64, f64, f64)

Compute (min, max, mean) for the named parameter across all records that contain it. Returns (0.0, 0.0, 0.0) if no records match.

Source

pub fn export_json(&self) -> String

Export all records as a compact JSON string.

Source

pub fn import_json_ids(&mut self, json: &str)

Import records from a minimal JSON array string as produced by export_json. Only the id and timestamp fields are parsed in this lightweight implementation; full parameter parsing requires a proper JSON library.

Source

pub fn len(&self) -> usize

Return the total number of records.

Source

pub fn is_empty(&self) -> bool

Return true if the database holds no records.

Trait Implementations§

Source§

impl Debug for SimulationDatabase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimulationDatabase

Source§

fn default() -> SimulationDatabase

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.