pub struct ObservationManager {
datasets: HashMap<DatasetId, Dataset>,
}
Expand description
Class to manage all observations and datasets.
ObservationManager
can be managed through its classical Rust API, as well as
through the external events (as it implements the SessionState
event).
Fields§
§datasets: HashMap<DatasetId, Dataset>
Implementations§
source§impl ObservationManager
impl ObservationManager
Methods for safely generating new valid (unique) instances of identifiers for
the current ObservationManager
.
sourcepub fn generate_dataset_id(
&self,
ideal_id: &str,
start_index: Option<usize>,
) -> DatasetId
pub fn generate_dataset_id( &self, ideal_id: &str, start_index: Option<usize>, ) -> DatasetId
Generate valid DatasetId
that’s currently not used by any dataset in this
ObservationManager
.
First, the given ideal_id
or its transformation by replacing invalid characters are tried.
If they are both invalid (non-unique), a numerical identifier is added at the end.
By specifying start_index
, the index search starts directly at that number (e.g., when
ideal ID is “d” and start index is 3, search for ID starts with “d_3”, “d_4”, …)
Warning: Do not use this to pre-generate more than one id at a time, as the process is deterministic and might generate the same IDs. Always generate an Id, add that dataset, and then repeat for other datasets.
sourcepub fn generate_obs_id(
&self,
dataset_id: &DatasetId,
ideal_obs_id: &str,
start_index: Option<usize>,
) -> ObservationId
pub fn generate_obs_id( &self, dataset_id: &DatasetId, ideal_obs_id: &str, start_index: Option<usize>, ) -> ObservationId
Generate valid ObservationId
that’s currently not used by any observation in a
particular dataset of this ObservationManager
.
For more, see super::Dataset::generate_obs_id.
Assumes that dataset_id
was checked beforehand.
source§impl ObservationManager
impl ObservationManager
sourcepub fn load_dataset(name: &str, csv_path: &str) -> Result<Dataset, String>
pub fn load_dataset(name: &str, csv_path: &str) -> Result<Dataset, String>
Load a dataset from given CSV file. The header line specifies variables, following lines represent individual observations (id and values).
The resulting dataset has empty annotation string (same for all its observations).
For example, the following might be a valid CSV file for a dataset with 2 observations: ID,YOX1,CLN3,YHP1,ACE2,SWI5,MBF Observation1,0,1,0,1,0,1 Observation2,1,0,,1,0,
sourcepub fn load_and_add_dataset(
&mut self,
csv_path: &str,
id: &str,
) -> Result<(), String>
pub fn load_and_add_dataset( &mut self, csv_path: &str, id: &str, ) -> Result<(), String>
Load a dataset from given CSV file, and add it to this ObservationManager
. The header
line specifies variables, following lines represent individual observations (id and values).
See Self::load_dataset for details.
source§impl ObservationManager
impl ObservationManager
Creating instances of ObservationManager
.
sourcepub fn new_empty() -> ObservationManager
pub fn new_empty() -> ObservationManager
Instantiate ObservationManager
with empty list of datasets.
sourcepub fn from_datasets(
datasets: Vec<(&str, Dataset)>,
) -> Result<ObservationManager, String>
pub fn from_datasets( datasets: Vec<(&str, Dataset)>, ) -> Result<ObservationManager, String>
Instantiate ObservationManager
with given list of ID-dataset pairs.
source§impl ObservationManager
impl ObservationManager
Editing ObservationManager
.
sourcepub fn add_dataset(
&mut self,
id: DatasetId,
dataset: Dataset,
) -> Result<(), String>
pub fn add_dataset( &mut self, id: DatasetId, dataset: Dataset, ) -> Result<(), String>
Add a new dataset with given id
to this ObservationManager
.
The ID must be valid identifier that is not already used by some other dataset.
Returns Err
in case the id
is already being used.
sourcepub fn add_dataset_by_str(
&mut self,
id: &str,
dataset: Dataset,
) -> Result<(), String>
pub fn add_dataset_by_str( &mut self, id: &str, dataset: Dataset, ) -> Result<(), String>
Add a new dataset with given string id
to this ObservationManager
.
The ID must be valid identifier that is not already used by some other dataset.
Returns Err
in case the id
is already being used.
sourcepub fn add_multiple_datasets(
&mut self,
id_name_pairs: Vec<(&str, Dataset)>,
) -> Result<(), String>
pub fn add_multiple_datasets( &mut self, id_name_pairs: Vec<(&str, Dataset)>, ) -> Result<(), String>
Shorthand to add a list of new datasets with given string IDs to this manager.
The ID must be valid identifier that is not already used by some other dataset.
Returns Err
in case the id
is already being used.
sourcepub fn swap_dataset_content(
&mut self,
id: &DatasetId,
new_content: Dataset,
) -> Result<(), String>
pub fn swap_dataset_content( &mut self, id: &DatasetId, new_content: Dataset, ) -> Result<(), String>
Swap content of a dataset with given id
. The ID must be valid identifier.
sourcepub fn swap_dataset_content_by_str(
&mut self,
id: &str,
new_content: Dataset,
) -> Result<(), String>
pub fn swap_dataset_content_by_str( &mut self, id: &str, new_content: Dataset, ) -> Result<(), String>
Swap content of a dataset with given id
. The ID must be valid identifier.
sourcepub fn set_dataset_name(
&mut self,
id: &DatasetId,
name: &str,
) -> Result<(), String>
pub fn set_dataset_name( &mut self, id: &DatasetId, name: &str, ) -> Result<(), String>
Set name of a dataset with given id. The name must be valid name string.
sourcepub fn set_dataset_name_by_str(
&mut self,
id: &str,
name: &str,
) -> Result<(), String>
pub fn set_dataset_name_by_str( &mut self, id: &str, name: &str, ) -> Result<(), String>
Set name of a dataset with given string id. The name must be valid name string.
sourcepub fn set_dataset_annot(
&mut self,
id: &DatasetId,
annot: &str,
) -> Result<(), String>
pub fn set_dataset_annot( &mut self, id: &DatasetId, annot: &str, ) -> Result<(), String>
Set annotation of a dataset with given id.
sourcepub fn set_dataset_annot_by_str(
&mut self,
id: &str,
annot: &str,
) -> Result<(), String>
pub fn set_dataset_annot_by_str( &mut self, id: &str, annot: &str, ) -> Result<(), String>
Set annotation of a dataset with given string id.
sourcepub fn set_dataset_id(
&mut self,
original_id: &DatasetId,
new_id: DatasetId,
) -> Result<(), String>
pub fn set_dataset_id( &mut self, original_id: &DatasetId, new_id: DatasetId, ) -> Result<(), String>
Set the id of dataset with original_id
to new_id
.
sourcepub fn set_dataset_id_by_str(
&mut self,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_dataset_id_by_str( &mut self, original_id: &str, new_id: &str, ) -> Result<(), String>
Set the id of dataset with original_id
to new_id
.
sourcepub fn set_var_id(
&mut self,
dataset_id: &DatasetId,
original_id: &VarId,
new_id: VarId,
) -> Result<(), String>
pub fn set_var_id( &mut self, dataset_id: &DatasetId, original_id: &VarId, new_id: VarId, ) -> Result<(), String>
Set the id of a variable with original_id
(in a given dataset) to new_id
.
sourcepub fn set_var_id_by_str(
&mut self,
dataset_id: &str,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_var_id_by_str( &mut self, dataset_id: &str, original_id: &str, new_id: &str, ) -> Result<(), String>
Set the id of a variable with original_id
(in a given dataset) to new_id
.
sourcepub fn set_all_variables(
&mut self,
dataset_id: &DatasetId,
new_variables_list: Vec<VarId>,
) -> Result<(), String>
pub fn set_all_variables( &mut self, dataset_id: &DatasetId, new_variables_list: Vec<VarId>, ) -> Result<(), String>
Set the list of all variable IDs (in a given dataset), essentially renaming some/all of them. The length of the new list must be the same as existing one (only renaming, not adding/removing variables).
sourcepub fn set_all_variables_by_str(
&mut self,
dataset_id: &str,
new_variables_list: Vec<&str>,
) -> Result<(), String>
pub fn set_all_variables_by_str( &mut self, dataset_id: &str, new_variables_list: Vec<&str>, ) -> Result<(), String>
Set the list of all variable IDs (in a given dataset), essentially renaming some/all of them. The length of the new list must be the same as existing one (only renaming, not adding/removing variables).
sourcepub fn remove_var(
&mut self,
dataset_id: &DatasetId,
var_id: &VarId,
) -> Result<(), String>
pub fn remove_var( &mut self, dataset_id: &DatasetId, var_id: &VarId, ) -> Result<(), String>
Remove variable and all the values corresponding to it from a dataset (decrementing dimension of the dataset in process).
sourcepub fn remove_var_by_str(
&mut self,
dataset_id: &str,
id: &str,
) -> Result<(), String>
pub fn remove_var_by_str( &mut self, dataset_id: &str, id: &str, ) -> Result<(), String>
Remove variable and all the values corresponding to it from a dataset (decrementing dimension of the dataset in process).
sourcepub fn add_var(
&mut self,
dataset_id: &DatasetId,
var_id: VarId,
) -> Result<(), String>
pub fn add_var( &mut self, dataset_id: &DatasetId, var_id: VarId, ) -> Result<(), String>
Add variable column and fill all its values (in each existing observation) with *.
sourcepub fn add_var_by_str(
&mut self,
dataset_id: &str,
id: &str,
) -> Result<(), String>
pub fn add_var_by_str( &mut self, dataset_id: &str, id: &str, ) -> Result<(), String>
Add variable column and fill all its values (in each existing observation) with *.
source§impl ObservationManager
impl ObservationManager
Observing the ObservationManager
.
sourcepub fn num_datasets(&self) -> usize
pub fn num_datasets(&self) -> usize
The number of datasets in this ObservationManager
.
sourcepub fn is_valid_dataset_id(&self, id: &DatasetId) -> bool
pub fn is_valid_dataset_id(&self, id: &DatasetId) -> bool
Check if there is a dataset with given Id.
sourcepub fn get_dataset_id(&self, id: &str) -> Result<DatasetId, String>
pub fn get_dataset_id(&self, id: &str) -> Result<DatasetId, String>
Return a valid dataset’s DatasetId
corresponding to the given str id
.
Return Err
if such dataset does not exist (and the ID is invalid).
sourcepub fn get_dataset(&self, id: &DatasetId) -> Result<&Dataset, String>
pub fn get_dataset(&self, id: &DatasetId) -> Result<&Dataset, String>
Return a Dataset
corresponding to a given DatasetId
.
Return Err
if such dataset does not exist (the ID is invalid in this context).
sourcepub fn get_dataset_by_str(&self, id: &str) -> Result<&Dataset, String>
pub fn get_dataset_by_str(&self, id: &str) -> Result<&Dataset, String>
Return a Dataset
corresponding to a given id given as string.
Return Err
if such dataset does not exist (the ID is invalid in this context).
sourcepub fn get_obs_id(
&self,
dataset_id: &str,
obs_id: &str,
) -> Result<ObservationId, String>
pub fn get_obs_id( &self, dataset_id: &str, obs_id: &str, ) -> Result<ObservationId, String>
Shorthand to get ObservationId
from a specified dataset.
Return Err
if such dataset does not exist (the ID is invalid in this context).
sourcepub fn get_obs(
&self,
dataset_id: &DatasetId,
obs_id: &ObservationId,
) -> Result<&Observation, String>
pub fn get_obs( &self, dataset_id: &DatasetId, obs_id: &ObservationId, ) -> Result<&Observation, String>
Shorthand to get Observation
with a given id, from a specified dataset.
Return Err
if such dataset does not exist (the ID is invalid in this context).
sourcepub fn get_obs_by_str(
&self,
dataset_id: &str,
obs_id: &str,
) -> Result<&Observation, String>
pub fn get_obs_by_str( &self, dataset_id: &str, obs_id: &str, ) -> Result<&Observation, String>
Shorthand to get Observation
with a given string id, from a specified dataset.
Return Err
if such dataset (or observation) does not exist (the ID is invalid
in this context).
sourcepub fn datasets(&self) -> DatasetIterator<'_>
pub fn datasets(&self) -> DatasetIterator<'_>
Return an iterator over all datasets of this model.
source§impl ObservationManager
impl ObservationManager
Implementation for events related to modifying datasets
.
sourcepub(super) fn event_add_dataset(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_dataset( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new dataset
to this ObservationManager
.
sourcepub(super) fn event_add_default_dataset(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_default_dataset( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new DEFAULT (empty) dataset
to this ObservationsManager
.
Trait Implementations§
source§impl Clone for ObservationManager
impl Clone for ObservationManager
source§fn clone(&self) -> ObservationManager
fn clone(&self) -> ObservationManager
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ObservationManager
impl Debug for ObservationManager
source§impl Default for ObservationManager
impl Default for ObservationManager
source§fn default() -> ObservationManager
fn default() -> ObservationManager
Default manager instance with no datasets.
source§impl Manager for ObservationManager
impl Manager for ObservationManager
source§fn generate_id<T>(
&self,
ideal_id: &str,
is_taken: &dyn Fn(&Self, &T) -> bool,
num_indices: usize,
start_index: Option<usize>,
) -> T
fn generate_id<T>( &self, ideal_id: &str, is_taken: &dyn Fn(&Self, &T) -> bool, num_indices: usize, start_index: Option<usize>, ) -> T
T
for a certain component of a manager (e.g., generate a
VariableId
for a Variable
in a ModelState
). Read moresource§fn assert_ids_unique_and_used<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_used<T>( &self, id_list: &Vec<&str>, assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§fn assert_ids_unique_and_new<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_new<T>( &self, id_list: &Vec<&str>, assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§impl PartialEq for ObservationManager
impl PartialEq for ObservationManager
source§impl SessionHelper for ObservationManager
impl SessionHelper for ObservationManager
source§fn starts_with<'a, 'b>(
prefix: &str,
at_path: &'a [&'b str],
) -> Option<&'a [&'b str]>
fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>
at_path
starts with a specific first segment.
If yes, returns the remaining part of the path.source§fn matches(expected: &[&str], at_path: &[&str]) -> bool
fn matches(expected: &[&str], at_path: &[&str]) -> bool
at_path
is exactlysource§fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
source§fn invalid_path_error_specific<T>(
path: &[&str],
component: &str,
) -> Result<T, DynError>
fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>
component
.source§fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
source§impl SessionState for ObservationManager
impl SessionState for ObservationManager
impl StructuralPartialEq for ObservationManager
Auto Trait Implementations§
impl Freeze for ObservationManager
impl RefUnwindSafe for ObservationManager
impl Send for ObservationManager
impl Sync for ObservationManager
impl Unpin for ObservationManager
impl UnwindSafe for ObservationManager
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)