ruins.core
#
Submodules#
Package Contents#
Classes#
Streamlit app Config object. |
|
Main class for accessing different data sources. |
Functions#
|
|
|
Download the data archive and extract into the data folder. |
- class ruins.core.Config(path: str = None, **kwargs)#
Bases:
collections.abc.Mapping
Streamlit app Config object.
This class holds all configs needed to run the apps. It can be instantiated just like this to load default values. If a path is provided, it will load the configs from the referenced json file. Any config can be updated by passed kwargs.
This design makes the config updateable and easy to to manage. At the same time it can be persisted to the disk and even mirrored to a database if needed in the future.
- property debug#
- property story_mode#
- get_control_policy(control_name: str) str #
Get the control policy for the given control name.
- allowed policies are:
show: always show the control on the main container
hide: hide the control on the main container, but move to the expander
ignore: don’t show anything
- __iter__()#
- class ruins.core.DataManager(datapath: str = None, cache: bool = True, hot_load=False, debug: bool = False, **kwargs)#
Bases:
collections.abc.Mapping
Main class for accessing different data sources.
The DataManager holds and manages all data sources. The default behavior is to scan the specified path for files of known file extension and cache them in memory.
- Parameters:
datapath (str) – A location where the data is stored. The class will load all sources there and make them accessible through DataSource classes.
cache (bool) – Will be passed to the DataSource classes. It true, the source will only be read once and then stored in memory until the DataManager gets deconstructed.
include_mimes (dict) – A dictionary of file extensions and their corresponding DataSource. If something is not listed, the DataManager will ignore the file type. The include_mimes can be overwritten by passing filenames directly.
- from_config(datapath: str = None, cache: bool = True, hot_load: bool = False, debug: bool = False, **kwargs) None #
Initialize the DataManager from a
Config
object.
- property datasources List[DataSource] #
- _infer_from_folder() None #
Read all files from the datapath as specified on instantiation. Calls
add_source()
on each file.
- add_source(path: str, not_exists: str = 'raise') None #
Add a file as data source to the DataManager. Only if the file has an allowed file extension, it will be managed. Files of same name will be overwritten, this is also true if they had different extensions.
- resolve_class_name(cls_name: str) Type[DataSource] #
- __len__()#
Return the number of managed data sources
- __iter__()#
Iterate over all dataset names
- __getitem__(key: str) DataSource #
Return the requested datasource
- __repr__()#
Return repr(self).
- __str__()#
Return str(self).
- ruins.core.build_config(omit_dataManager: bool = False, url_params: Dict[str, List[str]] = {}, **kwargs) Tuple[ruins.core.config.Config, Union[None, ruins.core.data_manager.DataManager]] #
- ruins.core.download_data_archive(path: str = None, url: str = 'http://116.203.189.3/data.zip', DOI: str = None, if_exists: str = 'error')#
Download the data archive and extract into the data folder. If the path is None, the default path inside the repo itself is used. Then, you also need to change the datapath property of the application config. If the data folder already exists and is not empty, the function will error on default. You can pass
if_exists='prune'
to remove the existing data folder and replace it with the new one.