Search in sources :

Example 16 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultEventAnalyticsService method getEvents.

@Override
public Grid getEvents(EventQueryParams params) {
    securityManager.decideAccessEventQuery(params);
    queryPlanner.validate(params);
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    Grid grid = new ListGrid();
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    grid.addHeader(new GridHeader(ITEM_EVENT, NAME_EVENT, ValueType.TEXT, String.class.getName(), false, true)).addHeader(new GridHeader(ITEM_PROGRAM_STAGE, NAME_PROGRAM_STAGE, ValueType.TEXT, String.class.getName(), false, true)).addHeader(new GridHeader(ITEM_EVENT_DATE, NAME_EVENT_DATE, ValueType.DATE, Date.class.getName(), false, true)).addHeader(new GridHeader(ITEM_LONGITUDE, NAME_LONGITUDE, ValueType.NUMBER, Double.class.getName(), false, true)).addHeader(new GridHeader(ITEM_LATITUDE, NAME_LATITUDE, ValueType.NUMBER, Double.class.getName(), false, true)).addHeader(new GridHeader(ITEM_ORG_UNIT_NAME, NAME_ORG_UNIT_NAME, ValueType.TEXT, String.class.getName(), false, true)).addHeader(new GridHeader(ITEM_ORG_UNIT_CODE, NAME_ORG_UNIT_CODE, ValueType.TEXT, String.class.getName(), false, true));
    for (DimensionalObject dimension : params.getDimensions()) {
        grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDisplayName(), ValueType.TEXT, String.class.getName(), false, true));
    }
    for (QueryItem item : params.getItems()) {
        grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName(), item.getValueType(), item.getTypeAsString(), false, true, item.getOptionSetUid(), item.getLegendSetUid()));
    }
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    Timer timer = new Timer().start().disablePrint();
    params = queryPlanner.planEventQuery(params);
    timer.getSplitTime("Planned event query, got partitions: " + params.getPartitions());
    long count = 0;
    if (params.getPartitions().hasAny()) {
        if (params.isPaging()) {
            count += eventAnalyticsManager.getEventCount(params);
        }
        eventAnalyticsManager.getEvents(params, grid, queryPlanner.getMaxLimit());
        timer.getTime("Got events " + grid.getHeight());
    }
    // ---------------------------------------------------------------------
    // Meta-data
    // ---------------------------------------------------------------------
    addMetadata(params, grid);
    if (params.isPaging()) {
        Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
        grid.getMetaData().put(AnalyticsMetaDataKey.PAGER.getKey(), pager);
    }
    return grid;
}
Also used : Timer(org.hisp.dhis.util.Timer) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 17 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testHandleGridForDataValueSet.

@Test
public void testHandleGridForDataValueSet() {
    IndicatorType itA = new IndicatorType();
    DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
    ocA.setUid("ceabcdefghA");
    DataElement dxA = createDataElement('A');
    dxA.setUid("deabcdefghA");
    dxA.setValueType(ValueType.INTEGER);
    DataElement dxB = createDataElement('B');
    dxB.setUid("deabcdefghB");
    dxB.setValueType(ValueType.NUMBER);
    Indicator dxC = createIndicator('C', itA);
    dxC.setUid("deabcdefghC");
    dxC.setDecimals(0);
    dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
    Indicator dxD = createIndicator('D', itA);
    dxD.setUid("deabcdefghD");
    dxD.setDecimals(2);
    dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
    DataElementOperand dxE = new DataElementOperand(dxA, ocA);
    DataElementOperand dxF = new DataElementOperand(dxB, ocA);
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
    assertEquals(4, grid.getWidth());
    assertEquals(6, grid.getHeight());
    AnalyticsUtils.handleGridForDataValueSet(params, grid);
    assertEquals(6, grid.getWidth());
    assertEquals(6, grid.getHeight());
    assertEquals("deabcdefghA", grid.getRow(0).get(0));
    assertNull(grid.getRow(0).get(3));
    assertNull(grid.getRow(0).get(4));
    assertEquals(1, grid.getRow(0).get(5));
    assertEquals("deabcdefghB", grid.getRow(1).get(0));
    assertNull(grid.getRow(1).get(3));
    assertNull(grid.getRow(1).get(4));
    assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
    assertEquals("deabcdefghC", grid.getRow(2).get(0));
    assertNull(grid.getRow(2).get(3));
    assertEquals("ceabcdefghA", grid.getRow(2).get(4));
    assertEquals(3, grid.getRow(2).get(5));
    assertEquals("deabcdefghD", grid.getRow(3).get(0));
    assertEquals("ceabcdefghB", grid.getRow(3).get(3));
    assertNull(grid.getRow(3).get(4));
    assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
    assertEquals("deabcdefghA", grid.getRow(4).get(0));
    assertEquals("ceabcdefghA", grid.getRow(4).get(3));
    assertNull(grid.getRow(4).get(4));
    assertEquals(5, grid.getRow(4).get(5));
    assertEquals("deabcdefghB", grid.getRow(5).get(0));
    assertEquals("ceabcdefghA", grid.getRow(5).get(3));
    assertNull(grid.getRow(5).get(4));
    assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 18 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetAggregatedDataValueMapping.

@Test
public void testGetAggregatedDataValueMapping() {
    Grid grid = new ListGrid();
    grid.addRow();
    grid.addValue("de1");
    grid.addValue("ou2");
    grid.addValue("pe1");
    grid.addValue(3);
    grid.addRow();
    grid.addValue("de2");
    grid.addValue("ou3");
    grid.addValue("pe2");
    grid.addValue(5);
    Map<String, Object> map = AnalyticsUtils.getAggregatedDataValueMapping(grid);
    assertEquals(3, map.get("de1" + DIMENSION_SEP + "ou2" + DIMENSION_SEP + "pe1"));
    assertEquals(5, map.get("de2" + DIMENSION_SEP + "ou3" + DIMENSION_SEP + "pe2"));
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 19 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class ReportTableTest method testGetGrid.

@Test
public void testGetGrid() {
    ReportTable reportTable = new ReportTable("Grid table", dataElements, new ArrayList<>(), new ArrayList<>(), periods, Lists.newArrayList(unitB, unitC), true, true, false, null, null, null);
    reportTable.init(null, null, null, null, null, i18nFormat);
    List<String> columnDims = reportTable.getColumnDimensions();
    List<String> rowDims = reportTable.getRowDimensions();
    assertEquals(2, columnDims.size());
    assertEquals(1, rowDims.size());
    assertTrue(columnDims.contains(DimensionalObject.DATA_X_DIM_ID));
    assertTrue(columnDims.contains(DimensionalObject.PERIOD_DIM_ID));
    assertTrue(rowDims.contains(DimensionalObject.ORGUNIT_DIM_ID));
    Map<String, Object> valueMap = new HashMap<>();
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 11);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 21);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 12);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 22);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 13);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 23);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 14);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 24);
    DisplayProperty property = DisplayProperty.NAME;
    Grid grid = reportTable.getGrid(new ListGrid(), valueMap, property, false);
    assertEquals(8, grid.getWidth());
    assertEquals(8, grid.getHeaders().size());
    assertEquals(2, grid.getHeight());
    assertEquals(unitB.getUid(), grid.getValue(0, 0));
    assertEquals(unitB.getDisplayProperty(property), grid.getValue(0, 1));
    assertEquals(unitB.getCode(), grid.getValue(0, 2));
    assertEquals(unitB.getDescription(), grid.getValue(0, 3));
    assertEquals(11, grid.getValue(0, 4));
    assertEquals(12, grid.getValue(0, 5));
    assertEquals(13, grid.getValue(0, 6));
    assertEquals(14, grid.getValue(0, 7));
    assertEquals(unitC.getUid(), grid.getValue(1, 0));
    assertEquals(unitC.getDisplayProperty(property), grid.getValue(1, 1));
    assertEquals(unitC.getCode(), grid.getValue(1, 2));
    assertEquals(unitC.getDescription(), grid.getValue(1, 3));
    assertEquals(21, grid.getValue(1, 4));
    assertEquals(22, grid.getValue(1, 5));
    assertEquals(23, grid.getValue(1, 6));
    assertEquals(24, grid.getValue(1, 7));
}
Also used : DisplayProperty(org.hisp.dhis.common.DisplayProperty) HashMap(java.util.HashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class ReportTableTest method testGetGridHideEmptyColumns.

@Test
public void testGetGridHideEmptyColumns() {
    ReportTable reportTable = new ReportTable("Grid table", dataElements, new ArrayList<>(), new ArrayList<>(), periods, Lists.newArrayList(unitA, unitB), true, true, false, null, null, null);
    Map<String, Object> valueMap = new HashMap<>();
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitA.getDimensionItem(), 11);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 21);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitA.getDimensionItem(), 13);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 23);
    reportTable.init(null, null, null, null, null, i18nFormat);
    Grid grid = reportTable.getGrid(new ListGrid(), valueMap, DisplayProperty.NAME, false);
    assertEquals(8, grid.getWidth());
    reportTable.setHideEmptyColumns(true);
    grid = reportTable.getGrid(new ListGrid(), valueMap, DisplayProperty.NAME, false);
    // Removed description column and two data columns
    assertEquals(5, grid.getWidth());
}
Also used : HashMap(java.util.HashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)24 Grid (org.hisp.dhis.common.Grid)16 GridHeader (org.hisp.dhis.common.GridHeader)9 DimensionalObject (org.hisp.dhis.common.DimensionalObject)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)5 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 List (java.util.List)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DisplayProperty (org.hisp.dhis.common.DisplayProperty)2 Pager (org.hisp.dhis.common.Pager)2 QueryItem (org.hisp.dhis.common.QueryItem)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)2