Search in sources :

Example 61 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class ListGrid method addCumulativeColumn.

@Override
public Grid addCumulativeColumn(int columnIndex, boolean addHeader) {
    verifyGridState();
    List<Object> column = getColumn(columnIndex);
    List<Object> cumulativeColumn = new ArrayList<>();
    double sum = 0d;
    for (Object value : column) {
        double number = value != null ? Double.parseDouble(String.valueOf(value)) : 0d;
        sum += number;
        cumulativeColumn.add(sum);
    }
    addColumn(cumulativeColumn);
    if (addHeader && columnIndex < headers.size()) {
        GridHeader header = headers.get(columnIndex);
        if (header != null) {
            GridHeader regressionHeader = new GridHeader(header.getName() + CUMULATIVE_SUFFIX, header.getColumn() + CUMULATIVE_SUFFIX, header.getValueType(), header.isHidden(), header.isMeta());
            addHeader(regressionHeader);
        }
    }
    return this;
}
Also used : ArrayList(java.util.ArrayList) GridHeader(org.hisp.dhis.common.GridHeader)

Example 62 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class ListGrid method toString.

// -------------------------------------------------------------------------
// toString
// -------------------------------------------------------------------------
@Override
public String toString() {
    StringBuilder builder = new StringBuilder("[\n");
    if (headers != null && headers.size() > 0) {
        List<String> headerNames = new ArrayList<>();
        for (GridHeader header : headers) {
            headerNames.add(header.getName());
        }
        builder.append(headerNames).append("\n");
    }
    for (List<Object> row : grid) {
        builder.append(row).append("\n");
    }
    return builder.append("]").toString();
}
Also used : ArrayList(java.util.ArrayList) GridHeader(org.hisp.dhis.common.GridHeader)

Example 63 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class ListGrid method addHeaders.

@Override
public Grid addHeaders(SqlRowSet rs) {
    SqlRowSetMetaData rsmd = rs.getMetaData();
    int columnNo = rsmd.getColumnCount();
    for (int i = 1; i <= columnNo; i++) {
        addHeader(new GridHeader(rsmd.getColumnLabel(i), false, false));
    }
    return this;
}
Also used : SqlRowSetMetaData(org.springframework.jdbc.support.rowset.SqlRowSetMetaData) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)63 Grid (org.hisp.dhis.common.Grid)41 ListGrid (org.hisp.dhis.system.grid.ListGrid)31 Test (org.junit.jupiter.api.Test)17 ArrayList (java.util.ArrayList)15 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)13 HashMap (java.util.HashMap)9 List (java.util.List)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 Map (java.util.Map)6 QueryItem (org.hisp.dhis.common.QueryItem)6 LinkedHashSet (java.util.LinkedHashSet)5 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 RepeatableStageParams (org.hisp.dhis.common.RepeatableStageParams)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3