use of org.hisp.dhis.predictor.Predictor 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')")
public void runPredictor(@PathVariable("uid") String uid, @RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
Predictor predictor = predictorService.getPredictor(uid);
try {
int count = predictorService.predict(predictor, startDate, endDate);
webMessageService.send(WebMessageUtils.ok("Generated " + count + " predictions"), response, request);
} catch (Exception ex) {
log.error("Unable to predict " + predictor.getName(), ex);
webMessageService.send(WebMessageUtils.conflict("Unable to predict " + predictor.getName(), ex.getMessage()), response, request);
}
}
use of org.hisp.dhis.predictor.Predictor 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')")
public void runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
int count = 0;
List<Predictor> allPredictors = predictorService.getAllPredictors();
for (Predictor predictor : allPredictors) {
try {
count += predictorService.predict(predictor, startDate, endDate);
} catch (Exception ex) {
log.error("Unable to predict " + predictor.getName(), ex);
webMessageService.send(WebMessageUtils.conflict("Unable to predict " + predictor.getName(), ex.getMessage()), response, request);
return;
}
}
webMessageService.send(WebMessageUtils.ok("Generated " + count + " predictions"), response, request);
}
use of org.hisp.dhis.predictor.Predictor in project dhis2-core by dhis2.
the class DhisConvenienceTest method createPredictorGroup.
/**
* Creates a Predictor Group
*
* @param uniqueCharacter A unique character to identify the object.
* @param predictors Predictors to add to the group.
* @return PredictorGroup
*/
public static PredictorGroup createPredictorGroup(char uniqueCharacter, Predictor... predictors) {
PredictorGroup group = new PredictorGroup();
group.setAutoFields();
group.setName("PredictorGroup" + uniqueCharacter);
group.setDescription("Description" + uniqueCharacter);
group.setUid(BASE_PREDICTOR_GROUP_UID + uniqueCharacter);
for (Predictor p : predictors) {
group.addPredictor(p);
}
return group;
}
use of org.hisp.dhis.predictor.Predictor 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.Predictor in project dhis2-core by dhis2.
the class PredictorObjectBundleHook method preCreate.
@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
if (!Predictor.class.isInstance(object)) {
return;
}
Predictor predictor = (Predictor) object;
Expression skipTest = predictor.getSampleSkipTest();
preheatService.connectReferences(predictor.getGenerator(), bundle.getPreheat(), bundle.getPreheatIdentifier());
if (skipTest != null) {
preheatService.connectReferences(skipTest, bundle.getPreheat(), bundle.getPreheatIdentifier());
}
sessionFactory.getCurrentSession().save(predictor.getGenerator());
if (skipTest != null) {
sessionFactory.getCurrentSession().save(skipTest);
}
if (predictor.getPeriodType() != null) {
PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(predictor.getPeriodType().getName());
predictor.setPeriodType(periodType);
}
}
Aggregations