Manager

class Manager[source]

Bases: object

Data class manages the state and operations related to the village data.

subject

Instance of Subject class.

Type:

Subject

task

Instance of Task class.

Type:

Task

training

Instance of Training class.

Type:

Training

state

Current state of the system.

Type:

State

table

Data table type.

Type:

DataTable

rfid_reader

RFID reader settings.

Type:

Active

cycle

Current cycle settings.

Type:

Cycle

info

Information settings.

Type:

Info

actions

Actions settings.

Type:

Actions

cycle_text

Text representation of the current cycle.

Type:

str

text

Current system text.

Type:

str

day

Indicates if it’s day.

Type:

bool

changing_settings

Indicates if settings are being changed.

Type:

bool

tasks

Dictionary of tasks.

Type:

dict[str, type]

errors

Error messages.

Type:

str

events

Collection of events.

Type:

Collection

sessions_summary

Collection of session summaries.

Type:

Collection

subjects

Collection of subjects.

Type:

Collection

water_calibration

Collection of water calibration data.

Type:

Collection

sound_calibration

Collection of sound calibration data.

Type:

Collection

temperatures

Collection of temperature data.

Type:

Collection

process

Thread for running tasks.

Type:

Thread

__init__() None[source]

Initializes the Manager with default settings and initializes collections.

Methods

__init__()

Initializes the Manager with default settings and initializes collections.

create_collections()

Creates and initializes data collections for events, summaries, and measurements.

create_report(hours)

Generates a report of system activity and subject status for the last N hours.

cycle_checks()

Performs daily cycle checks and logs alarms for missing detections, sessions, or syncs.

disconnect_and_save(run_mode)

Disconnects devices and saves session data.

get_both_sessions_dfs()

Retrieves both the raw session DataFrame from disk and the current in-memory session DataFrame.

get_subject_from_tag(tag)

Retrieves a subject based on their RFID tag.

hourly_checks()

Performs hourly system health checks including temperature, disk space, and recent activity.

import_all_tasks()

Imports all tasks, custom classes, and functions from the configured code directory.

launch_task_auto(cam)

Launches a task in automatic mode based on training protocol.

launch_task_manual(cam)

Launches a task in manual mode.

multiple_detections(multiple)

Checks if multiple RFID tags were detected.

reset_subject_task_training()

Resets the subject, task, and training attributes to default states.

run_softcode_fuction(number)

Runs a user-defined softcode function.

run_task()

Executes the task logic and handles exceptions/errors during execution.

run_task_in_thread()

Starts the task execution in a separate thread.

save_refractory_to_subjects()

Updates the subject's next session time based on the refractory period (without full save).

save_to_sessions_summary(duration, trials, ...)

Saves a summary of the session to the sessions_summary collection.

save_to_subjects()

Updates subject data, including next session time and training settings, after a successful session.

send_heartbeat()

Sends a heartbeat signal to the healthcheck URL if configured.

update_cycle()

Updates the day/night cycle state based on current time and settings.

update_raw_session_df()

Updates and returns the raw session DataFrame from the CSV file.

update_text()

Updates the status text with current system state, subject, task, and cycle info.

create_collections() None[source]

Creates and initializes data collections for events, summaries, and measurements.

import_all_tasks() None[source]

Imports all tasks, custom classes, and functions from the configured code directory.

get_subject_from_tag(tag: str) bool[source]

Retrieves a subject based on their RFID tag.

Parameters:

tag (str) – The RFID tag string.

Returns:

True if subject found, False otherwise.

Return type:

bool

update_cycle() None[source]

Updates the day/night cycle state based on current time and settings.

update_text() None[source]

Updates the status text with current system state, subject, task, and cycle info.

multiple_detections(multiple: bool) bool[source]

Checks if multiple RFID tags were detected.

Parameters:

multiple (bool) – The multiple detection flag from the RFID reader.

Returns:

True if multiple tags detected, False otherwise.

Return type:

bool

launch_task_manual(cam: CameraBase) bool[source]

Launches a task in manual mode.

Parameters:

cam (CameraBase) – The camera instance to use.

Returns:

True if launched successfully, False otherwise.

Return type:

bool

launch_task_auto(cam: CameraBase) bool[source]

Launches a task in automatic mode based on training protocol.

Parameters:

cam (CameraBase) – The camera instance to use.

Returns:

True if launched successfully, False otherwise.

Return type:

bool

run_task_in_thread() None[source]

Starts the task execution in a separate thread.

run_task() None[source]

Executes the task logic and handles exceptions/errors during execution.

reset_subject_task_training() None[source]

Resets the subject, task, and training attributes to default states.

update_raw_session_df() pandas.DataFrame[source]

Updates and returns the raw session DataFrame from the CSV file.

Returns:

The loaded raw session data.

Return type:

pd.DataFrame

get_both_sessions_dfs() list[pandas.DataFrame][source]

Retrieves both the raw session DataFrame from disk and the current in-memory session DataFrame.

Returns:

A list containing [raw_session_df, task.session_df].

Return type:

list[pd.DataFrame]

disconnect_and_save(run_mode: str) None[source]

Disconnects devices and saves session data.

Parameters:

run_mode (str) – The mode in which the task was run (e.g., “Auto”, “Manual”).

save_to_subjects() None[source]

Updates subject data, including next session time and training settings, after a successful session.

save_refractory_to_subjects() None[source]

Updates the subject’s next session time based on the refractory period (without full save).

save_to_sessions_summary(duration: float, trials: int, water: int, settings_used_str: str) None[source]

Saves a summary of the session to the sessions_summary collection.

Parameters:
  • duration (float) – The duration of the session in seconds.

  • trials (int) – The number of trials completed.

  • water (int) – The amount of water delivered.

  • settings_used_str (str) – The settings string used for the session.

cycle_checks() None[source]

Performs daily cycle checks and logs alarms for missing detections, sessions, or syncs.

create_report(hours: int) tuple[str, list[str], list[str], list[str], bool][source]

Generates a report of system activity and subject status for the last N hours.

Parameters:

hours (int) – The number of hours to report on.

Returns:

A tuple containing the report text, list of non-detected subjects,

non-session subjects, low water subjects, and sync status boolean.

Return type:

tuple

send_heartbeat() None[source]

Sends a heartbeat signal to the healthcheck URL if configured.

hourly_checks() None[source]

Performs hourly system health checks including temperature, disk space, and recent activity.

run_softcode_fuction(number: int) None[source]

Runs a user-defined softcode function.

Parameters:

number (int) – The function index (1-based).