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: StringPath to the backing CSV file (informational; used by save/load helpers).
Implementations§
Source§impl SimulationDatabase
impl SimulationDatabase
Sourcepub fn new(file_path: impl Into<String>) -> Self
pub fn new(file_path: impl Into<String>) -> Self
Create a new, empty database associated with the given file path.
Sourcepub fn add_record(&mut self, record: SimulationRecord)
pub fn add_record(&mut self, record: SimulationRecord)
Append a record to the database.
Sourcepub fn find_by_id(&self, id: &str) -> Option<&SimulationRecord>
pub fn find_by_id(&self, id: &str) -> Option<&SimulationRecord>
Find a record by its unique id, returning a reference or None.
Sourcepub fn query_range(
&self,
param: &str,
lo: f64,
hi: f64,
) -> Vec<&SimulationRecord>
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].
Sourcepub fn query_time_range(&self, t_lo: u64, t_hi: u64) -> Vec<&SimulationRecord>
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].
Sourcepub fn delete_by_id(&mut self, id: &str) -> usize
pub fn delete_by_id(&mut self, id: &str) -> usize
Delete all records matching the given id. Returns the number of records removed.
Sourcepub fn save_to_csv(&self) -> String
pub fn save_to_csv(&self) -> String
Serialize all records to a CSV string.
Format: id,timestamp,key=value;…,metakey=metaval;…
Sourcepub fn load_from_csv(&mut self, s: &str)
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.
Sourcepub fn statistics(&self, param: &str) -> (f64, f64, f64)
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.
Sourcepub fn export_json(&self) -> String
pub fn export_json(&self) -> String
Export all records as a compact JSON string.
Sourcepub fn import_json_ids(&mut self, json: &str)
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.
Trait Implementations§
Source§impl Debug for SimulationDatabase
impl Debug for SimulationDatabase
Source§impl Default for SimulationDatabase
impl Default for SimulationDatabase
Source§fn default() -> SimulationDatabase
fn default() -> SimulationDatabase
Auto Trait Implementations§
impl Freeze for SimulationDatabase
impl RefUnwindSafe for SimulationDatabase
impl Send for SimulationDatabase
impl Sync for SimulationDatabase
impl Unpin for SimulationDatabase
impl UnsafeUnpin for SimulationDatabase
impl UnwindSafe for SimulationDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.