Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][API] Privacy Metrics Batch Job Creation #71

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Privacy Metrics Batch Job Creation #71

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

Adds the ability to create a privacy metrics batch job

Request

Method

POST

URL

/jobs/metrics/privacy_batch

Request Parameters

Parameter Description Required example
kind Job kind True privacy_metrics_batch
parameters Parameters for the privacy metrics batch job True JSON object

Request Body

The request body is a JSON object with the following structure:

{
  "kind": "privacy_metrics_batch",
  "parameters": {
    "dataset_uuid": "UUID of the dataset to analyze",
    "configs": [
      {
        "privacy_metric_kind": "KIND_OF_PRIVACY_METRIC",
        "model_kind": "KIND_OF_MODEL",
        "model_parameters": {
          "parameter_name": "parameter_value"
        }
      }
    ]
  }
}

Result

Result parameters

Parameter Description Required example
id Id of the privacy metrics batch job True UUID
kind Job kind True privacy_metrics_batch
created_at Date and time when the privacy metrics batch job was created True 2023-07-18T13:37:42.938919Z
status Status of the privacy metrics batch job True created
error_message Error message if the privacy metrics batch job failed False null
traceback Traceback if the privacy metrics batch job failed False null
result Result of the privacy metrics batch job False JSON object
parameters Parameters of the privacy metrics batch job True JSON object
current_progress Current progress of the privacy metrics batch job False JSON object

Result Body

The result body is a JSON object with the following structure:

{
  "kind": "privacy_metrics_batch",
  "parameters": {
    "dataset_uuid": "UUID of the dataset to analyze",
    "configs": [
      {
        "privacy_metric_kind": "KIND_OF_PRIVACY_METRIC",
        "model_kind": "KIND_OF_MODEL",
        "model_parameters": {
          "parameter_name": "parameter_value"
        }
      }
    ]
  },
  "result": {
    "privacy_metrics": [
      {
        "privacy_metric_kind": "KIND_OF_PRIVACY_METRIC",
        "model_kind": "KIND_OF_MODEL",
        "model_parameters": {
          "parameter_name": "parameter_value"
        },
        "value": "VALUE_OF_PRIVACY_METRIC"
      }
    ]
  }
}

Example Curl Request

Request

curl --location --request POST 'http://localhost:8080/jobs/metrics/privacy_batch' \
--header 'Content-Type: application/json' \
--data-raw '{
  "kind": "privacy_metrics_batch",
  "parameters": {
    "dataset_uuid": "f20de20c-0677-460a-a60e-725fb441bf58",
    "configs": [
      {
        "privacy_metric_kind": "K_ANONYMITY",
        "model_kind": "LINEAR_REGRESSION",
        "model_parameters": {
          "alpha": 0.001,
          "max_iter": 1000
        }
      }
    ]
  }
}'

Curl Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "581de059-1552-45d7-a612-5e5db722f0e6",
  "kind": "privacy_metrics_batch",
  "created_at": "2023-07-18T13:37:42.938919Z",
  "status": "created",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "dataset_uuid": "f20de20c-0677-460a-a60e-725fb441bf58",
    "configs": [
      {
        "privacy_metric_kind": "K_ANONYMITY",
        "model_kind": "LINEAR_REGRESSION",
        "model_parameters": {
          "alpha": 0.001,
          "max_iter": 1000
        }
      }
    ]
  },
  "current_progress": null
}

Go server

Struct

type PrivacyMetricsBatchJob struct {
    ID                UUID
    Kind              JobKind
    CreatedAt         time.Time
    Status            JobStatus
    ErrorMessage      *string
    Traceback         *string
    Result            *PrivacyMetricsBatchResult
    Parameters        PrivacyMetricsBatchParameters
    CurrentProgress  *JobProgress
}

Handler

func (s *Server) createPrivacyMetricsBatchJob(ctx context.Context, w http.ResponseWriter, r *http.Request) {
    var req PrivacyMetricsBatchJobCreate
    if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }
    if req.Kind != JobKindPrivacyMetricsBatch {
        http.Error(w, "Invalid job kind", http.StatusBadRequest)
        return
    }
    job, err := s.Service.CreatePrivacyMetricsBatchJob(ctx, req.Parameters)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
    w.Header().Set("Content-Type", "application/json")
    if err := json.NewEncoder(w).Encode(job); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant