Add aggregations representing the facets selected
339459
def aggregate(self, search):
        
        for f, facet in self.facets.items():
            agg = facet.get_aggregation()
            if isinstance(agg, Bucket):
                search.aggs.bucket(f, agg)
            elif isinstance(agg, Pipeline):
                search.aggs.pipeline(f, agg)
            else:
                search.aggs.metric(f, agg)
471750
def choose_aspect(decision):
    """"""
    choice = []
    for i in range(len(ASPECTSTYLES)):
        if (i < decision):
            choice = ASPECTSTYLES[i]
    return choice
781653
function make_bucket_agg(groupby, subagg) {
    var bucket_agg = {};
    groupby.forEach(function(field) {
        bucket_agg[field] = {
            terms: {
                field: field,
                size: _calculate_size_for_aggregation(subagg)
            }
        };
    });

    return _.reduceRight(bucket_agg, function nest(memo, value, key) {
        var obj = {};

        if (!_.isEmpty(memo)) {
            value.aggregations = memo;
        }

        obj[key] = value;

        return obj;
    }, subagg);
}
826369
def aggregate_tile(cells, ti, tj, aggregate, params, metadata, layout, summary):
  
  tile = []
  keys = cells.keys()
  for i,key in enumerate(keys):
    print("cell", i+1, "/", len(keys), end='\r')
    cell_json = aggregate(cells[key], params, metadata, layout, summary)
    tile.append({"aggregate":cell_json, "i":int(key[0]), "j":int(key[1])})
  return tile
1021842
function aggregateParams(_, pulse) {
  var key    = _.field,
  value  = _.value,
      op     = (_.op === 'count' ? '__count__' : _.op) || 'sum',
      fields = accessorFields(key).concat(accessorFields(value)),
      keys   = pivotKeys(key, _.limit || 0, pulse);

  return {
    key:      _.key,
    groupby:  _.groupby,
    ops:      keys.map(function() { return op; }),
    fields:   keys.map(function(k) { return get(k, key, value, fields); }),
    as:       keys.map(function(k) { return k + ''; }),
    modified: _.modified.bind(_)
  };
}
543847
private AggregationBuilder buildSelectAggregations(AggregationBuilder aggregationBuilder,
            SelectStatement selectStatement, EntityMetadata entityMetadata)
    {
        Expression expression = ((SelectClause) selectStatement.getSelectClause()).getSelectExpression();

        if (expression instanceof CollectionExpression)
        {
            aggregationBuilder = appendAggregation((CollectionExpression) expression, entityMetadata,
                    aggregationBuilder);
        }
        else
        {
            if (isAggregationExpression(expression) && checkIfKeyExists(expression.toParsedText()))
                aggregationBuilder.subAggregation(getMetricsAggregation(expression, entityMetadata));
        }
        return aggregationBuilder;
    }
168113
@Override
  public void aggregate()
  {
    final IndexedInts keys = keySelector.getRow();
    for (int i = 0; i < valueSelectors.length; i++) {
      values[i] = valueSelectors[i].getDouble();
    }
    synchronized (this) {
      for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
        final String key = keySelector.lookupName(keys.get(i));
        sketch.update(key, values);
      }
    }
  }
1139270
def _attach_dim_scales(self):
        """"""
        for name, var in self.variables.items():
            if name not in self.dimensions:
                for n, dim in enumerate(var.dimensions):
                    var._h5ds.dims[n].attach_scale(self._all_h5groups[dim])

        for subgroup in self.groups.values():
            subgroup._attach_dim_scales()
409014
function combineStatsAndIndexes(done, results) {
  var indexes = results.getIndexes;
  var stats = results.getIndexStats;
  var sizes = results.getIndexSizes;
  _.each(indexes, function(idx, i) {
    _.assign(indexes[i], stats[idx.name]);
    _.assign(indexes[i], sizes[idx.name]);
  });
  done(null, indexes);
}
63357
def _get_selected_items(self):
        """"""
        selection = self.get_selection()
        if selection.get_mode() != gtk.SELECTION_MULTIPLE:
            raise AttributeError('selected_items only valid for '
                                 'select_multiple')
        model, selected_paths = selection.get_selected_rows()
        result = []
        for path in selected_paths:
            result.append(model[path][0])
        return result
791078
def annotate(self, *args, **kwargs):
        
        obj = self._clone()

        for arg in args:
            if isinstance(arg, Facet):
                obj._facets.append(arg)
            elif isinstance(arg, six.string_types):
                obj._facets.append(TermFacet(arg.replace("__", ".")))
            elif isinstance(arg, Agg):
                obj._aggs.append(arg)
            elif isinstance(arg, six.string_types):
                obj._facets.append(TermFacet(arg.replace("__", ".")))
            else:
                raise NotImplementedError("invalid type")


        # Add the aggregates/facet to the query
        for name, field in kwargs.items():
            obj._facets.append(TermFacet(field=field.replace("__", "."), name=name.replace("__", ".")))
            obj._aggs.append(TermsAgg(field=field.replace("__", "."), name=name.replace("__", ".")))
        return obj
971059
def _do_multivalued_field_facets(self, results, field_facets):
        
        facet_dict = {}

        for field in field_facets:
            facet_list = {}
            if not self._multi_value_field(field):
                continue

            for result in results:
                field_value = getattr(result, field)
                for item in field_value:  # Facet each item in a MultiValueField
                    facet_list[item] = facet_list.get(item, 0) + 1

            facet_dict[field] = list(facet_list.items())
        return facet_dict
987949
public final FacetOptions addFacetOnPivot(Field... fields) {
		Assert.notNull(fields, "Pivot Facets must not be null.");

		for (Field field : fields) {
			Assert.notNull(field, "Cannot facet on null field.");
			Assert.hasText(field.getName(), "Cannot facet on field with null/empty fieldname.");
		}

		List<Field> list = Arrays.asList(fields);
		this.facetOnPivotFields.add(new SimplePivotField(list));
		return this;
	}
812433
private void populateGroupByResponse(Map<String, Object> aggregations, Iterable<Expression> resultOrderIterable,
            List<Object> results, Client client, EntityMetadata m)
    {
        List temp;
        Object entity = null;
        for (String entry : aggregations.keySet())
        {
            entity = null;
            Object obj = aggregations.get(entry);
            temp = new ArrayList<>();
            Iterator<Expression> resultOrder = resultOrderIterable.iterator();
            while (resultOrder.hasNext())
            {
                Expression expression = (Expression) resultOrder.next();

                if (AggregateFunction.class.isAssignableFrom(expression.getClass()))
                {
                    if (((Map) obj).get(expression.toParsedText()) != null)
                    {
                        temp.add(((Map) obj).get(expression.toParsedText()));
                    }
                }
                else
                {
                    if (entity == null)
                    {
                        entity = findUsingLucene(m, client, new Object[] { entry }).get(0);
                    }
                    temp.add(getEntityFieldValue(m, entity, expression.toParsedText()));
                }
            }
            results.add(temp.size() == 1 ? temp.get(0) : temp);
        }
    }
341498
def aggregate(self, *args, **kwargs):
        
        obj = self._clone()
        obj._facets = [] #reset facets
        from django.db.models import Avg, Max, Min

        for arg in args:
            if isinstance(arg, (Avg, Max, Min)):

                field, djfield = self._django_to_es_field(arg.lookup)
                if not djfield:
                    obj = obj.annotate(field)
                from pyes.facets import StatisticalFacet

                obj = obj.annotate(StatisticalFacet(field, field))
        facets = obj.get_facets()
        #collecting results
        result = {}
        for name, values in facets.items():
            for k, v in values.items():
                if k.startswith("_"):
                    continue
                result[u'%s__%s' % (name, k)] = v

        return result
47450
def drill_down_facets
      drill = drill_down.reverse
      i = drill.find_index{|f|f.selected?}
      if i == 0
        down = nil
	current, *ups = drill[0..-1]
      else
        down, current, *ups = drill[i-1..-1]
      end

      [ down, current, ups ]
    end
1037274
function _validateAggregationColumnsAndInteractivity (aggregationColumns, clickColumns, overColumns) {
  var aggColumns = (aggregationColumns && Object.keys(aggregationColumns)) || [];

  _validateColumnsConcordance(aggColumns, clickColumns, 'featureClick');
  _validateColumnsConcordance(aggColumns, overColumns, 'featureOver');
}