Search in sources :

Example 1 with BatchModelResponse

use of org.openscoring.common.BatchModelResponse in project openscoring by openscoring.

the class ModelResource method queryBatch.

@GET
@Produces(MediaType.APPLICATION_JSON)
public BatchModelResponse queryBatch() {
    BatchModelResponse batchResponse = new BatchModelResponse();
    List<ModelResponse> responses = new ArrayList<>();
    Collection<Map.Entry<String, Model>> entries = this.modelRegistry.entries();
    for (Map.Entry<String, Model> entry : entries) {
        ModelResponse response = createModelResponse(entry.getKey(), entry.getValue(), false);
        responses.add(response);
    }
    Comparator<ModelResponse> comparator = new Comparator<ModelResponse>() {

        @Override
        public int compare(ModelResponse left, ModelResponse right) {
            return (left.getId()).compareToIgnoreCase(right.getId());
        }
    };
    Collections.sort(responses, comparator);
    batchResponse.setResponses(responses);
    return batchResponse;
}
Also used : BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ArrayList(java.util.ArrayList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with BatchModelResponse

use of org.openscoring.common.BatchModelResponse in project openscoring by openscoring.

the class ModelResourceTest method queryBatch.

private BatchModelResponse queryBatch() {
    Response response = target("model").request(MediaType.APPLICATION_JSON).get();
    assertEquals(200, response.getStatus());
    return response.readEntity(BatchModelResponse.class);
}
Also used : EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response)

Example 3 with BatchModelResponse

use of org.openscoring.common.BatchModelResponse in project openscoring by openscoring.

the class ModelResourceTest method decisionTreeIris.

@Test
public void decisionTreeIris() throws Exception {
    String id = "DecisionTreeIris";
    assertEquals("Iris", extractSuffix(id));
    BatchModelResponse batchModelResponse = queryBatch();
    List<ModelResponse> modelResponses = batchModelResponse.getResponses();
    assertNull(modelResponses);
    deploy(id);
    batchModelResponse = queryBatch();
    modelResponses = batchModelResponse.getResponses();
    assertEquals(1, modelResponses.size());
    download(id);
    List<EvaluationRequest> evaluationRequests = loadRecords(id);
    EvaluationRequest evaluationRequest = evaluationRequests.get(0);
    EvaluationResponse evaluationResponse = evaluate(id, evaluationRequest);
    assertEquals(evaluationRequest.getId(), evaluationResponse.getId());
    EvaluationRequest invalidEvaluationRequest = invalidate(evaluationRequests.get(50));
    evaluationRequests = Arrays.asList(evaluationRequests.get(0), invalidEvaluationRequest, evaluationRequests.get(100));
    BatchEvaluationRequest batchEvaluationRequest = new BatchEvaluationRequest();
    batchEvaluationRequest.setRequests(evaluationRequests);
    BatchEvaluationResponse batchEvaluationResponse = evaluateBatch(id, batchEvaluationRequest);
    assertEquals(batchEvaluationRequest.getId(), batchEvaluationResponse.getId());
    List<EvaluationResponse> evaluationResponses = batchEvaluationResponse.getResponses();
    assertEquals(evaluationRequests.size(), evaluationResponses.size());
    EvaluationResponse invalidEvaluationResponse = evaluationResponses.get(1);
    assertEquals(invalidEvaluationRequest.getId(), invalidEvaluationResponse.getId());
    assertNotNull(invalidEvaluationResponse.getMessage());
    undeploy(id);
}
Also used : BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationRequest(org.openscoring.common.EvaluationRequest) BatchModelResponse(org.openscoring.common.BatchModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

BatchModelResponse (org.openscoring.common.BatchModelResponse)3 ModelResponse (org.openscoring.common.ModelResponse)3 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)2 EvaluationResponse (org.openscoring.common.EvaluationResponse)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1 BatchEvaluationRequest (org.openscoring.common.BatchEvaluationRequest)1 EvaluationRequest (org.openscoring.common.EvaluationRequest)1 SimpleResponse (org.openscoring.common.SimpleResponse)1