Skip to content

Commit

Permalink
Add metric_id property for dashboards.
Browse files Browse the repository at this point in the history
Fix future_dashboards example.
  • Loading branch information
Liraim committed Jan 8, 2025
1 parent 36c31ec commit d19454a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
31 changes: 20 additions & 11 deletions examples/future_dashboads.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-01-03T16:03:38.786175Z",
"start_time": "2025-01-03T16:03:35.972155Z"
"end_time": "2025-01-08T13:01:54.904648Z",
"start_time": "2025-01-08T13:01:51.766554Z"
}
},
"source": [
"from evidently.ui.dashboards import CounterAgg\n",
"from evidently.ui.dashboards import PanelValue\n",
"from evidently.ui.dashboards import ReportFilter\n",
"import datetime\n",
"import pandas as pd\n",
"\n",
Expand All @@ -24,16 +27,15 @@
"from evidently.future.backport import SingleValueDashboardPanel\n",
"from evidently.future.report import Report\n",
"from evidently.future.tests import lte\n",
"from evidently.ui.dashboards import DashboardPanelCounter\n",
"from evidently.ui.workspace import Workspace\n",
"\n",
"def create_snapshot(i):\n",
" df = pd.DataFrame({\"col\": list(range(i + 5))})\n",
" dataset = Dataset.from_pandas(\n",
" df,\n",
" data_definition=DataDefinition(\n",
" {\n",
" \"col\": ColumnInfo(ColumnType.Numerical),\n",
" }\n",
" numerical_features=[\"col\"],\n",
" ),\n",
" )\n",
" report = Report([MeanValue(column=\"col\", tests=[lte(4)])])\n",
Expand All @@ -55,7 +57,14 @@
"\n",
" project = ws.add_project(Project(id=ZERO_UUID, name=\"test proj\"))\n",
"\n",
" project.dashboard.add_panel(SingleValueDashboardPanel(metric_id=\"mean:col\"))\n",
" project.dashboard.add_panel(SingleValueDashboardPanel(metric_id=MeanValue(column=\"col\", tests=[lte(4)]).metric_id))\n",
" project.dashboard.add_panel(DashboardPanelCounter(\n",
" title=\"Last mean value\",\n",
" agg=CounterAgg.LAST,\n",
" value=PanelValue(field_path=\"value\", metric_args={\"metric.metric_id\": \"2e5caa9690281e02cf243c736d687782\"}),\n",
" filter=ReportFilter(metadata_values={}, tag_values=[], include_test_suites=True),\n",
" ))\n",
" # project.dashboard.add_panel(SingleValueDashboardPanel(metric_id=\"mean:col\"))\n",
" project.save()\n",
"\n",
"for i in range(10):\n",
Expand All @@ -67,17 +76,17 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-03T16:03:38.789133Z",
"start_time": "2025-01-03T16:03:38.787020Z"
"end_time": "2025-01-08T13:01:54.911704Z",
"start_time": "2025-01-08T13:01:54.908667Z"
}
},
"cell_type": "code",
"outputs": [],
"execution_count": 2,
"source": [
"# use `evidently ui` to run UI service to see project dashboard."
],
"id": "35a20fd14d577dc8"
"id": "35a20fd14d577dc8",
"outputs": [],
"execution_count": 2
}
],
"metadata": {
Expand Down
4 changes: 4 additions & 0 deletions src/evidently/future/metric_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ def to_calculation(self) -> TCalculation:
def get_metric_id(self) -> str:
return self.get_fingerprint()

@property
def metric_id(self) -> str:
return self.get_fingerprint()

def _default_tests(self) -> List[MetricTestProto[TResult]]:
"""
allows to redefine default tests for metric
Expand Down

0 comments on commit d19454a

Please sign in to comment.