Search in sources :

Example 1 with Predictor

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);
    }
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Predictor

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);
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Predictor

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;
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) PredictorGroup(org.hisp.dhis.predictor.PredictorGroup)

Example 4 with Predictor

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());
    }
}
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 5 with Predictor

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);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Predictor(org.hisp.dhis.predictor.Predictor) Expression(org.hisp.dhis.expression.Expression)

Aggregations

Predictor (org.hisp.dhis.predictor.Predictor)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Expression (org.hisp.dhis.expression.Expression)3 PeriodType (org.hisp.dhis.period.PeriodType)3 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 PredictionSummary (org.hisp.dhis.predictor.PredictionSummary)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 PredictorGroup (org.hisp.dhis.predictor.PredictorGroup)1 Test (org.junit.jupiter.api.Test)1