use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.
the class CalculatedIndicatorsQuery method queryAttributeGroups.
private void queryAttributeGroups() {
Set<Integer> groupIds = Sets.newHashSet();
for (Dimension dim : query.getDimensions()) {
if (dim instanceof AttributeGroupDimension) {
AttributeGroupDimension groupDim = (AttributeGroupDimension) dim;
groupIds.add(groupDim.getAttributeGroupId());
}
}
SqlQuery.select().appendColumn("g.attributeGroupId", "groupId").appendColumn("g.name", "groupName").appendColumn("a.attributeId").appendColumn("a.name").appendColumn("a.sortOrder").from(Tables.ATTRIBUTE, "a").leftJoin(Tables.ATTRIBUTE_GROUP, "g").on("a.attributeGroupId=g.attributeGroupId").where("a.attributeGroupId").in(groupIds).execute(queryContext.getExecutionContext().getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
for (SqlResultSetRow row : results.getRows()) {
int groupId = row.getInt("groupId");
int attributeId = row.getInt("attributeId");
int sortOrder = row.getInt("sortOrder");
String attributeName = row.getString("name");
attributes.put(groupId, new EntityCategory(attributeId, attributeName, sortOrder));
}
querySites();
}
});
}
use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.
the class CalculatedIndicatorsQuery method aggregateSites.
private void aggregateSites(SiteResult result) {
for (int i = 0; i != result.getTotalLength(); ++i) {
SiteDTO site = result.getData().get(i);
// Now loop over each value
for (EntityCategory indicator : indicatorMap.values()) {
Double value = site.getIndicatorDoubleValue(indicator.getId());
if (value != null && !Double.isNaN(value) && !Double.isInfinite(value)) {
Bucket bucket = new Bucket(value);
bucket.setAggregationMethod(indicatorAggregationMap.get(indicator.getId()));
bucket.setCategory(new Dimension(DimensionType.Target), TargetCategory.REALIZED);
if (query.isPivotedBy(DimensionType.Indicator)) {
bucket.setCategory(new Dimension(DimensionType.Indicator), indicator);
}
for (int j = 0; j != dimAccessors.size(); ++j) {
bucket.setCategory(dimAccessors.get(j).getDimension(), dimAccessors.get(j).getCategory(site));
}
queryContext.addBucket(bucket);
}
}
}
}
use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.
the class PivotTableDataBuilder method find.
protected PivotTableData.Axis find(PivotTableData.Axis axis, Iterator<Dimension> dimensionIterator, Map<Dimension, Comparator<PivotTableData.Axis>> comparators, Bucket result) {
Dimension childDimension = dimensionIterator.next();
DimensionCategory category = result.getCategory(childDimension);
PivotTableData.Axis child = null;
child = axis.getChild(category);
if (child == null) {
String categoryLabel;
if (category == null) {
categoryLabel = I18N.CONSTANTS.emptyDimensionCategory();
} else {
categoryLabel = childDimension.getLabel(category);
if (categoryLabel == null) {
categoryLabel = category.getLabel();
}
}
child = axis.addChild(childDimension, result.getCategory(childDimension), categoryLabel, comparators.get(childDimension));
}
if (dimensionIterator.hasNext()) {
return find(child, dimensionIterator, comparators, result);
} else {
return child;
}
}
use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.
the class PivotTableDataBuilder method build.
public PivotTableData build(List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
PivotTableData table = new PivotTableData();
Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(Iterables.concat(rowDims, colDims));
for (Bucket bucket : buckets) {
PivotTableData.Axis column = colDims.isEmpty() ? table.getRootColumn() : find(table.getRootColumn(), colDims.iterator(), comparators, bucket);
PivotTableData.Axis row = rowDims.isEmpty() ? table.getRootRow() : find(table.getRootRow(), rowDims.iterator(), comparators, bucket);
row.setValue(column, bucket.doubleValue());
}
return table;
}
use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.
the class PivotTestResource method command.
private PivotSites command(Report model, PivotReportElement<?> element, boolean newEngine, boolean showDetails) {
Filter effectiveFilter = new Filter(model.getFilter(), element.getFilter());
Set<Dimension> dimensions = Sets.newHashSet();
for (Dimension dimension : element.allDimensions()) {
dimensions.add(dimension);
}
if (showDetails) {
dimensions.add(new Dimension(DimensionType.Site));
dimensions.add(new Dimension(DimensionType.Activity));
dimensions.add(new Dimension(DimensionType.Database));
dimensions.add(new Dimension(DimensionType.Indicator));
}
PivotSites command = new PivotSites(dimensions, effectiveFilter);
if (newEngine) {
return command;
} else {
return new OldPivotSites(command);
}
}
Aggregations