use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxDataElementController method getObjectList.
//--------------------------------------------------------------------------
// GET
//--------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getObjectList(MinMaxDataElementQueryParams query) throws QueryParserException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
query.setFilters(filters);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<MinMaxDataElement> minMaxDataElements = minMaxService.getMinMaxDataElements(query);
RootNode rootNode = NodeUtils.createMetadata();
if (!query.isSkipPaging()) {
query.setTotal(minMaxService.countMinMaxDataElements(query));
rootNode.addChild(NodeUtils.createPager(query.getPager()));
}
rootNode.addChild(fieldFilterService.filter(MinMaxDataElement.class, minMaxDataElements, fields));
return rootNode;
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxDataElementController method postJsonObject.
//--------------------------------------------------------------------------
// POST
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_MINMAX_DATAELEMENT_ADD')")
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
MinMaxDataElement minMax = renderService.fromJson(request.getInputStream(), MinMaxDataElement.class);
validate(minMax);
minMax = getReferences(minMax);
MinMaxDataElement persisted = minMaxService.getMinMaxDataElement(minMax.getSource(), minMax.getDataElement(), minMax.getOptionCombo());
if (Objects.isNull(persisted)) {
minMaxService.addMinMaxDataElement(minMax);
} else {
persisted.mergeWith(minMax);
minMaxService.updateMinMaxDataElement(persisted);
}
WebMessage webMessage = new WebMessage();
webMessage.setHttpStatus(HttpStatus.CREATED);
webMessage.setStatus(Status.OK);
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxDataElementBatchHandler method mapRow.
@Override
public MinMaxDataElement mapRow(ResultSet resultSet) throws SQLException {
MinMaxDataElement mde = new MinMaxDataElement();
mde.setMin(resultSet.getInt("minimumvalue"));
mde.setMax(resultSet.getInt("maximumvalue"));
mde.setGenerated(resultSet.getBoolean("generatedvalue"));
return mde;
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxOutlierAnalysisServiceTest method testGetFindOutliers.
// ----------------------------------------------------------------------
// Business logic tests
// ----------------------------------------------------------------------
@Test
public void testGetFindOutliers() {
dataValueA = createDataValue(dataElementA, periodI, organisationUnitA, "41", categoryOptionCombo);
dataValueB = createDataValue(dataElementA, periodJ, organisationUnitA, "-41", categoryOptionCombo);
dataValueService.addDataValue(createDataValue(dataElementA, periodA, organisationUnitA, "5", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodB, organisationUnitA, "-5", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodC, organisationUnitA, "5", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodD, organisationUnitA, "-5", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodE, organisationUnitA, "10", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodF, organisationUnitA, "-10", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodG, organisationUnitA, "13", categoryOptionCombo));
dataValueService.addDataValue(createDataValue(dataElementA, periodH, organisationUnitA, "-13", categoryOptionCombo));
dataValueService.addDataValue(dataValueA);
dataValueService.addDataValue(dataValueB);
minMaxDataElement = new MinMaxDataElement(organisationUnitA, dataElementA, categoryOptionCombo, -40, 40, false);
minMaxDataElementService.addMinMaxDataElement(minMaxDataElement);
List<Period> periods = new ArrayList<>();
periods.add(periodI);
periods.add(periodJ);
periods.add(periodA);
periods.add(periodE);
List<DeflatedDataValue> result = minMaxOutlierAnalysisService.analyse(Lists.newArrayList(organisationUnitA), dataElementsA, periods, null, from);
assertEquals(2, result.size());
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChartHistory.
@Override
public JFreeChart getJFreeChartHistory(DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, Period lastPeriod, OrganisationUnit organisationUnit, int historyLength, I18nFormat format) {
lastPeriod = periodService.reloadPeriod(lastPeriod);
List<Period> periods = periodService.getPeriods(lastPeriod, historyLength);
MinMaxDataElement minMax = minMaxDataElementService.getMinMaxDataElement(organisationUnit, dataElement, categoryOptionCombo);
UnivariateInterpolator interpolator = new SplineInterpolator();
Integer periodCount = 0;
List<Double> x = new ArrayList<>();
List<Double> y = new ArrayList<>();
// ---------------------------------------------------------------------
// DataValue, MinValue and MaxValue DataSets
// ---------------------------------------------------------------------
DefaultCategoryDataset dataValueDataSet = new DefaultCategoryDataset();
DefaultCategoryDataset metaDataSet = new DefaultCategoryDataset();
for (Period period : periods) {
++periodCount;
period.setName(format.formatPeriod(period));
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
double value = 0;
if (dataValue != null && dataValue.getValue() != null && MathUtils.isNumeric(dataValue.getValue())) {
value = Double.parseDouble(dataValue.getValue());
x.add(periodCount.doubleValue());
y.add(value);
}
dataValueDataSet.addValue(value, dataElement.getShortName(), period.getName());
if (minMax != null) {
metaDataSet.addValue(minMax.getMin(), "Min value", period.getName());
metaDataSet.addValue(minMax.getMax(), "Max value", period.getName());
}
}
if (// minimum 3 points required for interpolation
x.size() >= 3) {
periodCount = 0;
double[] xa = getArray(x);
int min = MathUtils.getMin(xa).intValue();
int max = MathUtils.getMax(xa).intValue();
try {
UnivariateFunction function = interpolator.interpolate(xa, getArray(y));
for (Period period : periods) {
if (++periodCount >= min && periodCount <= max) {
metaDataSet.addValue(function.value(periodCount), "Regression value", period.getName());
}
}
} catch (MathRuntimeException ex) {
throw new RuntimeException("Failed to interpolate", ex);
}
}
// ---------------------------------------------------------------------
// Plots
// ---------------------------------------------------------------------
CategoryPlot plot = getCategoryPlot(dataValueDataSet, getBarRenderer(), PlotOrientation.VERTICAL, CategoryLabelPositions.UP_45);
plot.setDataset(1, metaDataSet);
plot.setRenderer(1, getLineRenderer());
JFreeChart jFreeChart = getBasicJFreeChart(plot);
return jFreeChart;
}
Aggregations