|
| 1 | +"""This module contains definitions for acceptance tests.""" |
| 2 | + |
| 3 | +from datetime import datetime |
| 4 | +from enum import Enum |
| 5 | + |
| 6 | +from nextmv.base_model import BaseModel |
| 7 | + |
| 8 | + |
| 9 | +class MetricType(str, Enum): |
| 10 | + """Type of metric when doing a comparison.""" |
| 11 | + |
| 12 | + absolute_threshold = "absolute-threshold" |
| 13 | + """Absolute threshold metric type.""" |
| 14 | + difference_threshold = "difference-threshold" |
| 15 | + """Difference threshold metric type.""" |
| 16 | + direct_comparison = "direct-comparison" |
| 17 | + """Direct comparison metric type.""" |
| 18 | + |
| 19 | + |
| 20 | +class Comparison(str, Enum): |
| 21 | + """Comparison to use for two metrics.""" |
| 22 | + |
| 23 | + equal_to = "eq" |
| 24 | + """Equal to metric type.""" |
| 25 | + greater_than = "gt" |
| 26 | + """Greater than metric type.""" |
| 27 | + greater_than_or_equal_to = "ge" |
| 28 | + """Greater than or equal to metric type.""" |
| 29 | + less_than = "lt" |
| 30 | + """Less than metric type.""" |
| 31 | + less_than_or_equal_to = "le" |
| 32 | + """Less than or equal to metric type.""" |
| 33 | + not_equal_to = "ne" |
| 34 | + """Not equal to metric type.""" |
| 35 | + |
| 36 | + |
| 37 | +class AcceptanceTestParams(BaseModel): |
| 38 | + """Parameters of an acceptance test.""" |
| 39 | + |
| 40 | + operator: Comparison |
| 41 | + """Operator used to compare two metrics.""" |
| 42 | + |
| 43 | + |
| 44 | +class Metric(BaseModel): |
| 45 | + """A metric is a key performance indicator that is used to evaluate the |
| 46 | + performance of a test.""" |
| 47 | + |
| 48 | + field: str |
| 49 | + """Field of the metric.""" |
| 50 | + metric_type: MetricType |
| 51 | + """Type of the metric.""" |
| 52 | + params: AcceptanceTestParams |
| 53 | + """Parameters of the metric.""" |
| 54 | + statistic: str |
| 55 | + """Statistic of the metric.""" |
| 56 | + |
| 57 | + |
| 58 | +class ComparisonInstance(BaseModel): |
| 59 | + """An instance used for a comparison.""" |
| 60 | + |
| 61 | + instance_id: str |
| 62 | + """ID of the instance.""" |
| 63 | + version_id: str |
| 64 | + """ID of the version.""" |
| 65 | + |
| 66 | + |
| 67 | +class AcceptanceTest(BaseModel): |
| 68 | + """An acceptance test gives a go/no-go decision criteria for a set of |
| 69 | + metrics. It relies on a batch experiment.""" |
| 70 | + |
| 71 | + id: str |
| 72 | + """ID of the acceptance test.""" |
| 73 | + name: str |
| 74 | + """Name of the acceptance test.""" |
| 75 | + description: str |
| 76 | + """Description of the acceptance test.""" |
| 77 | + app_id: str |
| 78 | + """ID of the app that owns the acceptance test.""" |
| 79 | + experiment_id: str |
| 80 | + """ID of the batch experiment underlying in the acceptance test.""" |
| 81 | + control: ComparisonInstance |
| 82 | + """Control instance of the acceptance test.""" |
| 83 | + candidate: ComparisonInstance |
| 84 | + """Candidate instance of the acceptance test.""" |
| 85 | + metrics: list[Metric] |
| 86 | + """Metrics of the acceptance test.""" |
| 87 | + created_at: datetime |
| 88 | + """Creation date of the acceptance test.""" |
| 89 | + updated_at: datetime |
| 90 | + """Last update date of the acceptance test.""" |
0 commit comments