BF-VARIOUS - Various Functions
Ver. 2.0.0 (2023-02-22)
This module provides various classes with elementry functionalities for reuse in higher level classes. For example: logging, load/save, timer…
- class mlpro.bf.various.Loadable
Bases:
object
This abstract class adds the ability to be loadable to inherited classes.
- static load(p_path, p_filename)
Loads content from the given path and file name. If file does not exist, it returns None.
- Parameters:
file (p_path Path that contains the) –
name (p_filename File) –
- Returns:
A loaded object, if file content was loaded successfully. None otherwise.
- class mlpro.bf.various.Saveable
Bases:
object
This abstract class adds the ability to be saveable to inherited classes. The filename can be generated internally by implementing the method get_filename() or provided from outside otherwise.
- C_SUFFIX = '.pkl'
- generate_filename()
To be redefined in case of use of internal generated file names.
- Return type:
Returns an internal unique filename.
- save(p_path, p_filename=None) bool
Saves content to the given path and file name. If file name is None, a unique file name will be generated by calling method generate_filename(). If it returns False then the saving method is failed. For saving the object, the custom method _save is called. This contains a default implementation based on pickle/dill and can be redefined on demand.
- Parameters:
saved (p_path Path where file will be) –
generated) (p_filename File name (if None an internal filename will be) –
- Return type:
True, if file content was saved successfully. False otherwise.
- class mlpro.bf.various.LoadSave
-
This abstract class adds the ability to be loadable and saveable to inherited classes. The filename can be generated internally by implementing the method generate_filename() or provided from outside otherwise. See classes Loadable and Saveable for further information.
- class mlpro.bf.various.Log(p_logging=True)
Bases:
object
This class adds elementry log functionality to inherited classes.
- Parameters:
p_logging – Log level (see constants C_LOG_*). Default: Log.C_LOG_ALL
- C_TYPE = '????'
- C_NAME = '????'
- C_LOG_TYPE_I = 'I'
- C_LOG_TYPE_W = 'W'
- C_LOG_TYPE_E = 'E'
- C_LOG_TYPE_S = 'S'
- C_LOG_TYPES = ['I', 'W', 'E', 'S']
- C_COL_WARNING = '\x1b[93m'
- C_COL_ERROR = '\x1b[91m'
- C_COL_SUCCESS = '\x1b[32m'
- C_COL_RESET = '\x1b[0m'
- C_LOG_ALL = True
- C_LOG_NOTHING = False
- C_LOG_WE = 'W'
- C_LOG_E = 'E'
- C_LOG_LEVELS = [True, False, 'W', 'E']
- C_INST_MSG = True
- get_name() str
- set_name(p_name: str)
- switch_logging(p_logging)
Sets new log level.
- Parameters:
p_logging – Log level (constant C_LOG_LEVELS contains valid values)
- get_log_level()
- log(p_type, *p_args)
Writes log line to standard output in format: yyyy-mm-dd hh:mm:ss.mmmmmm [p_type C_TYPE C_NAME]: [p_args]
- Parameters:
entry (p_type type of log) –
informations (p_args log) –
- Returns:
Nothing
- class mlpro.bf.various.Timer(p_mode: int, p_lap_duration: timedelta | None = None, p_lap_limit: int = 999999)
Bases:
object
Timer class in two time modes (real/virtual) and with simple lap management.
- Parameters:
p_mode (int) – C_MODE_REAL for real time mode or C_MODE_VIRTUAL for virtual time mode
p_lap_duration (timedelta = None) – Optional duration of a single lap.
p_lap_limit (int = C_LAP_LIMIT) – Maximum number of laps until the lap counter restarts with 0
- C_MODE_REAL = 0
- C_MODE_VIRTUAL = 1
- C_LAP_LIMIT = 999999
- reset() None
Resets timer.
- Returns:
Nothing
- get_time() timedelta
- get_lap_time() timedelta
- get_lap_id()
- add_time(p_delta: timedelta)
- finish_lap() bool
Finishes the current lap. In timer mode C_MODE_REAL the remaining time until the end of the lap will be paused.
- Returns:
True, if the remaining time to the next lap was positive. False, if the timer timed out.
- class mlpro.bf.various.TStamp(p_tstamp: timedelta | None = None)
Bases:
object
This class provides elementry time stamp functionality for inherited classes.
- get_tstamp() timedelta
- set_tstamp(p_tstamp: timedelta)
- class mlpro.bf.various.ScientificObject
Bases:
object
This class provides elementary functionality for storing a scientific reference.
- C_SCIREF_TYPE_NONE = None
- C_SCIREF_TYPE_ARTICLE = 'Journal Article'
- C_SCIREF_TYPE_BOOK = 'Book'
- C_SCIREF_TYPE_ONLINE = 'Online'
- C_SCIREF_TYPE_PROCEEDINGS = 'Proceedings'
- C_SCIREF_TYPE_TECHREPORT = 'Technical Report'
- C_SCIREF_TYPE_UNPUBLISHED = 'Unpublished'
- C_SCIREF_TYPE = None
- C_SCIREF_AUTHOR = None
- C_SCIREF_TITLE = None
- C_SCIREF_JOURNAL = None
- C_SCIREF_ABSTRACT = None
- C_SCIREF_VOLUME = None
- C_SCIREF_NUMBER = None
- C_SCIREF_PAGES = None
- C_SCIREF_YEAR = None
- C_SCIREF_MONTH = None
- C_SCIREF_DAY = None
- C_SCIREF_DOI = None
- C_SCIREF_KEYWORDS = None
- C_SCIREF_ISBN = None
- C_SCIREF_SERIES = None
- C_SCIREF_PUBLISHER = None
- C_SCIREF_CITY = None
- C_SCIREF_COUNTRY = None
- C_SCIREF_URL = None
- C_SCIREF_CHAPTER = None
- C_SCIREF_BOOKTITLE = None
- C_SCIREF_INSTITUTION = None
- C_SCIREF_CONFERENCE = None
- C_SCIREF_NOTES = None
- C_SCIREF_EDITOR = None
- class mlpro.bf.various.PersonalisedStamp(p_name: str, p_id: int | None = None)
Bases:
object
This class serves as a base class of label to set up a name and id for another class.
- Parameters:
p_name (str) – name of the created class.
p_id (int) – unique id of the created class. Default: None.
- C_NAME
name of the created class. Default: ‘’.
- Type:
str
- C_NAME = ''
- set_id(p_id: int | None = None)
This method provides a functionality to set an unique ID.
- Parameters:
p_id (int, optional) – An unique ID. Default: None.
- get_id() str
This method provides a functionality to get the defined unique ID.
- Returns:
The unique ID.
- Return type:
str
- set_name(p_name: str)
This method provides a functionality to set an unique name.
- Parameters:
p_name (str) – An unique name.
- get_name() str
This method provides a functionality to get the unique name.
- Returns:
The unique name of the related component.
- Return type:
str