def from_proto(cls, proto): run_data = cls() # iterate proto and add metrics and params for proto_metric in proto.metrics: run_data._add_metric(Metric.from_proto(proto_metric)) for proto_param in proto.params: run_data._add_param(Param.from_proto(proto_param)) return run_data
def from_proto(cls, proto): run_data = cls() # iterate proto and add metrics, params, and tags for proto_metric in proto.metrics: run_data._add_metric(Metric.from_proto(proto_metric)) for proto_param in proto.params: run_data._add_param(Param.from_proto(proto_param)) for proto_tag in proto.tags: run_data._add_tag(RunTag.from_proto(proto_tag)) return run_data
def get_metric_history(self, run_uuid, metric_key): """ Returns all logged value for a given metric. :param run_uuid: Unique identifier for run :param metric_key: Metric name within the run :return: A list of float values logged for the give metric if logged, else empty list """ req_body = _message_to_json(GetMetricHistory(run_uuid=run_uuid, metric_key=metric_key)) response_proto = self._call_endpoint(GetMetricHistory, req_body) return [Metric.from_proto(metric).value for metric in response_proto.metrics]
def get_metric(self, run_uuid, metric_key): """ Returns the last logged value for a given metric. :param run_uuid: Unique identifier for run :param metric_key: Metric name within the run :return: A single float value for the give metric if logged, else None """ req_body = _message_to_json(GetMetric(run_uuid=run_uuid, metric_key=metric_key)) response_proto = self._call_endpoint(GetMetric, req_body) return Metric.from_proto(response_proto.metric)
def test_creation_and_hydration(self): key = random_str() value = 10000 ts = int(time.time()) metric = Metric(key, value, ts) self._check(metric, key, value, ts) as_dict = {"key": key, "value": value, "timestamp": ts} self.assertEqual(dict(metric), as_dict) proto = metric.to_proto() metric2 = metric.from_proto(proto) self._check(metric2, key, value, ts) metric3 = Metric.from_dictionary(as_dict) self._check(metric3, key, value, ts)