Coretex
metric.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 from typing import Dict, List, Optional, Union
19 from typing_extensions import Self
20 
21 from .metric_type import MetricType
22 from ....codable import Codable, KeyDescriptor
23 
24 
25 class Metric(Codable):
26 
27  name: str
28  xLabel: str
29  xType: str
30  yLabel: str
31  yType: str
32  xRange: Optional[List[float]]
33  yRange: Optional[List[float]]
34 
35  @classmethod
36  def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
37  descriptors = super()._keyDescriptors()
38  descriptors["name"] = KeyDescriptor("metric")
39 
40  return descriptors
41 
42  @classmethod
43  def create(
44  cls,
45  name: str,
46  xLabel: str,
47  xType: Union[MetricType, int],
48  yLabel: str,
49  yType: Union[MetricType, int],
50  xRange: Optional[List[float]] = None,
51  yRange: Optional[List[float]] = None
52  ) -> Self:
53 
54  """
55  name : str
56  name of Metric
57  xLabel : str
58  label of x axis which will be displayed
59  xType : Union[MetricType, int]
60  type of x axis which will be displayed
61  yLabel : str
62  label of y axis which will be displayed
63  yType : Union[MetricType, int]
64  type of y axis which will be displayed
65  xRange : Optional[List[float]]
66  range in which values will be displayed for x axis
67  yRange : Optional[List[float]]
68  range in which values will be displayed for y axis
69  """
70 
71  if isinstance(xType, int):
72  xType = MetricType(xType)
73 
74  if isinstance(yType, int):
75  yType = MetricType(yType)
76 
77  obj = cls()
78 
79  obj.name = name
80  obj.xLabel = xLabel
81  obj.xType = xType.name
82  obj.yLabel = yLabel
83  obj.yType = yType.name
84  obj.xRange = xRange
85  obj.yRange = yRange
86 
87  return obj
88 
89  def extract(self) -> Optional[float]:
90  return None