generated from adrienaury/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
This API allows to get the contributions of the dataset variables within the fitted space.
Request
Method
GET
URL
/contributions
Request Parameters
None
Request Body
None
Result
Result parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
data |
Dictionary of dictionaries of variable contributions | Yes | {<br> "feature1": {<br>  "value1": 0.1,<br>  "value2": 0.2<br> },<br> "feature2": {<br>  "value1": 0.3,<br>  "value2": 0.4<br> }<br>} |
Result Body
The following JSON is returned:
{
"data": {
"<variable 1>": {
"<value 1>": <contribution 1>,
"<value 2>": <contribution 2>,
},
"<variable 2>": {
"<value 1>": <contribution 1>,
"<value 2>": <contribution 2>,
},
}
}
Example Curl Request
curl -X GET \
http://localhost:8080/contributions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>'
Curl Response
{
"data": {
"age": {
"50-60": 0.5,
"60-70": 0.3,
"70-80": 0.2
},
"gender": {
"male": 0.7,
"female": 0.3
}
}
}Go server
Struct
type Contributions struct {
Data map[string]map[string]float64 `json:"data"`
}Handler
func (s *Server) contributions(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
jobID := r.FormValue("job_id")
if jobID == "" {
http.Error(w, "job_id is required", http.StatusBadRequest)
return
}
datasetID := r.FormValue("dataset_id")
if datasetID == "" {
http.Error(w, "dataset_id is required", http.StatusBadRequest)
return
}
// Get the contributions from the database
contributions, err := s.db.GetContributions(ctx, jobID, datasetID)
if err != nil {
http.Error(w, "failed to get contributions", http.StatusInternalServerError)
return
}
// Write the contributions to the response
if err := json.NewEncoder(w).Encode(contributions); err != nil {
http.Error(w, "failed to encode contributions", 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
Reactions are currently unavailable