autograder.model.stats
1import typing 2 3import edq.util.time 4import lms.model.base 5 6METRIC_TYPES: typing.List[str] = [ 7 'api-request', 8 'code-analysis-time', 9 'grading-time', 10 'cpu-usage', 11 'mem-usage', 12 'net-in', 13 'net-out', 14 'task-time', 15] 16 17class Metric(lms.model.base.BaseType): 18 """ 19 A metric value. 20 """ 21 22 CORE_FIELDS = [ 23 'timestamp', 24 'type', 25 'value', 26 ] 27 28 def __init__(self, 29 type: str, 30 timestamp: edq.util.time.Timestamp, 31 value: float, 32 attributes: typing.Union[typing.Dict[str, typing.Any], None] = None, 33 **kwargs: typing.Any) -> None: 34 super().__init__(**kwargs) 35 36 self.type: str = type 37 """ The type of metric. """ 38 39 self.timestamp: edq.util.time.Timestamp = timestamp 40 """ Metric collection time. """ 41 42 self.value: float = value 43 """ The metric's value. """ 44 45 if (attributes is None): 46 attributes = {} 47 48 self.attributes: typing.Dict[str, typing.Any] = attributes 49 """ Additional attributes attatched to the metric record. """ 50 51 @classmethod 52 def from_api(cls, data: typing.Dict[str, typing.Any]) -> 'Metric': 53 """ Convert a dict coming from autograder API JSON. """ 54 55 data = data.copy() 56 57 data['timestamp'] = edq.util.time.Timestamp(data['timestamp']) 58 59 return Metric(**data)
METRIC_TYPES: List[str] =
['api-request', 'code-analysis-time', 'grading-time', 'cpu-usage', 'mem-usage', 'net-in', 'net-out', 'task-time']
class
Metric(lms.model.base.BaseType):
18class Metric(lms.model.base.BaseType): 19 """ 20 A metric value. 21 """ 22 23 CORE_FIELDS = [ 24 'timestamp', 25 'type', 26 'value', 27 ] 28 29 def __init__(self, 30 type: str, 31 timestamp: edq.util.time.Timestamp, 32 value: float, 33 attributes: typing.Union[typing.Dict[str, typing.Any], None] = None, 34 **kwargs: typing.Any) -> None: 35 super().__init__(**kwargs) 36 37 self.type: str = type 38 """ The type of metric. """ 39 40 self.timestamp: edq.util.time.Timestamp = timestamp 41 """ Metric collection time. """ 42 43 self.value: float = value 44 """ The metric's value. """ 45 46 if (attributes is None): 47 attributes = {} 48 49 self.attributes: typing.Dict[str, typing.Any] = attributes 50 """ Additional attributes attatched to the metric record. """ 51 52 @classmethod 53 def from_api(cls, data: typing.Dict[str, typing.Any]) -> 'Metric': 54 """ Convert a dict coming from autograder API JSON. """ 55 56 data = data.copy() 57 58 data['timestamp'] = edq.util.time.Timestamp(data['timestamp']) 59 60 return Metric(**data)
A metric value.
Metric( type: str, timestamp: edq.util.time.Timestamp, value: float, attributes: Optional[Dict[str, Any]] = None, **kwargs: Any)
29 def __init__(self, 30 type: str, 31 timestamp: edq.util.time.Timestamp, 32 value: float, 33 attributes: typing.Union[typing.Dict[str, typing.Any], None] = None, 34 **kwargs: typing.Any) -> None: 35 super().__init__(**kwargs) 36 37 self.type: str = type 38 """ The type of metric. """ 39 40 self.timestamp: edq.util.time.Timestamp = timestamp 41 """ Metric collection time. """ 42 43 self.value: float = value 44 """ The metric's value. """ 45 46 if (attributes is None): 47 attributes = {} 48 49 self.attributes: typing.Dict[str, typing.Any] = attributes 50 """ Additional attributes attatched to the metric record. """
CORE_FIELDS =
['timestamp', 'type', 'value']
The common fields shared across backends for this type that are used for comparison and other operations. Child classes should set this to define how comparisons are made.
52 @classmethod 53 def from_api(cls, data: typing.Dict[str, typing.Any]) -> 'Metric': 54 """ Convert a dict coming from autograder API JSON. """ 55 56 data = data.copy() 57 58 data['timestamp'] = edq.util.time.Timestamp(data['timestamp']) 59 60 return Metric(**data)
Convert a dict coming from autograder API JSON.