Returns the aggregate for the entity
323257
def get_aggregate(self, security: Commodity) -> SecurityAggregate:
        
        assert security is not None
        assert isinstance(security, Commodity)

        return SecurityAggregate(self.book, security)
632152
def aggregate(self, start, end):
        '''
        
        '''
        last = self.objects(
            level='daily', date__lte=self.iso(end),
            date__gte=self.iso(start)).order_by('-date').first()
        return last.values[self.name]
1158125
private Object getAggregatedResult(InternalAggregations internalAggs, String identifier, Expression exp)
    {
        switch (identifier)
        {
        case Expression.MIN:
            return (((InternalMin) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.MAX:
            return (((InternalMax) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.AVG:
            return (((InternalAvg) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.SUM:
            return (((InternalSum) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.COUNT:
            return (((InternalValueCount) internalAggs.get(exp.toParsedText())).getValue());
        }

        throw new KunderaException("No support for " + identifier + " aggregation.");
    }
24598
def get_entity(self, entity_id, at=None):
        

        # Get a snapshot (None if none exist).
        if self._snapshot_strategy is not None:
            snapshot = self._snapshot_strategy.get_snapshot(entity_id, lte=at)
        else:
            snapshot = None

        # Decide the initial state of the entity, and the
        # version of the last item applied to the entity.
        if snapshot is None:
            initial_state = None
            gt = None
        else:
            initial_state = entity_from_snapshot(snapshot)
            gt = snapshot.originator_version

        # Obtain and return current state.
        return self.get_and_project_events(entity_id, gt=gt, lte=at, initial_state=initial_state)
365496
def aggregate(self):
        
        _, indices, inverse = np.unique(self.record.sample, axis=0,
                                        return_index=True, return_inverse=True)

        # unique also sorts the array which we don't want, so we undo the sort
        order = np.argsort(indices)
        indices = indices[order]

        record = self.record[indices]

        # fix the number of occurrences
        record.num_occurrences = 0
        for old_idx, new_idx in enumerate(inverse):
            new_idx = order[new_idx]
            record[new_idx].num_occurrences += self.record[old_idx].num_occurrences

        # dev note: we don't check the energies as they should be the same
        # for individual samples

        return type(self)(record, self.variables, copy.deepcopy(self.info),
                          self.vartype)
367739
public function count() {
        $repo = $this->getRepository();

        return $repo->aggregate($this->limit(0), __FUNCTION__, $repo->getPrimaryKey());
    }
178455
private void buildAggregation(DBObject group, Expression expression, EntityMetadata metadata, EntityType entityType,
            boolean hasLob)
    {
        if (expression instanceof AggregateFunction)
        {
            AggregateFunction aggregateFunction = (AggregateFunction) expression;
            String identifier = aggregateFunction.getIdentifier().toLowerCase();

            Expression child = aggregateFunction.getExpression();

            if (child instanceof StateFieldPathExpression)
            {
                StateFieldPathExpression sfpExp = (StateFieldPathExpression) child;
                String columnName = getColumnName(metadata, entityType, sfpExp.toActualText());
                String actualColumnName = columnName;
                if (hasLob)
                {
                    actualColumnName = "metadata." + columnName;
                }
                else if (metadata.getIdAttribute().equals(entityType.getAttribute(metadata.getFieldName(columnName))))
                {
                    actualColumnName = "_id";
                }

                BasicDBObject item = new BasicDBObject("$" + identifier, "$" + actualColumnName);
                group.put(identifier + "_" + columnName, item);
            }
            else if (expression instanceof CountFunction)
            {
                group.put("count", new BasicDBObject("$sum", 1));
            }
        }
        else if (expression instanceof CollectionExpression)
        {
            for (Expression child : expression.children())
            {
                buildAggregation(group, child, metadata, entityType, hasLob);
            }
        }
        else if (expression instanceof StateFieldPathExpression)
        {
            StateFieldPathExpression sfpExp = (StateFieldPathExpression) expression;

            BasicDBObject idObject;
            Object existing = group.get("_id");
            if (existing != null)
            {
                idObject = (BasicDBObject) existing;
            }
            else
            {
                idObject = new BasicDBObject();
                group.put("_id", idObject);
            }

            String columnName = getColumnName(metadata, entityType, sfpExp.toActualText());
            String actualColumnName = columnName;
            if (hasLob)
            {
                actualColumnName = "metadata." + columnName;
            }

            idObject.put(columnName, "$" + actualColumnName);
        }
    }
904685
public Long count(Criteria<T, T> criteria) {
        SingularAttribute<? super T, PK> id = getEntityManager().getMetamodel().entity(entityClass).getId(entityKey);
        return criteria.select(Long.class, countDistinct(id))
                .getSingleResult();
    }
965232
@Override
    public void aggregate(Aggregate op, long key) {
        int deviceId = Nd4j.getAffinityManager().getDeviceForCurrentThread();
        if (opCounter.get() == null)
            opCounter.set(new AtomicLong(0));

        // we enqueue op for specific device here
        aggregates.get(deviceId).add(new AggregateDescriptor(op, key, opCounter.get().getAndIncrement()));
    }
669212
public function count()
    {
        if ($this->isInitialized()) {
            return $this->collection->count();
        }

        // Return cached result in case count query was already executed
        if ($this->count !== null) {
            return $this->count;
        }

        return $this->count = $this->entityPersister->count($this->criteria);
    }
551481
def aggregate(type, ts)
      Octo::Enterprise.each do |enterprise|
        aggregate_baseline enterprise.id, type, ts
      end
    end
1304909
function generateAggregate (aggregateOp, defaultColumnName = undefined) {
  let funcName = `get${_.upperFirst(aggregateOp)}`

  /**
   * Do not re-add the method if exists
   */
  if (KnexQueryBuilder.prototype[funcName]) {
    return
  }

  KnexQueryBuilder.prototype[funcName] = async function (columnName = defaultColumnName) {
    if (!columnName) {
      throw new Error(`'${funcName}' requires a column name.`)
    }

    const wrapper = new this.constructor(this.client)
    const query = wrapper.from(this.as('__lucid'))

    /**
     * Copy events from the original query
     */
    query._events = this._events

    /**
     * Executing query chain
     */
    const results = await query[aggregateOp](`${columnName} as __lucid_aggregate`)

    return results[0].__lucid_aggregate
  }
}
894500
public AggregationResult aggregate(String rAggregateFormula) throws DDFException {

    return mAggregationHandler.aggregate(AggregateField.fromSqlFieldSpecs(parseRAggregateFormula(rAggregateFormula)));
  }
871128
def aggregate(self, *args, **kwargs):
        
        if self.query.distinct_fields:
            raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
        for arg in args:
            # The default_alias property may raise a TypeError, so we use
            # a try/except construct rather than hasattr in order to remain
            # consistent between PY2 and PY3 (hasattr would swallow
            # the TypeError on PY2).
            try:
                arg.default_alias
            except (AttributeError, TypeError):
                raise TypeError("Complex aggregates require an alias")
            kwargs[arg.default_alias] = arg

        if django.VERSION < (2, 0):
            query = self.query.clone(CTEAggregateQuery)
        else:
            query = self.query.chain(CTEAggregateQuery)
        for (alias, aggregate_expr) in kwargs.items():
            query.add_annotation(aggregate_expr, alias, is_summary=True)
            if not query.annotations[alias].contains_aggregate:
                raise TypeError("%s is not an aggregate expression" % alias)
        return query.get_aggregation(self.db, kwargs.keys())
415587
def sum(self):
        
        res = self._runQuery('SELECT', 'SUM(%s)' % (self._queryTarget,)) or [(0,)]
        assert len(res) == 1, "more than one result: %r" % (res,)
        dbval = res[0][0] or 0
        return self.attribute.outfilter(dbval, _FakeItemForFilter(self.store))
149349
protected List fetch()
    {
        EntityMetadata metadata = getEntityMetadata();
        Client client = persistenceDelegeator.getClient(metadata);
        List results = isRelational(metadata) ? recursivelyPopulateEntities(metadata, client) : populateEntities(
                metadata, client);
        return results;
    }
398216
def subentity(self, Entity, index):
        """"""
        dim = Entity.__dimension__
        entity = Entity.empty()
        
        if index >= self.dimensions[dim]:
            raise ValueError('index {} out of bounds for dimension {} (size {})'
                             .format(index, dim, self.dimensions[dim]))
        
        
        for name, attr in self.__attributes__.items():
            if attr.dim == dim:
                # If the dimension of the attributes is the same of the
                # dimension of the entity, we generate a field
                entity.__fields__[name] = attr.field(index)
            elif attr.dim in entity.dimensions:
                # Special case, we don't need to do anything
                if self.dimensions[attr.dim] == 0:
                    continue

                # Else, we generate a subattribute
                mapped_index = self.maps[attr.dim, dim].value == index
                entity.__attributes__[name] = attr.sub(mapped_index)
                entity.dimensions[attr.dim] = np.count_nonzero(mapped_index)

        for name, rel in self.__relations__.items():
            if rel.map == dim:
                # The relation is between entities we need to return
                # which means the entity doesn't know about that
                pass
            if rel.map in entity.dimensions:
                # Special case, we don't need to do anything
                if self.dimensions[rel.dim] == 0:
                    continue
                mapped_index = self.maps[rel.dim, dim].value == index
                entity.__relations__[name] = rel.sub(mapped_index)
                entity.dimensions[rel.dim] = np.count_nonzero(mapped_index)
                
                # We need to remap values
                convert_index = self.maps[rel.map, dim].value == index
                entity.__relations__[name].remap(convert_index.nonzero()[0],
                                                 range(entity.dimensions[rel.map]))
        
        return entity