MinMaxOutlierAnalysisService implements MinMaxDataAnalysisService { @Override public List<DeflatedDataValue> analyse( Collection<OrganisationUnit> parents, Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor, Date from ) { Set<DataElement> elements = dataElements.stream() .filter( de -> ValueType.NUMERIC_TYPES.contains( de.getValueType() ) ) .collect( Collectors.toSet() ); Set<CategoryOptionCombo> categoryOptionCombos = new HashSet<>(); for ( DataElement dataElement : elements ) { categoryOptionCombos.addAll( dataElement.getCategoryOptionCombos() ); } log.debug( "Starting min-max analysis, no of data elements: " + elements.size() + ", no of parent org units: " + parents.size() ); return dataAnalysisStore.getMinMaxViolations( elements, categoryOptionCombos, periods, parents, MAX_OUTLIERS ); } MinMaxOutlierAnalysisService( DataAnalysisStore dataAnalysisStore,
        MinMaxDataElementService minMaxDataElementService, BatchHandlerFactory batchHandlerFactory ); @Override List<DeflatedDataValue> analyse( Collection<OrganisationUnit> parents,
        Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor, Date from ); @Override void generateMinMaxValues( OrganisationUnit parent, Collection<DataElement> dataElements, Double stdDevFactor );  }
@Test public void testAnalyse() { 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() ); }