climate_ref.models.diagnostic
#
Diagnostic
#
Bases: CreatedUpdatedMixin, Base
Represents a diagnostic that can be calculated
Source code in packages/climate-ref/src/climate_ref/models/diagnostic.py
enabled = mapped_column(default=True)
class-attribute
instance-attribute
#
Whether the diagnostic is enabled or not
If a diagnostic is not enabled, it will not be used for any calculations.
name = mapped_column()
class-attribute
instance-attribute
#
Long name of the diagnostic
promoted_version = mapped_column(default=1, server_default='1')
class-attribute
instance-attribute
#
Currently promoted diagnostic version for default queries.
Default query helpers filter ExecutionGroup.diagnostic_version == Diagnostic.promoted_version
so consumers see exactly one version's worth of results.
Recomputed as max(ExecutionGroup.diagnostic_version) after a new group is inserted
(see recompute_promoted_version).
provider_id = mapped_column(ForeignKey('provider.id'))
class-attribute
instance-attribute
#
The provider that provides the diagnostic
slug = mapped_column()
class-attribute
instance-attribute
#
Unique identifier for the diagnostic
This will be used to reference the diagnostic in the benchmarking process
recompute_promoted_version(diagnostic_id, session)
#
Recompute Diagnostic.promoted_version as max(ExecutionGroup.diagnostic_version).
The largest diagnostic_version seen across this diagnostic's groups
becomes the version that default queries return.
A v2 group with zero successful executions still becomes the promoted version.
This helper is called explicitly from the solver after a new ExecutionGroup is inserted.
It is not a SQLAlchemy event listener because event-driven recomputation is
harder to reason about during flush and harder to test in isolation.
If the diagnostic has no execution groups yet, promoted_version is left at its default of 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic_id
|
int
|
Primary key of the diagnostic to recompute. |
required |
session
|
Session
|
SQLAlchemy session. The caller is responsible for committing. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The newly-stored |