models.py
1 from datetime import datetime 2 from typing import Any 3 from typing import Dict 4 from typing import List 5 from typing import Optional 6 7 import uuid6 8 9 from evidently._pydantic_compat import BaseModel 10 from evidently._pydantic_compat import Field 11 from evidently._pydantic_compat import validator 12 from evidently.legacy.core import new_id 13 from evidently.legacy.suite.base_suite import SnapshotLinks 14 from evidently.legacy.ui.type_aliases import OrgID 15 from evidently.legacy.ui.type_aliases import PanelID 16 from evidently.legacy.ui.type_aliases import ProjectID 17 from evidently.legacy.ui.type_aliases import SnapshotID 18 from evidently.legacy.ui.type_aliases import TabID 19 20 21 class DashboardTabModel(BaseModel): 22 """Model for a dashboard tab. 23 24 Represents a single tab in a dashboard configuration. Tabs organize panels 25 into logical groups for better visualization organization. 26 """ 27 28 id: TabID = Field(default_factory=uuid6.uuid7) 29 """Unique tab identifier.""" 30 title: Optional[str] 31 """Optional tab title.""" 32 panels: List[PanelID] 33 """List of panel IDs in this tab.""" 34 35 36 class PanelMetric(BaseModel): 37 """Configuration for a metric displayed in a dashboard panel. 38 39 Specifies which metric to display and how it should be rendered. Used in 40 `DashboardPanelPlot.values` to configure what metrics appear in a panel. 41 """ 42 43 legend: Optional[str] = None 44 """Optional legend text for the metric.""" 45 tags: List[str] = Field(default_factory=list) 46 """List of tags associated with the metric.""" 47 metadata: Dict[str, str] = Field(default_factory=dict) 48 """Additional metadata as key-value pairs.""" 49 metric: str 50 """Metric identifier (e.g., `"evidently:metric_v2:ColumnSummary"`).""" 51 metric_labels: Dict[str, str] = Field(default_factory=dict) 52 """Labels for metric values. Maps metric value keys to display labels.""" 53 view_params: Dict[str, Any] = Field(default_factory=dict) 54 """Parameters for customizing the metric view. Format depends on the metric type.""" 55 56 @validator("metric") 57 def metric_is_alias(cls, v): 58 if not v.startswith("evidently:metric_v2:"): 59 v = f"evidently:metric_v2:{v}" 60 return v 61 62 63 class DashboardPanelPlot(BaseModel): 64 """Model for a dashboard panel displaying metrics. 65 66 Represents a single visualization panel in a dashboard. Panels can display 67 one or more metrics using various visualization types (text, counter, line plot, etc.). 68 Use panel factory functions like `text_panel` or `bar_plot_panel` to create instances. 69 """ 70 71 id: PanelID = Field(default_factory=uuid6.uuid7) 72 """Unique panel identifier.""" 73 title: str 74 """Panel title.""" 75 subtitle: Optional[str] 76 """Optional panel subtitle.""" 77 size: Optional[str] 78 """Optional panel size specification.""" 79 values: List[PanelMetric] 80 """List of `PanelMetric` objects to display in this panel.""" 81 plot_params: Dict[str, Any] = Field(default_factory=dict) 82 """Parameters for customizing the plot visualization. Format depends on plot type (e.g., `plot_type`, `aggregation`, `is_stacked`).""" 83 84 85 class DashboardModel(BaseModel): 86 """Complete dashboard configuration. 87 88 Contains all tabs and panels that make up a project's dashboard. Used to 89 configure how metrics are organized and displayed in the UI. 90 """ 91 92 tabs: List[DashboardTabModel] 93 """List of `DashboardTabModel` objects representing dashboard tabs.""" 94 panels: List[DashboardPanelPlot] 95 """List of `DashboardPanelPlot` objects representing dashboard panels.""" 96 97 98 class ProjectModel(BaseModel): 99 """Model for an Evidently project. 100 101 Represents a project that organizes evaluations, snapshots, and datasets. 102 Projects are the top-level organizational unit in Evidently workspaces. 103 """ 104 105 id: ProjectID = Field(default_factory=new_id) 106 """Unique project identifier.""" 107 name: str 108 """Project name.""" 109 description: Optional[str] = None 110 """Optional project description.""" 111 org_id: Optional[OrgID] = None 112 """Optional organization ID (for cloud workspaces).""" 113 version: str = "2" 114 """Project version string.""" 115 116 117 class SnapshotLink(BaseModel): 118 """Link between a snapshot and a dataset. 119 120 Associates a snapshot (evaluation run) with a dataset, specifying the dataset's 121 role (reference vs current) and subtype (e.g., production, training). 122 """ 123 124 snapshot_id: SnapshotID 125 """ID of the snapshot.""" 126 dataset_type: str 127 """Type of dataset (e.g., `"reference"`, `"current"`).""" 128 dataset_subtype: str 129 """Subtype of dataset (e.g., `"production"`, `"training"`).""" 130 131 132 class SnapshotMetadataModel(BaseModel): 133 """Metadata for a snapshot (evaluation run). 134 135 Contains information about a snapshot including its ID, name, tags, timestamp, 136 and links to associated datasets. Returned when listing or querying snapshots. 137 """ 138 139 id: SnapshotID 140 """Unique snapshot identifier.""" 141 name: Optional[str] 142 """Optional snapshot name.""" 143 metadata: Dict[str, str] 144 """Additional metadata as key-value pairs.""" 145 tags: List[str] 146 """List of tags associated with the snapshot.""" 147 timestamp: datetime 148 """Timestamp when the snapshot was created.""" 149 links: SnapshotLinks 150 """Links to datasets associated with this snapshot. Maps dataset types to `SnapshotLink` objects."""