Skip to content

Commit

Permalink
UI~Bakend typing (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaAmega authored Jun 26, 2024
1 parent 2c2c3df commit afdbaa6
Show file tree
Hide file tree
Showing 86 changed files with 4,247 additions and 2,227 deletions.
29 changes: 29 additions & 0 deletions .github/share-actions/ui-types-from-backend/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: UI types
runs:
using: "composite"
steps:
- name: Cache UI types
id: cache-ui-types
uses: actions/cache@v4
with:
path: ui/packages/evidently-ui-lib/src/api/types/endpoints.d.ts
key: ui-types-${{ runner.os }}-${{ hashFiles('./.github/**', './src/evidently/**', '!src/evidently/ui/assets/**', '!src/evidently/nbextension/**') }}

- uses: actions/setup-python@v5
if: steps.cache-ui-types.outputs.cache-hit != 'true'
with:
python-version: "3.11"
architecture: "x64"
cache: "pip"

- name: Install Evidently
if: steps.cache-ui-types.outputs.cache-hit != 'true'
run: pip install -e .
shell: bash

- name: Caclulate types
if: steps.cache-ui-types.outputs.cache-hit != 'true'
run: |
litestar --app evidently.ui.app:litestar_app schema openapi --output evidently-openapi-schema.yml
npx openapi-typescript@6 ./evidently-openapi-schema.yml -o ui/packages/evidently-ui-lib/src/api/types/endpoints.d.ts
shell: bash
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
with:
files_yaml: |
evidently_python:
- .github/**
- src/evidently/**
- '!src/evidently/ui/assets/**'
- '!src/evidently/nbextension/**'
Expand Down Expand Up @@ -95,8 +96,7 @@ jobs:
key: cache-bikes-dataset
- name: Download test data
if: ${{ steps.cache-bikes-dataset.outputs.cache-hit != 'true' }}
run:
curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip
run: curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip

test-minimal:
name: Test on minimal requirements
Expand All @@ -123,8 +123,7 @@ jobs:
enableCrossOsArchive: true
- name: Download test data
if: ${{ steps.cache-bikes-dataset.outputs.cache-hit != 'true' }}
run:
curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip
run: curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install minimal dependencies
Expand Down Expand Up @@ -175,8 +174,7 @@ jobs:
enableCrossOsArchive: true
- name: Download test data
if: ${{ steps.cache-bikes-dataset.outputs.cache-hit != 'true' }}
run:
curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip
run: curl -k https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip -o Bike-Sharing-Dataset.zip
- name: Install package
run: pip install -e .[dev,spark,fsspec]
- name: Run Tests
Expand Down
47 changes: 39 additions & 8 deletions .github/workflows/ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ jobs:
with:
files_yaml: |
ui:
- .github/**
- ui/**
evidently_python:
- .github/**
- workspace-for-visual-testing.dvc
- src/evidently/**
- requirements.dev.txt
Expand All @@ -56,11 +58,11 @@ jobs:
echo "One or more evidently_python file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files.outputs.evidently_python_all_changed_and_modified_files }}"
ui-build:
name: UI type-check and build
ui-type-check:
name: UI type-check
runs-on: ubuntu-22.04
needs: changed_files
if: ${{ github.event.pull_request.draft == false && needs.changed_files.outputs.ui_any_modified == 'true' }}
if: ${{ github.event.pull_request.draft == false && needs.changed_files.outputs.ui_any_modified == 'true' && needs.changed_files.outputs.evidently_python_any_modified == 'true' }}

steps:
- name: ⬇️ Checkout repo
Expand All @@ -69,13 +71,25 @@ jobs:
- name: 📥 Install ui dependencies
uses: ./.github/share-actions/ui-node-pnpm-install

- name: 👌 Get types for UI
uses: ./.github/share-actions/ui-types-from-backend

- name: 🔬 Type check
working-directory: ui
run: pnpm type-check

- name: 🔧 Build
working-directory: ui
run: pnpm build
ui-deps-analyze:
name: UI deps analyze
runs-on: ubuntu-22.04
needs: changed_files
if: ${{ github.event.pull_request.draft == false && needs.changed_files.outputs.ui_any_modified == 'true' }}

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 📥 Install ui dependencies
uses: ./.github/share-actions/ui-node-pnpm-install

- name: 🔬 Analyze deps
working-directory: ui/service
Expand All @@ -88,8 +102,25 @@ jobs:
path: ui/service/vite-bundle-report
retention-days: 30

ui-build:
name: UI build
runs-on: ubuntu-22.04
needs: changed_files
if: ${{ github.event.pull_request.draft == false && needs.changed_files.outputs.ui_any_modified == 'true' }}

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 📥 Install ui dependencies
uses: ./.github/share-actions/ui-node-pnpm-install

- name: 🔧 Build
working-directory: ui
run: pnpm build

ui-test:
name: Playwright tests for Service
name: UI playwright tests
runs-on: ubuntu-22.04
needs: changed_files
if: ${{ github.event.pull_request.draft == false && needs.changed_files.outputs.evidently_python_any_modified == 'true' }}
Expand All @@ -100,7 +131,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.11"
architecture: "x64"
cache: "pip"

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ profile.json

__pycache__

evidently-openapi-schema.yml

# see .devcontainer/devcontainer.json
test-workspace
workspace-for-visual-testing
17 changes: 11 additions & 6 deletions src/evidently/model/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dataclasses
import uuid
from dataclasses import dataclass
from dataclasses import field
from enum import Enum
from typing import Any
from typing import Iterable
Expand Down Expand Up @@ -85,14 +86,18 @@ class BaseWidgetInfo:
alertsPosition: Optional[str] = None
alertStats: Optional[AlertStats] = None
params: Any = None
insights: Iterable[Insight] = ()
additionalGraphs: Iterable[Union[AdditionalGraphInfo, "BaseWidgetInfo", PlotlyGraphInfo]] = ()
alerts: Iterable[Alert] = ()
tabs: Iterable["TabInfo"] = ()
widgets: Iterable["BaseWidgetInfo"] = ()
insights: Iterable[Insight] = field(default_factory=list)
additionalGraphs: Iterable[Union[AdditionalGraphInfo, "BaseWidgetInfo", PlotlyGraphInfo]] = field(
default_factory=list
)
alerts: Iterable[Alert] = field(default_factory=list)
tabs: Iterable["TabInfo"] = field(default_factory=list)
widgets: Iterable["BaseWidgetInfo"] = field(default_factory=list)
pageSize: int = 5

def get_additional_graphs(self) -> List[Union[AdditionalGraphInfo, PlotlyGraphInfo, "BaseWidgetInfo"]]:
def get_additional_graphs(
self,
) -> List[Union[AdditionalGraphInfo, PlotlyGraphInfo, "BaseWidgetInfo"]]:
return list(self.additionalGraphs) + [
graph for widget in self.widgets for graph in widget.get_additional_graphs()
]
Expand Down
152 changes: 76 additions & 76 deletions src/evidently/nbextension/static/index.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/evidently/options/color_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

RED = "#ed0400"
GREY = "#4d4d4d"
COLOR_DISCRETE_SEQUENCE = (
COLOR_DISCRETE_SEQUENCE = [
"#ed0400",
"#0a5f38",
"#6c3461",
"#71aa34",
"#d8dcd6",
"#6b8ba4",
)
]


class ColorOptions(Option):
Expand Down Expand Up @@ -62,54 +62,54 @@ def get_reference_data_color(self):
current_data_color="#268bd2",
reference_data_color="#073642",
additional_data_color="",
color_sequence=(
color_sequence=[
"#268bd2",
"#2aa198",
"#859900",
"#b58900",
"#cb4b16",
"#dc322f",
),
],
)

KARACHI_SUNRISE_COLOR_OPTIONS = ColorOptions(
primary_color="#000000",
secondary_color="#14213d",
current_data_color="#fca311",
reference_data_color="#e5e5e5",
color_sequence=(
color_sequence=[
"#dad7cd",
"#a3b18a",
"#588157",
"#3a5a40",
"#344e41",
),
],
)

BERLIN_AUTUMN_COLOR_OPTIONS = ColorOptions(
primary_color="#3d348b",
secondary_color="#7678ed",
current_data_color="#f7b801",
reference_data_color="#f18701",
color_sequence=(
color_sequence=[
"#f35b04",
"#4e598c",
"#f9c784",
"#fcaf58",
"#ff8c42",
),
],
)

NIGHTOWL_COLOR_OPTIONS = ColorOptions(
primary_color="#003049",
secondary_color="#d62828",
current_data_color="#f77f00",
reference_data_color="#fcbf49",
color_sequence=(
color_sequence=[
"#eae2b7",
"#f08080",
"#84a59d",
"#f28482",
"#f6bd60",
),
],
)
31 changes: 23 additions & 8 deletions src/evidently/ui/api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
import datetime
import uuid
from typing import Any
from dataclasses import dataclass
from typing import Dict
from typing import List
from typing import Optional
Expand All @@ -10,6 +10,7 @@
from evidently._pydantic_compat import BaseModel
from evidently.base_metric import Metric
from evidently.model.dashboard import DashboardInfo
from evidently.model.widget import BaseWidgetInfo
from evidently.report import Report
from evidently.suite.base_suite import MetadataValueType
from evidently.test_suite import TestSuite
Expand Down Expand Up @@ -37,7 +38,6 @@ def from_metric(cls, metric: Metric):
class ReportModel(BaseModel):
id: uuid.UUID
timestamp: datetime.datetime
metrics: List[MetricModel]
metadata: Dict[str, MetadataValueType]
tags: List[str]

Expand All @@ -46,7 +46,6 @@ def from_report(cls, report: Report):
return cls(
id=report.id,
timestamp=report.timestamp,
metrics=[MetricModel.from_metric(m) for m in report._first_level_metrics],
metadata=report.metadata,
tags=report.tags,
)
Expand All @@ -56,7 +55,6 @@ def from_snapshot(cls, snapshot: SnapshotMetadata):
return cls(
id=snapshot.id,
timestamp=snapshot.timestamp,
metrics=[],
metadata=snapshot.metadata,
tags=snapshot.tags,
)
Expand All @@ -70,7 +68,12 @@ class TestSuiteModel(BaseModel):

@classmethod
def from_report(cls, report: TestSuite):
return cls(id=report.id, timestamp=report.timestamp, metadata=report.metadata, tags=report.tags)
return cls(
id=report.id,
timestamp=report.timestamp,
metadata=report.metadata,
tags=report.tags,
)

@classmethod
def from_snapshot(cls, snapshot: SnapshotMetadata):
Expand All @@ -82,9 +85,10 @@ def from_snapshot(cls, snapshot: SnapshotMetadata):
)


class DashboardInfoModel(BaseModel):
@dataclass
class DashboardInfoModel:
name: str
widgets: List[Any]
widgets: List[BaseWidgetInfo]
min_timestamp: Optional[datetime.datetime] = None
max_timestamp: Optional[datetime.datetime] = None

Expand All @@ -111,7 +115,12 @@ def from_project_with_time_range(

info = project.build_dashboard_info(timestamp_start=timestamp_start, timestamp_end=timestamp_end)

return cls(**dataclasses.asdict(info), **time_range)
return cls(
name=info.name,
widgets=info.widgets,
min_timestamp=time_range["min_timestamp"],
max_timestamp=time_range["max_timestamp"],
)


class OrgModel(BaseModel):
Expand Down Expand Up @@ -163,3 +172,9 @@ class RoleModel(BaseModel):
@classmethod
def from_role(cls, role: Role):
return RoleModel(id=role.id, name=role.name, entity_type=role.entity_type)


class Version(BaseModel):
application: str
version: str
commit: str
Loading

0 comments on commit afdbaa6

Please sign in to comment.