juham.database

Description

Classes implementing MQTT pub-sub networks used for data transmission between IoT nodes. These classes must be derived trom base.MQtt base class.

class juham.database.JConsole(name='jconsole')[source]

Bases: JDatabase

Database interface that simply dumps the written records to stdout solely for testing and debugging purposes.

app_name = 'juham'
classmethod classattrs_from_dict(attributes)

Set class attributes from a dictionary.

classmethod classattrs_to_dict()

Convert class attributes to a dictionary.

config_folder = 'config'
copy()

Create and return a copy of the current object.

This method serializes the current object to a dictionary using the to_dict method, creates a new instance of the object’s class, and populates it with the serialized data using the from_dict method.

This method uses class identifier based instantiation (see factory method pattern) to create a new instance of the object, and ‘to_dict’ and ‘from_dict’ methods to initialize object’s state.

Returns:

A new instance of the object’s class with the same state as the original object.

Example:

john = Human("john")
john.height = 1.8
john.age = 62
clone_of_john = john.copy()
database = 'home'
debug(msg, details='')

Logs the given debug message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

deserialize_from_json(f)

Load attributes from a JSON file.

error(msg, details='')

Logs the given error message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod find_class(class_id)

Given class identifier find the registered class. If no class with the give identifier exists return None.

Parameters:

class_id (int) – class identifier

Returns:

class or null if not registered

Return type:

obj (obj)

from_dict(data_dict)

Update instance attributes from a dictionary.

classmethod get_class_id()

Return the class id of the class. Each class has an unique identifier that can be used for instantiating the class via Object.instantiate() method.

Parameters:

cls (class) – class

Return type:

str

Returns:

id (int) unique class identifier through which the class can be instantiated by factory method pattern.

classmethod get_json_file()

Generate the JSON file name based on the class name.

The file is created into users home folder.

host: str = 'https://eu-central-1-1.aws.cloud2.influxdata.com'
info(msg, details='')

Logs the given information message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod initialize_class()

Initialize the class for instantiation, if not initialized already. This method initializes the class identifier and deserializes the public attributes from the specified configuration folder.

Returns:

returns true if the class was initialized, false implies the class is already initialized in which case the method call has no effect.

Return type:

bool

classmethod instantiate(class_id)

Given class identifier create the corresponding object. This method implements so called factory method pattern.

Parameters:

class_id (int) – class identifier

Returns:

instance of the given class.

Return type:

obj (obj)

classmethod instantiate_with_param(class_id, param)

Given class identifier and one constructor argument create the corresponding object.

Parameters:
  • class_id (str | None) – class identifier

  • param (Any) – class specific constructor parameter

Returns:

instance of the given class.

Return type:

obj

classmethod is_abstract()

Check whether the class is abstract or real. Override in the derived sub-classes. The default is False.

Return type:

bool

Returns:

True (bool) if abstract

classmethod load_from_json()

Load class attributes from a JSON file.

org: str = 'juham'
classmethod parse_args()

Parse the startup arguments defined by this class.

Return type:

None

classmethod register()[source]

Register the class to the class database.

Once registered the class can be instantiated by its class identifier. Note that this method is called automatically by the system when the python loads the class. In this method sub classes should prepare themselves for instantiation by initializing their class attributes, for example.

classmethod register_class(class_id, ctor)

Register the given class identifier for identifier based instantiation . This, factory method pattern, as it is called, decouples the actual implementation from the interface. For more information see instantiate() method.

Parameters:
  • class_id (str) – class identifier

  • ctor (function) – constructor

classmethod save_to_json()

Create class configuration file, if the file does not exist yet.

serialize_to_json(f)

Serialize.

classmethod set_log(l)

Set logger.

Parameters:

l (logger) – logger object

Return type:

None

to_dict()

Convert instance attributes to a dictionary.

token: str = 'Oxj1TY_3rvpPhhpNtOjhAHgJpgDcg-uR3b3__kwC2N7PNhWvpczQoOjnkx67t-XkK7HdPR7Vh2eePHsbKx-tGA=='
warning(msg, details='')

Logs the given warning message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

write(point)[source]

Write record to database table.

@param point point to be written

class juham.database.JInflux(name='influx')[source]

Bases: JDatabase

Influx time series database version 3.

app_name = 'juham'
classmethod classattrs_from_dict(attributes)

Set class attributes from a dictionary.

classmethod classattrs_to_dict()

Convert class attributes to a dictionary.

config_folder = 'config'
copy()

Create and return a copy of the current object.

This method serializes the current object to a dictionary using the to_dict method, creates a new instance of the object’s class, and populates it with the serialized data using the from_dict method.

This method uses class identifier based instantiation (see factory method pattern) to create a new instance of the object, and ‘to_dict’ and ‘from_dict’ methods to initialize object’s state.

Returns:

A new instance of the object’s class with the same state as the original object.

Example:

john = Human("john")
john.height = 1.8
john.age = 62
clone_of_john = john.copy()
database = 'home'
debug(msg, details='')

Logs the given debug message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

deserialize_from_json(f)

Load attributes from a JSON file.

error(msg, details='')

Logs the given error message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod find_class(class_id)

Given class identifier find the registered class. If no class with the give identifier exists return None.

Parameters:

class_id (int) – class identifier

Returns:

class or null if not registered

Return type:

obj (obj)

from_dict(data_dict)

Update instance attributes from a dictionary.

classmethod get_class_id()

Return the class id of the class. Each class has an unique identifier that can be used for instantiating the class via Object.instantiate() method.

Parameters:

cls (class) – class

Return type:

str

Returns:

id (int) unique class identifier through which the class can be instantiated by factory method pattern.

classmethod get_json_file()

Generate the JSON file name based on the class name.

The file is created into users home folder.

host: str = 'https://eu-central-1-1.aws.cloud2.influxdata.com'
info(msg, details='')

Logs the given information message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod initialize_class()

Initialize the class for instantiation, if not initialized already. This method initializes the class identifier and deserializes the public attributes from the specified configuration folder.

Returns:

returns true if the class was initialized, false implies the class is already initialized in which case the method call has no effect.

Return type:

bool

classmethod instantiate(class_id)

Given class identifier create the corresponding object. This method implements so called factory method pattern.

Parameters:

class_id (int) – class identifier

Returns:

instance of the given class.

Return type:

obj (obj)

classmethod instantiate_with_param(class_id, param)

Given class identifier and one constructor argument create the corresponding object.

Parameters:
  • class_id (str | None) – class identifier

  • param (Any) – class specific constructor parameter

Returns:

instance of the given class.

Return type:

obj

classmethod is_abstract()

Check whether the class is abstract or real. Override in the derived sub-classes. The default is False.

Return type:

bool

Returns:

True (bool) if abstract

classmethod load_from_json()

Load class attributes from a JSON file.

org: str = 'juham'
classmethod parse_args()

Parse the startup arguments defined by this class.

Return type:

None

classmethod register()[source]

Register the class to the class database.

Once registered the class can be instantiated by its class identifier. Note that this method is called automatically by the system when the python loads the class. In this method sub classes should prepare themselves for instantiation by initializing their class attributes, for example.

Return type:

None

classmethod register_class(class_id, ctor)

Register the given class identifier for identifier based instantiation . This, factory method pattern, as it is called, decouples the actual implementation from the interface. For more information see instantiate() method.

Parameters:
  • class_id (str) – class identifier

  • ctor (function) – constructor

classmethod save_to_json()

Create class configuration file, if the file does not exist yet.

serialize_to_json(f)

Serialize.

classmethod set_log(l)

Set logger.

Parameters:

l (logger) – logger object

Return type:

None

to_dict()

Convert instance attributes to a dictionary.

token: str = 'Oxj1TY_3rvpPhhpNtOjhAHgJpgDcg-uR3b3__kwC2N7PNhWvpczQoOjnkx67t-XkK7HdPR7Vh2eePHsbKx-tGA=='
warning(msg, details='')

Logs the given warning message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

write(point)[source]

Write record to database table.

@param point point to be written

Return type:

None