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

Methods for safely generating new valid (unique) instances of identifiers for the current ObservationManager.

source

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.

source

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

pub fn generate_var_id( &self, dataset_id: &DatasetId, ideal_var_id: &str, start_index: Option<usize>, ) -> VarId

Generate valid VarId that’s currently not used by any variable in a particular dataset of this ObservationManager.

Assumes that dataset_id was checked beforehand.

source§

impl ObservationManager

source

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,

source

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

Creating instances of ObservationManager.

source

pub fn new_empty() -> ObservationManager

Instantiate ObservationManager with empty list of datasets.

source

pub fn from_datasets( datasets: Vec<(&str, Dataset)>, ) -> Result<ObservationManager, String>

Instantiate ObservationManager with given list of ID-dataset pairs.

source§

impl ObservationManager

Editing ObservationManager.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn set_dataset_annot( &mut self, id: &DatasetId, annot: &str, ) -> Result<(), String>

Set annotation of a dataset with given id.

source

pub fn set_dataset_annot_by_str( &mut self, id: &str, annot: &str, ) -> Result<(), String>

Set annotation of a dataset with given string id.

source

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.

source

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.

source

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.

source

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.

source

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).

source

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).

source

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).

source

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).

source

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 *.

source

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

pub fn remove_dataset(&mut self, id: &DatasetId) -> Result<(), String>

Remove the dataset with given id from this manager. Returns Err in case the id is not a valid dataset’s identifier.

source

pub fn remove_dataset_by_str(&mut self, id: &str) -> Result<(), String>

Remove the dataset with given string id from this manager. Returns Err in case the id is not a valid dataset’s identifier.

source§

impl ObservationManager

Observing the ObservationManager.

source

pub fn num_datasets(&self) -> usize

The number of datasets in this ObservationManager.

source

pub fn is_valid_dataset_id(&self, id: &DatasetId) -> bool

Check if there is a dataset with given Id.

source

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).

source

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).

source

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).

source

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).

source

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).

source

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).

source

pub fn datasets(&self) -> DatasetIterator<'_>

Return an iterator over all datasets of this model.

source

fn assert_no_dataset(&self, id: &DatasetId) -> Result<(), String>

(internal) Utility method to ensure there is no dataset with given ID yet.

source

fn assert_valid_dataset(&self, id: &DatasetId) -> Result<(), String>

(internal) Utility method to ensure there is a dataset with given ID.

source§

impl ObservationManager

Implementation for events related to modifying datasets.

source

pub(super) fn event_add_dataset( &mut self, event: &Event, ) -> Result<Consumed, DynError>

Perform event of adding a new dataset to this ObservationManager.

source

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.

source

pub(super) fn event_load_dataset( &mut self, event: &Event, ) -> Result<Consumed, DynError>

Perform event of loading (and adding) new dataset to this ObservationManager.

source

pub(super) fn event_modify_dataset( &mut self, event: &Event, at_path: &[&str], dataset_id: DatasetId, ) -> Result<Consumed, DynError>

Perform event of modifying or removing existing dataset component of this ObservationManager.

Trait Implementations§

source§

impl Clone for ObservationManager

source§

fn clone(&self) -> ObservationManager

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ObservationManager

source§

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

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

impl Default for ObservationManager

source§

fn default() -> ObservationManager

Default manager instance with no datasets.

source§

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
where T: FromStr, <T as FromStr>::Err: Debug,

Generate an ID of type T for a certain component of a manager (e.g., generate a VariableId for a Variable in a ModelState). Read more
source§

fn assert_ids_unique_and_used<T>( &self, id_list: &Vec<&str>, assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
where T: Eq + Hash + Debug + FromStr, <T as FromStr>::Err: Debug,

Check that the list of (typesafe or string) IDs contains only unique IDs (no duplicates), and check that all of the IDs are already managed by the manager instance (this is important, for instance, when we need to change already existing elements). Read more
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>
where T: Eq + Hash + Debug + FromStr, <T as FromStr>::Err: Debug,

Check that the list of (typesafe or string) IDs contains only unique IDs (no duplicates), and check that all of the IDs are NOT yet managed by the manager instance, i.e., they are fresh new values (this is important, for instance, when we need to add several new elements). Read more
source§

impl PartialEq for ObservationManager

source§

fn eq(&self, other: &ObservationManager) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl SessionHelper for ObservationManager

source§

fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>

A utility function which checks if 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

A utility function which checks if at_path is exactly
source§

fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>

A utility function which emits a generic “invalid path” error.
source§

fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>

A utility function which emits a “invalid path” error mentioning specific state’s component.
source§

fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>

A utility function to get and clone a payload of an event. Errors if payload is empty. Read more
source§

fn assert_path_length( path: &[&str], length: usize, component: &str, ) -> Result<(), DynError>

A utility function to assert that path has a given length, or emit a DynError otherwise. Read more
source§

fn assert_payload_empty(event: &Event, component: &str) -> Result<(), DynError>

A utility function to assert that payload is empty - otherwise, DynError is emitted. Read more
source§

impl SessionState for ObservationManager

source§

fn perform_event( &mut self, event: &Event, at_path: &[&str], ) -> Result<Consumed, DynError>

Modify the session state using the provided event. The possible outcomes are described by Consumed.
source§

fn refresh( &self, full_path: &[String], at_path: &[&str], ) -> Result<Event, DynError>

“Read” session state into an event without modifying it.
source§

impl StructuralPartialEq for ObservationManager

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

§

impl<T> UserEvent for T
where T: Debug + Clone + Send + 'static,