use of org.hisp.dhis.common.ListMap in project dhis2-core by dhis2.
the class DefaultPredictionService method getSamplePeriodsMap.
/**
* Creates a map relating each output period to a list of sample periods
* from which the sample data is to be drawn. Sample periods returned for
* each output period are in order from older to newer, so any prediction
* results can be brought forward if they are to be used in later period
* predictions.
*/
private ListMap<Period, Period> getSamplePeriodsMap(List<Period> outputPeriods, Predictor predictor) {
int sequentialCount = predictor.getSequentialSampleCount();
int annualCount = predictor.getAnnualSampleCount();
int skipCount = firstNonNull(predictor.getSequentialSkipCount(), 0);
PeriodType periodType = predictor.getPeriodType();
ListMap<Period, Period> samplePeriodsMap = new ListMap<>();
for (Period outputPeriod : outputPeriods) {
samplePeriodsMap.put(outputPeriod, new ArrayList<>());
Period p = periodType.getPreviousPeriod(outputPeriod, skipCount);
for (int i = skipCount; i < sequentialCount; i++) {
p = periodType.getPreviousPeriod(p);
samplePeriodsMap.putValue(outputPeriod, p);
}
for (int year = 1; year <= annualCount; year++) {
Period pPrev = periodType.getPreviousYearsPeriod(outputPeriod, year);
Period pNext = pPrev;
samplePeriodsMap.putValue(outputPeriod, pPrev);
for (int i = 0; i < sequentialCount; i++) {
pPrev = periodType.getPreviousPeriod(pPrev);
pNext = periodType.getNextPeriod(pNext);
samplePeriodsMap.putValue(outputPeriod, pPrev);
samplePeriodsMap.putValue(outputPeriod, pNext);
}
}
}
return samplePeriodsMap;
}
use of org.hisp.dhis.common.ListMap in project dhis2-core by dhis2.
the class PartitionUtils method getPeriodTypePeriodMap.
/**
* Creates a mapping between period type name and period for the given
* periods.
*/
public static ListMap<String, DimensionalItemObject> getPeriodTypePeriodMap(Collection<DimensionalItemObject> periods) {
ListMap<String, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject period : periods) {
String periodTypeName = ((Period) period).getPeriodType().getName();
map.putValue(periodTypeName, period);
}
return map;
}
Aggregations