retuve.classes.metrics
Metric Classes for all Retuve Models.
1# Copyright 2024 Adam McArthur 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15""" 16Metric Classes for all Retuve Models. 17""" 18 19from typing import List, Union 20 21 22class Metric2D: 23 """ 24 2D Metrics just have a name and a value. 25 """ 26 27 def __init__(self, name: str, value: Union[int, float]): 28 """ 29 Initialize a 2D Metric. 30 31 :param name: Name of the metric. 32 :param value: Value of the metric. 33 """ 34 self.name = name 35 self.value = value 36 37 def __str__(self) -> str: 38 return f"Metric2D(name={self.name}, value={self.value})" 39 40 41class Metric3D: 42 """ 43 3D Metrics have a name and 4 values: Post, Graf, Ant, Full. 44 """ 45 46 def __init__( 47 self, 48 name: str, 49 post: Union[float, str] = 0, 50 graf: Union[float, str] = 0, 51 ant: Union[float, str] = 0, 52 full: Union[float, None] = None, 53 ): 54 """ 55 If full is not not provided, it is calculated as the average of Post, Graf, and Ant. 56 """ 57 if full is None: 58 self.name = name 59 self.post = post 60 self.graf = graf 61 self.ant = ant 62 63 average_calc = [] 64 for val in [post, graf, ant]: 65 if val > 0: 66 average_calc.append(val) 67 68 if len(average_calc) == 0: 69 self.full = 0 70 else: 71 self.full = round(sum(average_calc) / len(average_calc), 2) 72 73 else: 74 self.name = name 75 self.post, self.graf, self.ant = "N/A", "N/A", "N/A" 76 self.full = full 77 78 def dump(self) -> List[Union[str, float]]: 79 """ 80 Dump the values of the metric into a list. 81 82 Useful for writing to CSV. 83 """ 84 return [ 85 self.name.capitalize(), 86 self.post, 87 self.graf, 88 self.ant, 89 self.full, 90 ] 91 92 def names(self) -> List[str]: 93 """ 94 Return the names of the values in the metric. (In order) 95 """ 96 97 return ["Post", "Graf", "Ant", "Full"]
class
Metric2D:
23class Metric2D: 24 """ 25 2D Metrics just have a name and a value. 26 """ 27 28 def __init__(self, name: str, value: Union[int, float]): 29 """ 30 Initialize a 2D Metric. 31 32 :param name: Name of the metric. 33 :param value: Value of the metric. 34 """ 35 self.name = name 36 self.value = value 37 38 def __str__(self) -> str: 39 return f"Metric2D(name={self.name}, value={self.value})"
2D Metrics just have a name and a value.
Metric2D(name: str, value: Union[int, float])
28 def __init__(self, name: str, value: Union[int, float]): 29 """ 30 Initialize a 2D Metric. 31 32 :param name: Name of the metric. 33 :param value: Value of the metric. 34 """ 35 self.name = name 36 self.value = value
Initialize a 2D Metric.
Parameters
- name: Name of the metric.
- value: Value of the metric.
class
Metric3D:
42class Metric3D: 43 """ 44 3D Metrics have a name and 4 values: Post, Graf, Ant, Full. 45 """ 46 47 def __init__( 48 self, 49 name: str, 50 post: Union[float, str] = 0, 51 graf: Union[float, str] = 0, 52 ant: Union[float, str] = 0, 53 full: Union[float, None] = None, 54 ): 55 """ 56 If full is not not provided, it is calculated as the average of Post, Graf, and Ant. 57 """ 58 if full is None: 59 self.name = name 60 self.post = post 61 self.graf = graf 62 self.ant = ant 63 64 average_calc = [] 65 for val in [post, graf, ant]: 66 if val > 0: 67 average_calc.append(val) 68 69 if len(average_calc) == 0: 70 self.full = 0 71 else: 72 self.full = round(sum(average_calc) / len(average_calc), 2) 73 74 else: 75 self.name = name 76 self.post, self.graf, self.ant = "N/A", "N/A", "N/A" 77 self.full = full 78 79 def dump(self) -> List[Union[str, float]]: 80 """ 81 Dump the values of the metric into a list. 82 83 Useful for writing to CSV. 84 """ 85 return [ 86 self.name.capitalize(), 87 self.post, 88 self.graf, 89 self.ant, 90 self.full, 91 ] 92 93 def names(self) -> List[str]: 94 """ 95 Return the names of the values in the metric. (In order) 96 """ 97 98 return ["Post", "Graf", "Ant", "Full"]
3D Metrics have a name and 4 values: Post, Graf, Ant, Full.
Metric3D( name: str, post: Union[float, str] = 0, graf: Union[float, str] = 0, ant: Union[float, str] = 0, full: Optional[float] = None)
47 def __init__( 48 self, 49 name: str, 50 post: Union[float, str] = 0, 51 graf: Union[float, str] = 0, 52 ant: Union[float, str] = 0, 53 full: Union[float, None] = None, 54 ): 55 """ 56 If full is not not provided, it is calculated as the average of Post, Graf, and Ant. 57 """ 58 if full is None: 59 self.name = name 60 self.post = post 61 self.graf = graf 62 self.ant = ant 63 64 average_calc = [] 65 for val in [post, graf, ant]: 66 if val > 0: 67 average_calc.append(val) 68 69 if len(average_calc) == 0: 70 self.full = 0 71 else: 72 self.full = round(sum(average_calc) / len(average_calc), 2) 73 74 else: 75 self.name = name 76 self.post, self.graf, self.ant = "N/A", "N/A", "N/A" 77 self.full = full
If full is not not provided, it is calculated as the average of Post, Graf, and Ant.
def
dump(self) -> List[Union[str, float]]:
79 def dump(self) -> List[Union[str, float]]: 80 """ 81 Dump the values of the metric into a list. 82 83 Useful for writing to CSV. 84 """ 85 return [ 86 self.name.capitalize(), 87 self.post, 88 self.graf, 89 self.ant, 90 self.full, 91 ]
Dump the values of the metric into a list.
Useful for writing to CSV.