Expand description
Contains functions for execution of all queries relevant for heating statistics (thermal) Manages the aggregation and persistence of daily heating statistics.
This module provides a dedicated interface, SqlInterfaceHeatingStats, for handling
all SQL operations related to the heatingstats table. It is responsible for
tracking daily energy consumption, average temperatures, and heater runtime.
§Key Components
-
SqlInterfaceHeatingStatsStruct: The primary interface that holds a database connection and provides methods for all heating statistics operations. -
HeatingStatsEntryStruct: A data structure representing the aggregated statistics for a single day. It includes anupdatemethod for incrementally calculating running averages. -
new()Constructor: A critical entry point that performs “fail-fast” validation at initialization. It checks the database to ensure:- The
heatingstatstable contains noNULLvalues. - The table’s row count does not exceed the configured maximum.
- The
-
get_single_heating_stats_from_database(): Retrieves the statistics record for the current day. -
insert_heating_stats_entry(): Writes aHeatingStatsEntryto the database using anINSERT ... ON DUPLICATE KEY UPDATEquery to either create a new daily record or update an existing one.
§Design and Purpose
The main goal of this module is to provide a robust and encapsulated interface for managing the application’s historical heating data.
-
Encapsulation: All SQL logic specific to the
heatingstatstable is contained within this module, separating concerns. -
Data Integrity: The constructor’s validation logic enforces data integrity rules at startup, preventing runtime errors caused by an invalid database state.
-
Time-Based Logic: It relies on a
SqlInterfaceMidnightCalculatorTraitto determine when a day has ended, which is crucial for finalizing one day’s statistics and starting a new record.
Structs§
- Heating
Stats Entry - Holds the statistical data of heating for one day. It is filled with post-processed data from a database query which is then updated by the control application.
- SqlInterface
Heating Stats - Contains the configuration and the implementation of the SQL interface for heating.