/ src / evidently / ui / service / api / models.py
models.py
 1  import datetime
 2  from typing import Dict
 3  from typing import List
 4  from typing import Optional
 5  
 6  from evidently._pydantic_compat import BaseModel
 7  from evidently.legacy.report import Report
 8  from evidently.legacy.suite.base_suite import MetadataValueType
 9  from evidently.legacy.suite.base_suite import SnapshotLinks
10  from evidently.sdk.models import SnapshotMetadataModel
11  from evidently.ui.service.base import Org
12  from evidently.ui.service.type_aliases import OrgID
13  from evidently.ui.service.type_aliases import SnapshotID
14  
15  
16  class ReportModel(BaseModel):
17      id: SnapshotID
18      name: Optional[str]
19      timestamp: datetime.datetime
20      metadata: Dict[str, MetadataValueType]
21      tags: List[str]
22      links: SnapshotLinks = SnapshotLinks()
23  
24      @classmethod
25      def from_report(cls, report: Report):
26          return cls(
27              id=report.id,
28              name=report.name,
29              timestamp=report.timestamp,
30              metadata=report.metadata,
31              tags=report.tags,
32          )
33  
34      @classmethod
35      def from_snapshot(cls, snapshot: SnapshotMetadataModel):
36          return cls(
37              id=snapshot.id,
38              name=snapshot.name,
39              timestamp=snapshot.timestamp,
40              metadata=snapshot.metadata,
41              tags=snapshot.tags,
42              links=snapshot.links,
43          )
44  
45  
46  class OrgModel(BaseModel):
47      id: OrgID
48      name: str
49  
50      @classmethod
51      def from_org(cls, org: Org):
52          return OrgModel(id=org.id, name=org.name)
53  
54      def to_org(self) -> Org:
55          return Org(id=self.id, name=self.name)
56  
57  
58  class Version(BaseModel):
59      application: str
60      version: str
61      commit: str