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());
}
}
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);
}
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");
}
Aggregations