use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class PredictionDataValueFetcher method addValueToMap.
/**
* Adds a non-deleted value to the value map.
* <p>
* The two types of dimensional item object that are needed from the data
* value table are DataElement (the sum of all category option combos for
* that data element) and DataElementOperand (a particular combination of
* DataElement and CategoryOptionCombo).
*/
private void addValueToMap(DataValue dv, MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> map) {
Object value = getObjectValue(dv.getValue(), dv.getDataElement().getValueType());
if (value != null) {
DataElementOperand dataElementOperand = new DataElementOperand(dv.getDataElement(), dv.getCategoryOptionCombo());
addToMap(dataElementOperand, dataElementOperands, dv, value, map);
addToMap(dv.getDataElement(), dataElements, dv, value, map);
}
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class PredictionAnalyticsDataFetcher method getValuesInternal.
/**
* Queries analytics for data.
*/
private List<FoundDimensionItemValue> getValuesInternal(List<OrganisationUnit> orgUnits, Set<DimensionalItemObject> dimensionItems, boolean hasAttributeOptions) {
List<FoundDimensionItemValue> values = new ArrayList<>();
if (dimensionItems.isEmpty()) {
return values;
}
DataQueryParams.Builder paramsBuilder = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(periods)).withDataDimensionItems(Lists.newArrayList(dimensionItems)).withOrganisationUnits(orgUnits);
if (hasAttributeOptions) {
paramsBuilder.withAttributeOptionCombos(Collections.emptyList());
}
Grid grid = analyticsService.getAggregatedDataValues(paramsBuilder.build());
int peInx = grid.getIndexOfHeader(DimensionalObject.PERIOD_DIM_ID);
int dxInx = grid.getIndexOfHeader(DimensionalObject.DATA_X_DIM_ID);
int ouInx = grid.getIndexOfHeader(DimensionalObject.ORGUNIT_DIM_ID);
int aoInx = hasAttributeOptions ? grid.getIndexOfHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID) : 0;
int vlInx = grid.getWidth() - 1;
for (List<Object> row : grid.getRows()) {
String pe = (String) row.get(peInx);
String dx = (String) row.get(dxInx);
String ou = (String) row.get(ouInx);
String ao = hasAttributeOptions ? (String) row.get(aoInx) : null;
Object vl = row.get(vlInx);
Period period = periodLookup.get(pe);
DimensionalItemObject item = analyticsItemsLookup.get(dx);
OrganisationUnit orgUnit = orgUnitLookup.get(ou);
CategoryOptionCombo attributeOptionCombo = hasAttributeOptions ? cocLookup.get(ao, () -> categoryService.getCategoryOptionCombo(ao)) : null;
values.add(new FoundDimensionItemValue(orgUnit, period, attributeOptionCombo, item, vl));
}
return values;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class PredictionContextGenerator method getContexts.
/**
* Generates prediction contexts. Each prediction context contains all the
* values required to evaluate a predictor to (possibly) generate one
* prediction.
* <p>
* All the data used to generate contexts has the same organisation unit.
*
* @param outputPeriods output periods (predict within each period)
* @param values input prediction values (all with the same orgUnit)
* @param defaultCategoryOptionCombo system default cat option combo
* @return contexts for prediction evaluation
*/
public static List<PredictionContext> getContexts(List<Period> outputPeriods, List<FoundDimensionItemValue> values, CategoryOptionCombo defaultCategoryOptionCombo) {
List<PredictionContext> contexts = new ArrayList<>();
MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> aocMap = getAocMap(values, defaultCategoryOptionCombo);
for (Map.Entry<CategoryOptionCombo, MapMap<Period, DimensionalItemObject, Object>> e : aocMap.entrySet()) {
CategoryOptionCombo aoc = e.getKey();
MapMap<Period, DimensionalItemObject, Object> periodValueMap = e.getValue();
for (Period outputPeriod : outputPeriods) {
contexts.add(new PredictionContext(aoc, outputPeriod, periodValueMap, firstNonNull(periodValueMap.get(outputPeriod), new HashMap<>())));
}
}
return contexts;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class GeoFeatureService method getCoordinates.
/**
* Get the {@link GeoFeature} coordinate from {@link DimensionalItemObject}
* <p>
* The coordinate value is retrieved from {@link DimensionalItemObject}'s
* geoJsonAttribute value.
*
* @param feature the {@link GeoFeature}
* @param unit the {@link DimensionalItemObject} contains the coordinate
* values.
* @param geoJsonAttribute The {@link Attribute} which has
* {@link ValueType#GEOJSON} and is assigned to
* {@link OrganisationUnit}.
* @return the given {@link GeoFeature} with updated coordinate value and
* coordinate type.
*/
private void getCoordinates(GeoFeature feature, DimensionalItemObject unit, Attribute geoJsonAttribute) {
if (geoJsonAttribute == null) {
getCoordinates(feature, unit);
return;
}
if (!unit.getClass().isAssignableFrom(OrganisationUnit.class)) {
return;
}
OrganisationUnit organisationUnit = (OrganisationUnit) unit;
Optional<AttributeValue> geoJsonAttributeValue = organisationUnit.getAttributeValues().stream().filter(attributeValue -> attributeValue.getAttribute().getUid().equals(geoJsonAttribute.getUid())).findFirst();
if (!geoJsonAttributeValue.isPresent() || StringUtils.isBlank(geoJsonAttributeValue.get().getValue())) {
getCoordinates(feature, unit);
return;
}
try {
GeoJsonObject geoJsonObject = new ObjectMapper().readValue(geoJsonAttributeValue.get().getValue(), GeoJsonObject.class);
GeoFeature geoJsonFeature = geoJsonObject.accept(new GeoFeatureVisitor());
if (geoJsonFeature == null) {
return;
}
feature.setTy(geoJsonFeature.getTy());
feature.setCo(geoJsonFeature.getCo());
} catch (JsonProcessingException e) {
log.error(String.format("Couldn't read GeoJson value from organisationUnit %s: ", organisationUnit), e);
getCoordinates(feature, unit);
}
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class VectorFunction method visitSampledPeriods.
/**
* Visits each of the sample periods and compiles a list of the double
* values produced.
*/
private List<Double> visitSampledPeriods(ExprContext ctx, CommonExpressionVisitor visitor) {
ExpressionParams params = visitor.getParams();
ExpressionState state = visitor.getState();
List<Double> values = new ArrayList<>();
for (Period p : params.getSamplePeriods()) {
state.setItemsFound(0);
state.setItemValuesFound(0);
Map<DimensionalItemObject, Object> valueMap = firstNonNull(params.getPeriodValueMap().get(p), Collections.emptyMap());
Double value = visitWithValueMap(ctx, visitor, valueMap);
if ((params.getMissingValueStrategy() == SKIP_IF_ANY_VALUE_MISSING && state.getItemValuesFound() < state.getItemsFound()) || (params.getMissingValueStrategy() == SKIP_IF_ALL_VALUES_MISSING && state.getItemsFound() != 0 && state.getItemValuesFound() == 0)) {
value = null;
}
if (value != null) {
values.add(value);
}
}
return values;
}
Aggregations