koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame^] | 1 | import abc |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 2 | import array |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame^] | 3 | from typing import Dict, List, Any, Tuple, Optional, Union, Type |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 4 | |
| 5 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 6 | class TimeSerie: |
| 7 | name = None # type: str |
| 8 | start_at = None # type: int |
| 9 | step = None # type: int |
| 10 | data = None # type: List[int] |
| 11 | second_axis_size = None # type: int |
| 12 | raw = None # type: Optional[bytes] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 13 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 14 | def __init__(self, name: str, raw: Optional[bytes], second_axis_size: int, |
| 15 | start_at: int, step: int, data: array.array) -> None: |
| 16 | self.name = name |
| 17 | self.start_at = start_at |
| 18 | self.step = step |
| 19 | self.second_axis_size = second_axis_size |
| 20 | self.data = data # type: ignore |
| 21 | self.raw = raw |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 22 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 23 | def meta(self) -> Dict[str, Any]: |
| 24 | return { |
| 25 | "start_at": self.start_at, |
| 26 | "step": self.step, |
| 27 | "second_axis_size": self.second_axis_size |
| 28 | } |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | class SensorInfo: |
| 32 | """Holds information from a single sensor from a single node""" |
| 33 | node_id = None # type: str |
| 34 | source_id = None # type: str |
| 35 | sensor_name = None # type: str |
| 36 | begin_time = None # type: int |
| 37 | end_time = None # type: int |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 38 | data = None # type: List[int] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 39 | |
| 40 | def __init__(self, node_id: str, source_id: str, sensor_name: str) -> None: |
| 41 | self.node_id = node_id |
| 42 | self.source_id = source_id |
| 43 | self.sensor_name = sensor_name |
| 44 | |
| 45 | |
| 46 | class TestInfo: |
| 47 | """Contains done test information""" |
| 48 | name = None # type: str |
| 49 | iteration_name = None # type: str |
| 50 | nodes = None # type: List[str] |
| 51 | start_time = None # type: int |
| 52 | stop_time = None # type: int |
| 53 | params = None # type: Dict[str, Any] |
| 54 | config = None # type: str |
| 55 | node_ids = None # type: List[str] |
| 56 | |
| 57 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 58 | class NodeTestResults: |
| 59 | name = None # type: str |
| 60 | node_id = None # type: str |
| 61 | summary = None # type: str |
| 62 | |
| 63 | load_start_at = None # type: int |
| 64 | load_stop_at = None # type: int |
| 65 | |
| 66 | series = None # type: Dict[str, TimeSerie] |
| 67 | |
| 68 | def __init__(self, name: str, node_id: str, summary: str) -> None: |
| 69 | self.name = name |
| 70 | self.node_id = node_id |
| 71 | self.summary = summary |
| 72 | self.series = {} |
| 73 | self.extra_logs = {} # type: Dict[str, bytes] |
| 74 | |
| 75 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 76 | class FullTestResult: |
| 77 | test_info = None # type: TestInfo |
| 78 | |
| 79 | # TODO(koder): array.array or numpy.array? |
| 80 | # {(node_id, perf_metrics_name): values} |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 81 | performance_data = None # type: Dict[Tuple[str, str], List[int]] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 82 | |
| 83 | # {(node_id, perf_metrics_name): values} |
| 84 | sensors_data = None # type: Dict[Tuple[str, str, str], SensorInfo] |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame^] | 85 | |
| 86 | |
| 87 | class IStorable(metaclass=abc.ABCMeta): |
| 88 | """Interface for type, which can be stored""" |
| 89 | |
| 90 | @abc.abstractmethod |
| 91 | def raw(self) -> Dict[str, Any]: |
| 92 | pass |
| 93 | |
| 94 | @abc.abstractclassmethod |
| 95 | def fromraw(cls, data: Dict[str, Any]) -> 'IStorable': |
| 96 | pass |
| 97 | |
| 98 | |
| 99 | Basic = Union[int, str, bytes, bool, None] |
| 100 | Storable = Union[IStorable, Dict[str, Any], List[Any], int, str, bytes, bool, None] |
| 101 | |