engagementanalytics package

Subpackages

Submodules

engagementanalytics.eventhandler module

This module defines the EventHandler class for handling detection events in the engagement analytics service.

Example usage:

from rrmsutils.models.engagementanalytics.configuration import Configuration
from engagementanalytics.eventhandler import EventHandler

# Initialize configuration
configuration = Configuration(...)

# Initialize event handler
event_handler = EventHandler(configuration)

# Start event handler
event_handler.start()

# Stop event handler
event_handler.stop()
class engagementanalytics.eventhandler.EventHandler(configuration: rrmsutils.models.engagementanalytics.configuration.Configuration, redis_host: str = 'localhost', redis_port: int = 6379, influx_url: str = 'http://localhost:8086', influx_org: str = 'Ridgerun', influx_bucket: str = 'jetson_metrics')

Bases: object

EventHandler class for handling detection events in the engagement analytics service.

The EventHandler class is responsible for:

start(configuration: rrmsutils.models.engagementanalytics.configuration.Configuration = None)

Starts the event handler.

Parameters:

configuration (Configuration, optional) – The configuration object to use. If not provided, the existing configuration will be used.

stop()

Stop the event handler.

engagementanalytics.logger module

Service Logger

class engagementanalytics.logger.CustomFormatter(format_str)

Bases: Formatter

Custom formatter for logging

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class engagementanalytics.logger.Logger

Bases: object

This class contains the methods used to configure the service logger.

LOGGER_NAME = 'engagementanalytics'
classmethod get_logger()

Get logger with the given name

Returns:

A logger object

Return type:

logging

classmethod init(log_level=20, log_file: str = None)

initialize the service logger

Parameters:
  • log_level (optional) – Logging level as in logging. Defaults to logging.INFO.

  • log_file (str, optional) – Log file path. Defaults to None.

engagementanalytics.main module

Server entry point

engagementanalytics.main.create_event_handler(configuration, args)

Tries to create an EventHandler instance periodically if it fails initially.

Parameters:
  • configuration (Configuration) – The configuration object.

  • args – Command line arguments

Returns:

The created EventHandler instance or None in case of error and no retry.

Return type:

EventHandler

engagementanalytics.main.main()

Main application

engagementanalytics.main.parse_args()

Parse arguments

engagementanalytics.main.parse_configuration(file_path: str)

Parses a JSON configuration file and validates its contents.

Parameters:

file_path (str) – The path to the JSON configuration file.

Returns:

The validated configuration object if successful, otherwise None if validation fails.

Return type:

Configuration

Raises:

Exception – If there is an error reading the file or validating the configuration.

engagementanalytics.peopleengagement module

This module provides the PeopleEngagement class, which is responsible for tracking and reporting engagement metrics of detected people. The class interacts with InfluxDB and Redis to store and retrieve engagement data.

class engagementanalytics.peopleengagement.PeopleEngagement(influx_client, influx_bucket, redis_client, configuration: rrmsutils.models.engagementanalytics.configuration.Configuration)

Bases: object

A class to handle people engagement analytics using InfluxDB and Redis.

handle_event(frame: rrmsutils.models.engagementanalytics.detection.Frame) bool

Handles an event by processing the frame data.

Parameters:

frame (Frame) – Frame containing detection data.

Returns:

True if the event was handled successfully, False otherwise.

Return type:

bool

start(configuration: rrmsutils.models.engagementanalytics.configuration.Configuration = None)

Starts the data base update and heatmap threads. This threads will keep statistics up to date in the databases.

Parameters:
  • configuration (Configuration, optional) – The configuration object to use. If not provived

  • used. (the current configuration will be)

stop()

Stops threads gracefully.

engagementanalytics.server module

Base HTTP server using Flask.

class engagementanalytics.server.Server(controllers: list, host: str = '127.0.0.1', port: int = 5053)

Bases: object

Flask server

start()

Run the server with given port.

Module contents