Home Assistant Unofficial Reference 2024.12.1
statistics.py File Reference

Go to the source code of this file.

Classes

class  homeassistant.components.recorder.statistics.BaseStatisticsRow
 
class  homeassistant.components.recorder.statistics.PlatformCompiledStatistics
 
class  homeassistant.components.recorder.statistics.ShortTermStatisticsRunCache
 
class  homeassistant.components.recorder.statistics.StatisticsRow
 
class  homeassistant.components.recorder.statistics.ValidationIssue
 

Namespaces

 homeassistant.components.recorder.statistics
 

Functions

None homeassistant.components.recorder.statistics._adjust_sum_statistics (Session session, type[StatisticsBase] table, int metadata_id, datetime start_time, float adj)
 
None homeassistant.components.recorder.statistics._async_import_statistics (HomeAssistant hass, StatisticMetaData metadata, Iterable[StatisticData] statistics)
 
None homeassistant.components.recorder.statistics._augment_result_with_change (HomeAssistant hass, Session session, datetime start_time, dict[str, str]|None units, set[Literal["change", "last_reset", "max", "mean", "min", "state", "sum"]] _types, type[Statistics|StatisticsShortTerm] table, dict[str, tuple[int, StatisticMetaData]] metadata, dict[str, list[StatisticsRow]] result)
 
list[StatisticsRow] homeassistant.components.recorder.statistics._build_converted_stats (list[Row] db_rows, float table_duration_seconds, int start_ts_idx, tuple[tuple[str, int],...] row_mapping, Callable[[float|None], float|None]|Callable[[float], float] convert)
 
list[StatisticsRow] homeassistant.components.recorder.statistics._build_stats (list[Row] db_rows, float table_duration_seconds, int start_ts_idx, tuple[tuple[str, int],...] row_mapping)
 
list[StatisticsRow] homeassistant.components.recorder.statistics._build_sum_converted_stats (list[Row] db_rows, float table_duration_seconds, int start_ts_idx, int sum_idx, Callable[[float|None], float|None]|Callable[[float], float] convert)
 
list[StatisticsRow] homeassistant.components.recorder.statistics._build_sum_stats (list[Row] db_rows, float table_duration_seconds, int start_ts_idx, int sum_idx)
 
None homeassistant.components.recorder.statistics._change_statistics_unit_for_table (Session session, type[StatisticsBase] table, int metadata_id, Callable[[float|None], float|None] convert)
 
None homeassistant.components.recorder.statistics._compile_hourly_statistics (Session session, datetime start)
 
StatementLambdaElement homeassistant.components.recorder.statistics._compile_hourly_statistics_last_sum_stmt (float start_time_ts, float end_time_ts)
 
StatementLambdaElement homeassistant.components.recorder.statistics._compile_hourly_statistics_summary_mean_stmt (float start_time_ts, float end_time_ts)
 
set[str] homeassistant.components.recorder.statistics._compile_statistics (Recorder instance, Session session, datetime start, bool fire_events)
 
list[int] homeassistant.components.recorder.statistics._extract_metadata_and_discard_impossible_columns (dict[str, tuple[int, StatisticMetaData]] metadata, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
StatementLambdaElement homeassistant.components.recorder.statistics._find_latest_short_term_statistic_for_metadata_id_stmt (int metadata_id)
 
datetime homeassistant.components.recorder.statistics._find_month_end_time (datetime timestamp)
 
datetime|None homeassistant.components.recorder.statistics._first_statistic (Session session, type[StatisticsBase] table, int metadata_id)
 
list[dict] homeassistant.components.recorder.statistics._flatten_list_statistic_ids_metadata_result (dict[str, dict[str, Any]] result)
 
StatementLambdaElement homeassistant.components.recorder.statistics._generate_max_mean_min_statistic_in_sub_period_stmt (Select columns, datetime|None start_time, datetime|None end_time, type[StatisticsBase] table, int metadata_id)
 
StatementLambdaElement homeassistant.components.recorder.statistics._generate_select_columns_for_types_stmt (type[StatisticsBase] table, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
StatementLambdaElement homeassistant.components.recorder.statistics._generate_statistics_at_time_stmt (type[StatisticsBase] table, set[int] metadata_ids, float start_time_ts, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
StatementLambdaElement homeassistant.components.recorder.statistics._generate_statistics_during_period_stmt (datetime start_time, datetime|None end_time, list[int]|None metadata_ids, type[StatisticsBase] table, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
Callable[[float], float]|None homeassistant.components.recorder.statistics._get_display_to_statistic_unit_converter (str|None display_unit, str|None statistic_unit)
 
StatementLambdaElement homeassistant.components.recorder.statistics._get_first_id_stmt (datetime start)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._get_last_statistics (HomeAssistant hass, int number_of_stats, str statistic_id, bool convert_units, type[StatisticsBase] table, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
StatementLambdaElement homeassistant.components.recorder.statistics._get_last_statistics_short_term_stmt (int metadata_id, int number_of_stats)
 
StatementLambdaElement homeassistant.components.recorder.statistics._get_last_statistics_stmt (int metadata_id, int number_of_stats)
 
dict[str, float|None] homeassistant.components.recorder.statistics._get_max_mean_min_statistic (Session session, datetime|None head_start_time, datetime|None head_end_time, datetime|None main_start_time, datetime|None main_end_time, datetime|None tail_start_time, datetime|None tail_end_time, bool tail_only, int metadata_id, set[Literal["max", "mean", "min", "change"]] types)
 
None homeassistant.components.recorder.statistics._get_max_mean_min_statistic_in_sub_period (Session session, dict[str, float] result, datetime|None start_time, datetime|None end_time, type[StatisticsBase] table, set[Literal["max", "mean", "min", "change"]] types, int metadata_id)
 
float|None homeassistant.components.recorder.statistics._get_newest_sum_statistic (Session session, datetime|None head_start_time, datetime|None head_end_time, datetime|None main_start_time, datetime|None main_end_time, datetime|None tail_start_time, datetime|None tail_end_time, bool tail_only, int metadata_id)
 
float|None homeassistant.components.recorder.statistics._get_oldest_sum_statistic (Session session, datetime|None head_start_time, datetime|None main_start_time, datetime|None tail_start_time, datetime|None oldest_stat, datetime|None oldest_5_min_stat, bool tail_only, int metadata_id)
 
Callable[[float|None], float|None]|Callable[[float], float]|None homeassistant.components.recorder.statistics._get_statistic_to_display_unit_converter (str|None statistic_unit, str|None state_unit, dict[str, str]|None requested_units, bool allow_none=True)
 
Callable[[float|None], float|None]|None homeassistant.components.recorder.statistics._get_unit_converter (str from_unit, str to_unit)
 
bool homeassistant.components.recorder.statistics._import_statistics_with_session (Recorder instance, Session session, StatisticMetaData metadata, Iterable[StatisticData] statistics, type[StatisticsBase] table)
 
StatisticsBase|None homeassistant.components.recorder.statistics._insert_statistics (Session session, type[StatisticsBase] table, int metadata_id, StatisticData statistic)
 
datetime|None homeassistant.components.recorder.statistics._last_statistic (Session session, type[StatisticsBase] table, int metadata_id)
 
StatementLambdaElement homeassistant.components.recorder.statistics._latest_short_term_statistics_by_ids_stmt (Iterable[int] ids)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._reduce_statistics (dict[str, list[StatisticsRow]] stats, Callable[[float, float], bool] same_period, Callable[[float], tuple[float, float]] period_start_end, timedelta period, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._reduce_statistics_per_day (dict[str, list[StatisticsRow]] stats, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._reduce_statistics_per_month (dict[str, list[StatisticsRow]] stats, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._reduce_statistics_per_week (dict[str, list[StatisticsRow]] stats, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._sorted_statistics_to_dict (HomeAssistant hass, Sequence[Row[Any]] stats, set[str]|None statistic_ids, dict[str, tuple[int, StatisticMetaData]] _metadata, bool convert_units, type[StatisticsBase] table, dict[str, str]|None units, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, dict[str, Any]] homeassistant.components.recorder.statistics._statistic_by_id_from_metadata (HomeAssistant hass, dict[str, tuple[int, StatisticMetaData]] metadata)
 
Sequence[Row]|None homeassistant.components.recorder.statistics._statistics_at_time (Session session, set[int] metadata_ids, type[StatisticsBase] table, datetime start_time, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics._statistics_during_period_with_session (HomeAssistant hass, Session session, datetime start_time, datetime|None end_time, set[str]|None statistic_ids, Literal["5minute", "day", "hour", "week", "month"] period, dict[str, str]|None units, set[Literal["change", "last_reset", "max", "mean", "min", "state", "sum"]] _types)
 
int|None homeassistant.components.recorder.statistics._statistics_exists (Session session, type[StatisticsBase] table, int metadata_id, datetime start)
 
None homeassistant.components.recorder.statistics._update_statistics (Session session, type[StatisticsBase] table, int stat_id, StatisticData statistic)
 
bool homeassistant.components.recorder.statistics.adjust_statistics (Recorder instance, str statistic_id, datetime start_time, float sum_adjustment, str adjustment_unit)
 
None homeassistant.components.recorder.statistics.async_add_external_statistics (HomeAssistant hass, StatisticMetaData metadata, Iterable[StatisticData] statistics)
 
None homeassistant.components.recorder.statistics.async_change_statistics_unit (HomeAssistant hass, str statistic_id, *str new_unit_of_measurement, str old_unit_of_measurement)
 
None homeassistant.components.recorder.statistics.async_import_statistics (HomeAssistant hass, StatisticMetaData metadata, Iterable[StatisticData] statistics)
 
list[dict] homeassistant.components.recorder.statistics.async_list_statistic_ids (HomeAssistant hass, set[str]|None statistic_ids=None, Literal["mean", "sum"]|None statistic_type=None)
 
int|None homeassistant.components.recorder.statistics.cache_latest_short_term_statistic_id_for_metadata_id (ShortTermStatisticsRunCache run_cache, Session session, int metadata_id)
 
bool homeassistant.components.recorder.statistics.can_convert_units (str|None from_unit, str|None to_unit)
 
None homeassistant.components.recorder.statistics.change_statistics_unit (Recorder instance, str statistic_id, str new_unit, str old_unit)
 
bool homeassistant.components.recorder.statistics.cleanup_statistics_timestamp_migration (Recorder instance)
 
None homeassistant.components.recorder.statistics.clear_statistics (Recorder instance, list[str] statistic_ids)
 
bool homeassistant.components.recorder.statistics.compile_missing_statistics (Recorder instance)
 
bool homeassistant.components.recorder.statistics.compile_statistics (Recorder instance, datetime start, bool fire_events)
 
str|None homeassistant.components.recorder.statistics.get_display_unit (HomeAssistant hass, str statistic_id, str|None statistic_unit)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics.get_last_short_term_statistics (HomeAssistant hass, int number_of_stats, str statistic_id, bool convert_units, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics.get_last_statistics (HomeAssistant hass, int number_of_stats, str statistic_id, bool convert_units, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types)
 
list[Row] homeassistant.components.recorder.statistics.get_latest_short_term_statistics_by_ids (Session session, Iterable[int] ids)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics.get_latest_short_term_statistics_with_session (HomeAssistant hass, Session session, set[str] statistic_ids, set[Literal["last_reset", "max", "mean", "min", "state", "sum"]] types, dict[str, tuple[int, StatisticMetaData]]|None metadata=None)
 
dict[str, tuple[int, StatisticMetaData]] homeassistant.components.recorder.statistics.get_metadata (HomeAssistant hass, *set[str]|None statistic_ids=None, Literal["mean", "sum"]|None statistic_type=None, str|None statistic_source=None)
 
dict[str, tuple[int, StatisticMetaData]] homeassistant.components.recorder.statistics.get_metadata_with_session (Recorder instance, Session session, *set[str]|None statistic_ids=None, Literal["mean", "sum"]|None statistic_type=None, str|None statistic_source=None)
 
ShortTermStatisticsRunCache homeassistant.components.recorder.statistics.get_short_term_statistics_run_cache (HomeAssistant hass)
 
datetime homeassistant.components.recorder.statistics.get_start_time ()
 
bool homeassistant.components.recorder.statistics.import_statistics (Recorder instance, StatisticMetaData metadata, Iterable[StatisticData] statistics, type[StatisticsBase] table)
 
list[dict] homeassistant.components.recorder.statistics.list_statistic_ids (HomeAssistant hass, set[str]|None statistic_ids=None, Literal["mean", "sum"]|None statistic_type=None)
 
float|None homeassistant.components.recorder.statistics.mean (list[float] values)
 
( tuple[ Callable[[float, float], bool], Callable[[float], tuple[float, float]],]) homeassistant.components.recorder.statistics.reduce_day_ts_factory ()
 
( tuple[ Callable[[float, float], bool], Callable[[float], tuple[float, float]],]) homeassistant.components.recorder.statistics.reduce_month_ts_factory ()
 
( tuple[ Callable[[float, float], bool], Callable[[float], tuple[float, float]],]) homeassistant.components.recorder.statistics.reduce_week_ts_factory ()
 
list[str] homeassistant.components.recorder.statistics.split_statistic_id (str entity_id)
 
dict[str, Any] homeassistant.components.recorder.statistics.statistic_during_period (HomeAssistant hass, datetime|None start_time, datetime|None end_time, str statistic_id, set[Literal["max", "mean", "min", "change"]]|None types, dict[str, str]|None units)
 
dict[str, list[StatisticsRow]] homeassistant.components.recorder.statistics.statistics_during_period (HomeAssistant hass, datetime start_time, datetime|None end_time, set[str]|None statistic_ids, Literal["5minute", "day", "hour", "week", "month"] period, dict[str, str]|None units, set[Literal["change", "last_reset", "max", "mean", "min", "state", "sum"]] types)
 
None homeassistant.components.recorder.statistics.update_statistics_issues (HomeAssistant hass)
 
None homeassistant.components.recorder.statistics.update_statistics_metadata (Recorder instance, str statistic_id, str|None|UndefinedType new_statistic_id, str|None|UndefinedType new_unit_of_measurement)
 
bool homeassistant.components.recorder.statistics.valid_statistic_id (str statistic_id)
 
str homeassistant.components.recorder.statistics.validate_statistic_id (str value)
 
dict[str, list[ValidationIssue]] homeassistant.components.recorder.statistics.validate_statistics (HomeAssistant hass)
 

Variables

 homeassistant.components.recorder.statistics._LOGGER = logging.getLogger(__name__)
 
dictionary homeassistant.components.recorder.statistics._type_column_mapping
 
string homeassistant.components.recorder.statistics.DATA_SHORT_TERM_STATISTICS_RUN_CACHE = "recorder_short_term_statistics_run_cache"
 
tuple homeassistant.components.recorder.statistics.QUERY_STATISTICS
 
tuple homeassistant.components.recorder.statistics.QUERY_STATISTICS_SHORT_TERM
 
tuple homeassistant.components.recorder.statistics.QUERY_STATISTICS_SUMMARY_MEAN
 
tuple homeassistant.components.recorder.statistics.QUERY_STATISTICS_SUMMARY_SUM
 
dictionary homeassistant.components.recorder.statistics.UNIT_CLASSES
 
 homeassistant.components.recorder.statistics.VALID_STATISTIC_ID = re.compile(r"^(?!.+__)(?!_)[\da-z_]+(?<!_):(?!_)[\da-z_]+(?<!_)$")