Search in sources :

Example 6 with Predictor

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

the class PredictorObjectBundleHook method preUpdate.

@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, 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)

Example 7 with Predictor

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

the class DhisConvenienceTest method createPredictor.

/**
     * Creates a Predictor
     *
     * @param output                the data element where the predictor stores its predictions
     * @param combo                 the category option combo (or null) under which the predictors are stored
     * @param uniqueCharacter       A unique character to identify the object.
     * @param generator             The right side expression.
     * @param skipTest              The skiptest expression
     * @param periodType            The period-type.
     * @param organisationUnitLevel The unit level of organisations to be
     *                              evaluated by this rule.
     * @param sequentialSampleCount How many sequential past periods to sample.
     * @param annualSampleCount     How many years of past periods to sample.
     * @param sequentialSkipCount   How many periods in the current year to skip
     */
public static Predictor createPredictor(DataElement output, DataElementCategoryOptionCombo combo, String uniqueCharacter, Expression generator, Expression skipTest, PeriodType periodType, OrganisationUnitLevel organisationUnitLevel, int sequentialSampleCount, int sequentialSkipCount, int annualSampleCount) {
    Predictor predictor = new Predictor();
    Set<OrganisationUnitLevel> orgUnitlevels = Sets.newHashSet(organisationUnitLevel);
    predictor.setAutoFields();
    predictor.setOutput(output);
    predictor.setOutputCombo(combo);
    predictor.setName("Predictor" + uniqueCharacter);
    predictor.setDescription("Description" + uniqueCharacter);
    predictor.setGenerator(generator);
    predictor.setSampleSkipTest(skipTest);
    predictor.setPeriodType(periodType);
    predictor.setOrganisationUnitLevels(orgUnitlevels);
    predictor.setSequentialSampleCount(sequentialSampleCount);
    predictor.setAnnualSampleCount(annualSampleCount);
    predictor.setSequentialSkipCount(sequentialSkipCount);
    return predictor;
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel)

Example 8 with Predictor

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

the class DhisConvenienceTest method createPredictor.

/**
 * Creates a Predictor
 *
 * @param output The data element where the predictor stores its predictions
 * @param combo The category option combo (or null) under which the
 *        predictors are stored
 * @param uniqueCharacter A unique character to identify the object.
 * @param generator The right side expression.
 * @param skipTest The skiptest expression
 * @param periodType The period-type.
 * @param organisationUnitLevels The organisation unit levels to be
 *        evaluated by this rule.
 * @param sequentialSampleCount How many sequential past periods to sample.
 * @param annualSampleCount How many years of past periods to sample.
 * @param sequentialSkipCount How many periods in the current year to skip
 */
public static Predictor createPredictor(DataElement output, CategoryOptionCombo combo, String uniqueCharacter, Expression generator, Expression skipTest, PeriodType periodType, Set<OrganisationUnitLevel> organisationUnitLevels, int sequentialSampleCount, int sequentialSkipCount, int annualSampleCount) {
    Predictor predictor = new Predictor();
    predictor.setAutoFields();
    predictor.setOutput(output);
    predictor.setOutputCombo(combo);
    predictor.setName("Predictor" + uniqueCharacter);
    predictor.setDescription("Description" + uniqueCharacter);
    predictor.setGenerator(generator);
    predictor.setSampleSkipTest(skipTest);
    predictor.setPeriodType(periodType);
    predictor.setOrganisationUnitLevels(organisationUnitLevels);
    predictor.setOrganisationUnitDescendants(OrganisationUnitDescendants.DESCENDANTS);
    predictor.setSequentialSampleCount(sequentialSampleCount);
    predictor.setAnnualSampleCount(annualSampleCount);
    predictor.setSequentialSkipCount(sequentialSkipCount);
    return predictor;
}
Also used : Predictor(org.hisp.dhis.predictor.Predictor)

Example 9 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')")
@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)

Example 10 with Predictor

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

the class TranslationServiceTest method testPredictorTranslations.

@Test
void testPredictorTranslations() {
    DataElement dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    manager.save(dataElementA);
    manager.save(dataElementB);
    manager.save(dataElementX);
    OrganisationUnitLevel orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    manager.save(orgUnitLevel1);
    CategoryOptionCombo defaultCombo = categoryService.getDefaultCategoryOptionCombo();
    PeriodType periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
    Expression expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
    expressionA.setTranslations(Sets.newHashSet(new Translation(locale.getLanguage(), "DESCRIPTION", "translated descriptionA")));
    Expression expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
    expressionB.setTranslations(Sets.newHashSet(new Translation(locale.getLanguage(), "DESCRIPTION", "translated descriptionB")));
    Predictor predictor = createPredictor(dataElementX, defaultCombo, "A", expressionA, expressionB, periodTypeMonthly, orgUnitLevel1, 6, 1, 0);
    manager.save(predictor);
    manager.updateTranslations(predictor, Sets.newHashSet(new Translation(locale.getLanguage(), "NAME", "translated Predictor Name")));
    predictor = manager.get(Predictor.class, predictor.getUid());
    assertEquals("translated Predictor Name", predictor.getDisplayName());
    assertEquals("translated descriptionA", predictor.getGenerator().getDisplayDescription());
    assertEquals("translated descriptionB", predictor.getSampleSkipTest().getDisplayDescription());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) PeriodType(org.hisp.dhis.period.PeriodType) Expression(org.hisp.dhis.expression.Expression) Predictor(org.hisp.dhis.predictor.Predictor) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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