Search in sources :

Example 1 with PredictionSummary

use of org.hisp.dhis.predictor.PredictionSummary in project dhis2-core by dhis2.

the class PredictorController method runPredictor.

@RequestMapping(value = "/{uid}/run", method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
@ResponseBody
public WebMessage runPredictor(@PathVariable("uid") String uid, @RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams) {
    Predictor predictor = predictorService.getPredictor(uid);
    try {
        PredictionSummary predictionSummary = new PredictionSummary();
        predictionService.predict(predictor, startDate, endDate, predictionSummary);
        return ok("Generated " + predictionSummary.getPredictions() + " predictions");
    } catch (Exception ex) {
        log.error("Unable to predict " + predictor.getName(), ex);
        return conflict("Unable to predict " + predictor.getName(), ex.getMessage());
    }
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PredictionSummary(org.hisp.dhis.predictor.PredictionSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with PredictionSummary

use of org.hisp.dhis.predictor.PredictionSummary in project dhis2-core by dhis2.

the class PredictionController method runPredictors.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
@ResponseBody
public WebMessage runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, @RequestParam(value = "predictor", required = false) List<String> predictors, @RequestParam(value = "predictorGroup", required = false) List<String> predictorGroups, @RequestParam(defaultValue = "false", required = false) boolean async, HttpServletRequest request) {
    if (async) {
        JobConfiguration jobId = new JobConfiguration("inMemoryPrediction", PREDICTOR, currentUserService.getCurrentUser().getUid(), true);
        taskExecutor.executeTask(new PredictionTask(startDate, endDate, predictors, predictorGroups, predictionService, jobId));
        return jobConfigurationReport(jobId).setLocation("/system/tasks/" + PREDICTOR);
    }
    PredictionSummary predictionSummary = predictionService.predictTask(startDate, endDate, predictors, predictorGroups, null);
    return new WebMessage(Status.OK, HttpStatus.OK).setResponse(predictionSummary).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : PredictionTask(org.hisp.dhis.predictor.PredictionTask) PredictionSummary(org.hisp.dhis.predictor.PredictionSummary) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with PredictionSummary

use of org.hisp.dhis.predictor.PredictionSummary in project dhis2-core by dhis2.

the class PredictorController method runPredictors.

@RequestMapping(value = "/run", method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
@ResponseBody
public WebMessage runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams) {
    int count = 0;
    List<Predictor> allPredictors = predictorService.getAllPredictors();
    for (Predictor predictor : allPredictors) {
        try {
            PredictionSummary predictionSummary = new PredictionSummary();
            predictionService.predict(predictor, startDate, endDate, predictionSummary);
            count += predictionSummary.getPredictions();
        } catch (Exception ex) {
            log.error("Unable to predict " + predictor.getName(), ex);
            return conflict("Unable to predict " + predictor.getName(), ex.getMessage());
        }
    }
    return ok("Generated " + count + " predictions");
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PredictionSummary(org.hisp.dhis.predictor.PredictionSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PredictionSummary (org.hisp.dhis.predictor.PredictionSummary)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Predictor (org.hisp.dhis.predictor.Predictor)2 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)1 PredictionTask (org.hisp.dhis.predictor.PredictionTask)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1