Search in sources :

Example 1 with Statistic

use of org.activityinfo.ui.client.analysis.model.Statistic in project activityinfo by bedatadriven.

the class MeasurePane method showMenu.

private void showMenu(Element element, MeasureListItem item) {
    MeasureModel measure = item.getModel();
    Menu contextMenu = new Menu();
    // Edit the alias
    MenuItem editLabel = new MenuItem();
    editLabel.setText("Edit Label...");
    editLabel.addSelectionHandler(event -> editLabel(measure));
    contextMenu.add(editLabel);
    // Edit the formula...
    MenuItem editFormula = new MenuItem();
    editFormula.setText("Edit Formula...");
    editFormula.addSelectionHandler(event -> editFormula(measure));
    contextMenu.add(editFormula);
    contextMenu.add(new SeparatorMenuItem());
    // Choose the aggregation
    for (Statistic statistic : Statistic.values()) {
        CheckMenuItem aggregationItem = new CheckMenuItem(statistic.getLabel());
        aggregationItem.setChecked(measure.getStatistics().contains(statistic));
        aggregationItem.addCheckChangeHandler(event -> updateStatistic(measure, statistic, event.getChecked()));
        contextMenu.add(aggregationItem);
    }
    contextMenu.add(new SeparatorMenuItem());
    // Remove the dimension
    MenuItem remove = new MenuItem();
    remove.setText(I18N.CONSTANTS.remove());
    remove.addSelectionHandler(event -> removeMeasure(measure.getId()));
    contextMenu.add(remove);
    contextMenu.show(element, new Style.AnchorAlignment(Style.Anchor.BOTTOM, Style.Anchor.BOTTOM, true));
}
Also used : CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) Statistic(org.activityinfo.ui.client.analysis.model.Statistic) Style(com.sencha.gxt.core.client.Style) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) Menu(com.sencha.gxt.widget.core.client.menu.Menu) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) MeasureModel(org.activityinfo.ui.client.analysis.model.MeasureModel) ImmutableMeasureModel(org.activityinfo.ui.client.analysis.model.ImmutableMeasureModel)

Example 2 with Statistic

use of org.activityinfo.ui.client.analysis.model.Statistic in project activityinfo by bedatadriven.

the class MeasureResultBuilder method aggregate.

private void aggregate(TotalSubset totalSubset, GroupMap singleValuedDims, MultiDimSet multiValuedDims, MeasureVector values) {
    /*
         * For dimensions that can have multiple values, we need to run the aggregation
         * multiple times as a single value can be counted towards multiple categories.
         */
    for (MultiDimCategory multiDimCategory : multiValuedDims.build()) {
        int[] groupArray = singleValuedDims.copyOfGroupArray();
        /*
             * Exclude the values that do not belong to this multiDimCategory
             * by marking them as NaN.
             */
        double[] filteredValues = multiDimCategory.filter(values.getDoubleArray());
        /*
             * Sort the group and value arrays in tandem
             * (We can only do this in the inner loop because we need the original
             *  order for applying the multi-dimensional category filter)
             */
        HeapsortTandem.heapsortDescending(groupArray, filteredValues, filteredValues.length);
        /*
             * Now calculated all the required statistics.
             */
        for (Statistic statistic : measure.getModel().getStatistics()) {
            if (isMeasureValidForStatistic(values, statistic)) {
                aggregate(totalSubset, singleValuedDims, multiDimCategory, statistic, groupArray, filteredValues);
            }
        }
    }
}
Also used : Statistic(org.activityinfo.ui.client.analysis.model.Statistic)

Example 3 with Statistic

use of org.activityinfo.ui.client.analysis.model.Statistic in project activityinfo by bedatadriven.

the class MeasurePane method updateStatistic.

private void updateStatistic(MeasureModel measureModel, Statistic statistic, Tree.CheckState checked) {
    Set<Statistic> newSelection = new HashSet<>(measureModel.getStatistics());
    if (checked == Tree.CheckState.CHECKED) {
        newSelection.add(statistic);
    } else {
        newSelection.remove(statistic);
    }
    ImmutableMeasureModel updatedMeasure = ImmutableMeasureModel.builder().from(measureModel).statistics(newSelection).build();
    viewModel.updateModel(viewModel.getWorkingModel().withMeasure(updatedMeasure));
}
Also used : Statistic(org.activityinfo.ui.client.analysis.model.Statistic) HashSet(java.util.HashSet) ImmutableMeasureModel(org.activityinfo.ui.client.analysis.model.ImmutableMeasureModel)

Aggregations

Statistic (org.activityinfo.ui.client.analysis.model.Statistic)3 ImmutableMeasureModel (org.activityinfo.ui.client.analysis.model.ImmutableMeasureModel)2 Style (com.sencha.gxt.core.client.Style)1 CheckMenuItem (com.sencha.gxt.widget.core.client.menu.CheckMenuItem)1 Menu (com.sencha.gxt.widget.core.client.menu.Menu)1 MenuItem (com.sencha.gxt.widget.core.client.menu.MenuItem)1 SeparatorMenuItem (com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem)1 HashSet (java.util.HashSet)1 MeasureModel (org.activityinfo.ui.client.analysis.model.MeasureModel)1