Implementation:Evidentlyai Evidently UI Backport: Difference between revisions
Auto-imported from implementations/Evidentlyai_Evidently_UI_Backport.md |
Sync from local file |
||
| Line 187: | Line 187: | ||
* [[requires_env::Environment:Evidentlyai_Evidently_Python_Core_Environment]] | * [[requires_env::Environment:Evidentlyai_Evidently_Python_Core_Environment]] | ||
* [[Evidentlyai_Evidently_Legacy_Base_Suite]] | * [[Implementation:Evidentlyai_Evidently_Legacy_Base_Suite]] | ||
* [[Evidentlyai_Evidently_Legacy_UI_Base]] | * [[Implementation:Evidentlyai_Evidently_Legacy_UI_Base]] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:38, 27 September 2026
| Knowledge Sources | |
|---|---|
| Domains | UI, Compatibility, Metrics, Testing, Reporting |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Provides a compatibility layer that converts v2 metric results, data definitions, and snapshots into their v1 legacy equivalents, enabling the v2 reporting system to work with the legacy UI and workspace infrastructure.
Description
The UI backport module bridges the gap between Evidently's v2 metric/report system and the legacy v1 UI system. The v1 UI expects specific data structures for rendering dashboards and storing snapshots, so this module provides conversion functions and adapter classes.
Metric Result Adapters: Several adapter classes wrap v2 metric results in v1-compatible models:
MetricResultV2Adapter: Base adapter storing widget dictionariesSingleValueV1: AdaptsSingleValue(float/int/str)ByLabelValueV1: AdaptsByLabelValue(per-label values)ByLabelCountValueV1: AdaptsByLabelCountValue(per-label counts and shares)CountValueV1: AdaptsCountValue(count and share)MeanStdValueV1: AdaptsMeanStdValue(mean and standard deviation)PresetMetricValueV1: Adapts preset metric widgets
Metric Adapters: MetricV2Adapter wraps a v2 Metric as a v1 Metric and carries its fingerprint for deduplication. MetricV2PresetAdapter handles preset metrics with a simple ID. Both have corresponding renderers that extract widget information from stored results.
Test Adapters: TestV2Adapter wraps a v2 BoundTest as a v1 Test, and TestV2Parameters provides empty v1-compatible test parameters. TestsConfig stores test configuration data as a v2 metric for serialization.
Conversion Functions:
metric_result_v2_to_v1(): Converts a v2MetricResultto its v1 equivalent, dispatching by typemetric_v2_to_v1(): Wraps a v2Metricin aMetricV2Adapterdata_definition_v2_to_v1(): Converts a v2DataDefinitionto a v1DataDefinition, mapping column typessnapshot_v2_to_v1(): The main conversion function. Converts an entire v2Snapshotto a v1Snapshot, including all metrics, metric results, tests, test results, and data definitions. It also processes descriptors and handles test widget generation.
Dashboard Panel: SingleValueDashboardPanel extends DashboardPanelV2 to render single-value metric time series as line plots in the legacy dashboard.
Main function: Includes a main() function demonstrating the v2-to-v1 conversion workflow, creating demo snapshots and adding them to a workspace.
Usage
This module is used internally whenever v2 reports or snapshots need to be displayed in the legacy UI or stored in the legacy workspace. The primary entry point is snapshot_v2_to_v1(), which is called by Project.add_snapshot_async() when a v2 snapshot is provided.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/ui/backport.py
Signature
# Metric result adapters
class MetricResultV2Adapter(MetricResultV1):
widget: List[dict]
class SingleValueV1(MetricResultV2Adapter):
value: Union[float, int, str]
class ByLabelValueV1(MetricResultV2Adapter):
values: Dict[Label, Union[float, int, bool, str]]
class ByLabelCountValueV1(MetricResultV2Adapter):
counts: Dict[Label, int]
shares: Dict[Label, float]
class CountValueV1(MetricResultV2Adapter):
count: int
share: float
class MeanStdValueV1(MetricResultV2Adapter):
mean: float
std: float
# Conversion functions
def metric_result_v2_to_v1(metric_result: MetricResultV2, ignore_widget: bool = False) -> MetricResultV1: ...
def metric_v2_to_v1(metric: MetricV2) -> MetricV1: ...
def data_definition_v2_to_v1(dd: DataDefinition, reference_present: bool) -> DataDefinitionV1: ...
def snapshot_v2_to_v1(snapshot: SnapshotV2) -> SnapshotV1: ...
# Metric adapters
class MetricV2Adapter(MetricV1[MetricResultV2Adapter]):
metric: Union[MetricV2, dict]
fingerprint: Fingerprint
class MetricV2PresetAdapter(MetricV1[MetricResultV2Adapter]):
id: str
# Test adapters
class TestV2Adapter(TestV1):
test: BoundTest
# Dashboard
class SingleValueDashboardPanel(DashboardPanelV2):
metric_id: str
Import
from evidently.ui.backport import snapshot_v2_to_v1
from evidently.ui.backport import metric_result_v2_to_v1
from evidently.ui.backport import metric_v2_to_v1
from evidently.ui.backport import data_definition_v2_to_v1
from evidently.ui.backport import MetricV2Adapter, MetricV2PresetAdapter
from evidently.ui.backport import SingleValueDashboardPanel
I/O Contract
snapshot_v2_to_v1
| Parameter | Type | Description |
|---|---|---|
| snapshot | SnapshotV2 |
A v2 snapshot from the new reporting system |
| Output | Type | Description |
|---|---|---|
| return | SnapshotV1 |
A v1 snapshot compatible with the legacy UI |
metric_result_v2_to_v1
| Parameter | Type | Description |
|---|---|---|
| metric_result | MetricResultV2 |
A v2 metric result (SingleValue, ByLabelValue, etc.) |
| ignore_widget | bool |
If True, skip widget generation (default: False) |
| Output | Type | Description |
|---|---|---|
| return | MetricResultV1 |
A v1 metric result adapter with widget data |
data_definition_v2_to_v1
| Parameter | Type | Description |
|---|---|---|
| dd | DataDefinition |
V2 data definition with column type lists |
| reference_present | bool |
Whether reference data is present |
| Output | Type | Description |
|---|---|---|
| return | DataDefinitionV1 |
V1 data definition with column mapping |
Usage Examples
from evidently.ui.backport import snapshot_v2_to_v1
# Convert a v2 snapshot for legacy UI storage
from evidently.core.report import Report, Snapshot as SnapshotV2
from evidently.metrics import MeanValue
report = Report([MeanValue(column="col")])
snapshot_v2 = report.run(dataset, None)
# Convert to v1 format for legacy workspace
snapshot_v1 = snapshot_v2_to_v1(snapshot_v2)
# The v1 snapshot can now be added to a legacy workspace project
project.add_snapshot(snapshot_v1)