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