Search in sources :

Example 1 with BatchEvaluationResponse

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

the class ModelResourceTest method associationRulesShopping.

@Test
public void associationRulesShopping() throws Exception {
    String id = "AssociationRulesShopping";
    assertEquals("Shopping", extractSuffix(id));
    deployForm(id);
    query(id);
    List<EvaluationRequest> evaluationRequests = loadRecords(id);
    BatchEvaluationRequest batchEvaluationRequest = new BatchEvaluationRequest();
    batchEvaluationRequest.setRequests(evaluationRequests);
    BatchEvaluationResponse batchEvaluationResponse = evaluateBatch(id, batchEvaluationRequest);
    assertEquals(batchEvaluationRequest.getId(), batchEvaluationResponse.getId());
    List<EvaluationRequest> aggregatedEvaluationRequests = ModelResource.aggregateRequests(FieldName.create("transaction"), evaluationRequests);
    batchEvaluationRequest = new BatchEvaluationRequest("aggregate");
    batchEvaluationRequest.setRequests(aggregatedEvaluationRequests);
    batchEvaluationResponse = evaluateBatch(id, batchEvaluationRequest);
    assertEquals(batchEvaluationRequest.getId(), batchEvaluationResponse.getId());
    evaluateCsv(id);
    evaluateCsvForm(id);
    undeployForm(id);
}
Also used : BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationRequest(org.openscoring.common.EvaluationRequest) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with BatchEvaluationResponse

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

the class ModelResource method evaluateBatch.

@POST
@Path("{id: " + ModelRegistry.ID_REGEX + "}/batch")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public BatchEvaluationResponse evaluateBatch(@PathParam("id") String id, BatchEvaluationRequest request) {
    BatchEvaluationResponse batchResponse = new BatchEvaluationResponse(request.getId());
    List<EvaluationRequest> requests = request.getRequests();
    List<EvaluationResponse> responses = doEvaluate(id, requests, false, "evaluate.batch");
    batchResponse.setResponses(responses);
    return batchResponse;
}
Also used : BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) EvaluationRequest(org.openscoring.common.EvaluationRequest) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with BatchEvaluationResponse

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

the class ModelResourceTest method evaluateBatch.

private BatchEvaluationResponse evaluateBatch(String id, BatchEvaluationRequest batchRequest) {
    Entity<BatchEvaluationRequest> entity = Entity.json(batchRequest);
    Response response = target("model/" + id + "/batch").request(MediaType.APPLICATION_JSON).post(entity);
    assertEquals(200, response.getStatus());
    return response.readEntity(BatchEvaluationResponse.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) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest)

Example 4 with BatchEvaluationResponse

use of org.openscoring.common.BatchEvaluationResponse 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

BatchEvaluationRequest (org.openscoring.common.BatchEvaluationRequest)4 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)4 EvaluationRequest (org.openscoring.common.EvaluationRequest)3 EvaluationResponse (org.openscoring.common.EvaluationResponse)3 JerseyTest (org.glassfish.jersey.test.JerseyTest)2 Test (org.junit.Test)2 BatchModelResponse (org.openscoring.common.BatchModelResponse)2 ModelResponse (org.openscoring.common.ModelResponse)2 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 SimpleResponse (org.openscoring.common.SimpleResponse)1