def list_model_metric_metas(
        self,
        model_name: Text,
        project_name: Optional[Text] = None
    ) -> Tuple[int, Text, Union[None, MetricMeta, List[MetricMeta]]]:
        """
        List of model metric metadata filter by model name and project name for Metric Center.

        :param model_name: Name of the model associated with the registered metric meta.
        :param project_name: Name of the project associated with the registered metric meta.

        :return: List of :py:class:`ai_flow.meta.metric_meta.MetricMeta` objects.
        """
        request = ListModelMetricMetasRequest(
            model_name=model_name, project_name=stringValue(project_name))
        response = self.metric_stub.listModelMetricMetas(request)
        if 0 == response.return_code:
            repeated_metric_meta_proto = response.metric_metas
            if 1 == len(repeated_metric_meta_proto):
                metric_meta = proto_to_metric_meta(
                    repeated_metric_meta_proto[0])
                return response.return_code, response.return_msg, metric_meta
            else:
                res = []
                for metric_meta_proto in repeated_metric_meta_proto:
                    res.append(proto_to_metric_meta(metric_meta_proto))
                return response.return_code, response.return_msg, res

        else:
            return response.return_code, response.return_msg, None
    def get_dataset_metric_meta(self, dataset_id: int) -> Tuple[int, Text, Union[None, MetricMeta, List[MetricMeta]]]:
        request = metric_service_pb2.GetDataSetMetricMetaRequest(dataset_id=dataset_id)
        response = self.metric_stub.getDatasetMetricMeta(request)

        if 0 == response.return_code:
            repeated_metric_meta_proto = response.metric_meta
            if 1 == len(repeated_metric_meta_proto):
                metric_meta = proto_to_metric_meta(repeated_metric_meta_proto[0])
                return response.return_code, response.return_msg, metric_meta
            else:
                res = []
                for metric_meta_proto in repeated_metric_meta_proto:
                    res.append(proto_to_metric_meta(metric_meta_proto))
                return response.return_code, response.return_msg, res

        else:
            return response.return_code, response.return_msg, None
    def get_model_metric_meta(self, model_name, model_version) \
            -> Tuple[int, Text, Union[None, MetricMeta, List[MetricMeta]]]:
        request = metric_service_pb2.GetModelMetricMetaRequest(model_name=model_name, model_version=model_version)
        response = self.metric_stub.getModelMetricMeta(request)

        if 0 == response.return_code:
            repeated_metric_meta_proto = response.metric_meta
            if 1 == len(repeated_metric_meta_proto):
                metric_meta = proto_to_metric_meta(repeated_metric_meta_proto[0])
                return response.return_code, response.return_msg, metric_meta
            else:
                res = []
                for metric_meta_proto in repeated_metric_meta_proto:
                    res.append(proto_to_metric_meta(metric_meta_proto))
                return response.return_code, response.return_msg, res

        else:
            return response.return_code, response.return_msg, None
    def get_metric_meta(self, name: Text) -> Tuple[int, Text, Union[None, MetricMeta]]:
        request = metric_service_pb2.GetMetricMetaRequest(metric_name=name)
        response = self.metric_stub.getMetricMeta(request)

        if 0 == response.return_code:
            metric_meta_proto = response.metric_meta
            metric_meta = proto_to_metric_meta(metric_meta_proto)
            return response.return_code, response.return_msg, metric_meta
        else:
            return response.return_code, response.return_msg, None
 def updateMetricMeta(self, request, context):
     metric_meta_proto = request.metric_meta
     metric_meta = proto_to_metric_meta(metric_meta_proto)
     res_metric_meta = self.store.update_metric_meta(
         metric_meta.metric_name, metric_meta.metric_desc,
         metric_meta.project_name, metric_meta.dataset_name,
         metric_meta.model_name, metric_meta.job_name,
         metric_meta.start_time, metric_meta.end_time, metric_meta.uri,
         metric_meta.tags, metric_meta.properties)
     return _warp_metric_meta_response(res_metric_meta)
 def register_metric_meta(
     self,
     metric_name: Text,
     metric_type: MetricType,
     project_name: Text,
     metric_desc: Optional[Text] = None,
     dataset_name: Optional[Text] = None,
     model_name: Optional[Text] = None,
     job_name: Optional[Text] = None,
     start_time: int = None,
     end_time: int = None,
     uri: Optional[Text] = None,
     tags: Optional[Text] = None,
     properties: Properties = None
 ) -> Tuple[int, Text, Optional[MetricMeta]]:
     """
     Register metric metadata in Metric Center.
     
     :param metric_name: Name of registered metric meta. This is expected to be unique in the backend store.
     :param metric_type: Type of registered metric meta.
     :param project_name: Name of the project associated with the registered metric meta.
     :param metric_desc: (Optional) Description of registered metric meta.
     :param dataset_name: (Optional) Name of the dataset associated with the registered metric meta.
     :param model_name: (Optional) Name of the model associated with the registered metric meta.
     :param job_name: (Optional) Name of the job associated with the registered metric meta.
     :param start_time: (Optional) Start time of registered metric meta.
     :param end_time: (Optional) End time of registered metric meta.
     :param uri: (Optional) Uri of registered metric meta.
     :param tags: (Optional) Tags of registered metric meta.
     :param properties: (Optional) Properties of registered metric meta.
     
     :return: A single :py:class:`ai_flow.meta.metric_meta.MetricMeta` object.
     """
     request = MetricMetaRequest(metric_meta=MetricMetaProto(
         metric_name=stringValue(metric_name),
         metric_type=MetricTypeProto.Value(metric_type.value),
         metric_desc=stringValue(metric_desc),
         project_name=stringValue(project_name),
         dataset_name=stringValue(dataset_name),
         model_name=stringValue(model_name),
         job_name=stringValue(job_name),
         start_time=int64Value(start_time),
         end_time=int64Value(end_time),
         uri=stringValue(uri),
         tags=stringValue(tags),
         properties=properties))
     response = self.metric_stub.registerMetricMeta(request)
     if 0 == response.return_code:
         metric_meta_proto = response.metric_meta
         metric_meta = proto_to_metric_meta(metric_meta_proto)
         return response.return_code, response.return_msg, metric_meta
     else:
         return response.return_code, response.return_msg, None
Esempio n. 7
0
    def registerMetricMeta(self, request, context):
        metric_meta_proto = request.metric_meta

        metric_meta = proto_to_metric_meta(metric_meta_proto)

        res_metric_meta = self.store.register_metric_meta(
            metric_meta.name, metric_meta.dataset_id, metric_meta.model_name,
            metric_meta.model_version, metric_meta.job_id,
            metric_meta.start_time, metric_meta.end_time,
            metric_meta.metric_type, metric_meta.uri, metric_meta.tags,
            metric_meta.metric_description, metric_meta.properties)

        return _warp_metric_meta_response(res_metric_meta)
    def get_metric_meta(
            self,
            metric_name: Text) -> Tuple[int, Text, Union[None, MetricMeta]]:
        """
        Get metric metadata detail filter by metric name for Metric Center.

        :param metric_name: Name of registered metric meta. This is expected to be unique in the backend store.

       :return: A single :py:class:`ai_flow.meta.metric_meta.MetricMeta` object.
        """
        request = MetricNameRequest(metric_name=metric_name)
        response = self.metric_stub.getMetricMeta(request)

        if 0 == response.return_code:
            metric_meta_proto = response.metric_meta
            metric_meta = proto_to_metric_meta(metric_meta_proto)
            return response.return_code, response.return_msg, metric_meta
        else:
            return response.return_code, response.return_msg, None
    def update_metric_meta(self,
                           uuid: int,
                           name: Text = None,
                           dataset_id: int = None,
                           model_name: Optional[Text] = None,
                           model_version: Optional[Text] = None,
                           job_id: int = None,
                           start_time: int = None,
                           end_time: int = None,
                           metric_type: MetricType = MetricType.DATASET,
                           uri: Text = None,
                           tags: Text = None,
                           metric_description: Text = None,
                           properties: Properties = None,
                           ) -> Tuple[int, Text, Optional[MetricMeta]]:

        pb_metric_type = message_pb2.MetricTypeProto.Value(metric_type.value)
        request = metric_service_pb2.MetricMetaRequest(
            metric_meta=message_pb2.MetricMetaProto(
                uuid=uuid,
                name=stringValue(name),
                dataset_id=int64Value(dataset_id),
                model_name=stringValue(model_name),
                model_version=stringValue(model_version),
                job_id=int64Value(job_id),
                start_time=int64Value(start_time),
                end_time=int64Value(end_time),
                metric_type=pb_metric_type,
                uri=stringValue(uri),
                tags=stringValue(tags),
                metric_description=stringValue(metric_description),
                properties=properties)
        )
        response = self.metric_stub.updateMetricMeta(request)
        if 0 == response.return_code:
            metric_meta_proto = response.metric_meta
            metric_meta = proto_to_metric_meta(metric_meta_proto)
            return response.return_code, response.return_msg, metric_meta
        else:
            return response.return_code, response.return_msg, None