-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantification.py
More file actions
47 lines (37 loc) · 1.49 KB
/
quantification.py
File metadata and controls
47 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from __future__ import annotations
import json
from typing import List
from pydantic import BaseModel
class Quantification(BaseModel):
"""
A class that represents quantification of the performance of a system using the provided criteria.
"""
name: str
results: str | int | float
def __init__(self, name: str, results: str | int | float):
"""
Args:
name (str): The name of the quantification.
results (str | int | float): The results of the quantification.
"""
super().__init__(name=name, results=results)
@staticmethod
def parse_json_str(quantification: str) -> List[Quantification]:
"""
Parse a json string into a list of Quantification objects.
Args:
quantification (str): A json string that represents a list of Quantification objects.
Returns:
List[Quantification]: A list of Quantification objects.
"""
return [Quantification(k, v) for k, v in json.loads(quantification).items()]
@staticmethod
def write_json(quantification: List[Quantification]) -> str:
"""
Write a list of Quantification objects into a json string.
Args:
quantification (List[Quantification]): A list of Quantification objects.
Returns:
str: A json string that represents a list of Quantification objects.
"""
return json.dumps([q.model_dump() for q in quantification], indent=2)