Expand description
Contains functions for execution of all queries relevant for time-data recording (recorder) Manages all database interactions for time-series sensor and state data.
This module provides a dedicated interface, SqlInterfaceData, for handling
all SQL operations related to the main data table. It encapsulates the logic
for writing RecorderDataFrame objects, which contain a snapshot of all sensor
readings and system states at a specific point in time.
§Key Components
-
SqlInterfaceDataStruct: The primary struct that holds a database connection and provides methods for all data-logging database operations. -
new()Constructor: A critical entry point that not only creates anSqlInterfaceDatainstance but also performs essential “fail-fast” validation. At initialization, it checks whether the number of rows in thedatatable exceeds themax_rows_datalimit defined in the application configuration. This acts as a safeguard against uncontrolled table size at startup. -
write_data_frame_to_database(): The core function of this module. It takes aRecorderDataFrameand constructs a singleINSERT ... ON DUPLICATE KEY UPDATEquery. It intelligently handles optional or invalid floating-point values (e.g.,None,NaN,Infinity) by converting them toNULLbefore insertion, ensuring data integrity in the database.
§Design and Purpose
The main goal of this module is to provide a robust and encapsulated interface for persisting the application’s high-frequency time-series data.
-
Encapsulation: All SQL logic specific to the
datatable is contained within this module, separating concerns and simplifying the data logger’s responsibilities. -
Data Integrity: The constructor’s validation logic enforces the configured row limit at startup. The
write_data_frame_to_databasefunction ensures that invalid or missing data points are correctly stored asNULLin the database, preventing data corruption.
Structs§
- SqlInterface
Data - Contains the configuration and the implementation of the SQL interface for time-based data.