Performs stat aggregation.
768682
def _aggregate(self, instanceId, container, value, subKey = None):
    """"""

    # Get the aggregator.
    if instanceId not in self._aggregators:
      self._aggregators[instanceId] = _Stats.getAggregator(instanceId, self.__name)
    aggregator = self._aggregators[instanceId]

    # If we are aggregating, get the old value.
    if aggregator:
      oldValue = container.get(self.__name)
      if subKey:
        oldValue = oldValue[subKey]
        aggregator[0].update(aggregator[1], oldValue, value, subKey)
      else:
        aggregator[0].update(aggregator[1], oldValue, value)
810574
def stats(self):
        ''''''
        data = Counter()
        for name, value, aggregated in self.raw:
            if aggregated:
                data['%s.max' % name] = max(data['%s.max' % name], value)
                data['%s.total' % name] += value
            else:
                data[name] = value

        return sorted(data.items())
1285481
def aggregate(self):
        
        for report in self.reportset:
            printtime('Processing {}'.format(report.split('.')[0]), self.start)
            # Initialise the header for each report - MLST is different, as the header is different for each
            # MLST scheme. This provides a generic header instead
            header = '' if report != 'mlst.csv' else 'Strain,Genus,SequenceType,Matches,1,2,3,4,5,6,7\n'
            # Initialise a string to hold the data for each report
            data = ''
            # Open the aggregated report
            with open(os.path.join(self.reportpath, report), 'w') as aggregate:
                for sample in self.runmetadata.samples:
                    # Try to open the report for this run
                    try:
                        #
                        with open(os.path.join(sample.general.reportpath, report), 'r') as runreport:
                            # Only get the header from the first file
                            if not header:
                                header = runreport.readline()
                            else:
                                for row in runreport:
                                    # The final entry in a report does not have a newline character. Add \n as required
                                    if not row.endswith('\n'):
                                        row += '\n'
                                    # For certain reports, the header row is printed above each strain - ignore multiple
                                    # instances of the header
                                    if row.split(',')[0] != header.split(',')[0]:
                                        # Add the row to the string of data
                                        data += row
                    except IOError:
                        pass
                # Write the strings to the aggregate report file
                aggregate.write(header)
                aggregate.write(data)
1194401
def manage_itstat(self):
        """"""

        # Extract and record iteration stats
        itst = self.iteration_stats()
        self.itstat.append(itst)
        self.display_status(self.fmtstr, itst)
523681
public void combine(SpdStat other) {
        if (other == null)
            return;
        if (stat.isEnabled() && other.isEnabled())
            //stat.combine((TimeStatisticImpl)other.getStatistic());
            stat.combine(other.getStatistic());
    }
896484
def _aggregations(search, definitions):
    """"""
    if definitions:
        for name, agg in definitions.items():
            search.aggs[name] = agg if not callable(agg) else agg()
    return search
1152514
def aggregate(input, **params):
    
    PARAM_CFG_EXTRACT = 'extract'
    PARAM_CFG_SUBSTITUTE = 'substitute'
    PARAM_CFG_AGGREGATE = 'aggregate'
    AGGR_FIELD = 'field'
    AGGR_FUNC = 'func'

    extract_params = params.get(PARAM_CFG_EXTRACT)
    extract_params.update({AccessParams.KEY_TYPE: AccessParams.TYPE_MULTI})
    dataset = __extract(input, extract_params)
    if PARAM_CFG_SUBSTITUTE in params:
        dataset = __substitute(input, dataset, params.get(PARAM_CFG_SUBSTITUTE))
    cfg = params.get(PARAM_CFG_AGGREGATE)
    res = Aggregator.agg_single_func(dataset, cfg[AGGR_FIELD], cfg[AGGR_FUNC])
    return res
1202209
def aggregate(d, y_size, x_size):
        """"""
        if d.ndim != 2:
            # we can't guarantee what blocks we are getting and how
            # it should be reshaped to do the averaging.
            raise ValueError("Can't aggregrate (reduce) data arrays with "
                             "more than 2 dimensions.")
        if not (x_size.is_integer() and y_size.is_integer()):
            raise ValueError("Aggregation factors are not integers")
        for agg_size, chunks in zip([y_size, x_size], d.chunks):
            for chunk_size in chunks:
                if chunk_size % agg_size != 0:
                    raise ValueError("Aggregation requires arrays with "
                                     "shapes and chunks divisible by the "
                                     "factor")

        new_chunks = (tuple(int(x / y_size) for x in d.chunks[0]),
                      tuple(int(x / x_size) for x in d.chunks[1]))
        return da.core.map_blocks(_mean, d, y_size, x_size, dtype=d.dtype, chunks=new_chunks)
1136564
def _raise_check_aggregation(aggregation: str):
        
        if aggregation not in ComputeStats.EXTRA_AGGREGATIONS and not hasattr(np, aggregation):
            raise ValueError('Aggregation `{}` is not a NumPy function or a member '
                             'of EXTRA_AGGREGATIONS.'.format(aggregation))
1162656
def aggregate(self, other=None):
        ''''''
        if not self.status:
            return self
        if not other:
            return self
        if not other.status:
            return other
        return Value(True, other.index, self.value + other.value, None)
883552
private static void getStats(
      StatsSnapshot snapshot,
      AggregationData data,
      View view,
      ViewData.AggregationWindowData windowData) {
    if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_VIEW || view == RPC_SERVER_SERVER_LATENCY_VIEW) {
      snapshot.avgLatencyTotal = ((DistributionData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_MINUTE_VIEW
        || view == RPC_SERVER_SERVER_LATENCY_MINUTE_VIEW) {
      snapshot.avgLatencyLastMinute = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_HOUR_VIEW
        || view == RPC_SERVER_SERVER_LATENCY_HOUR_VIEW) {
      snapshot.avgLatencyLastHour = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ERROR_COUNT_VIEW || view == RPC_SERVER_ERROR_COUNT_VIEW) {
      snapshot.errorsTotal = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_MINUTE_VIEW
        || view == RPC_SERVER_ERROR_COUNT_MINUTE_VIEW) {
      snapshot.errorsLastMinute = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_HOUR_VIEW
        || view == RPC_SERVER_ERROR_COUNT_HOUR_VIEW) {
      snapshot.errorsLastHour = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_REQUEST_BYTES_VIEW || view == RPC_SERVER_REQUEST_BYTES_VIEW) {
      DistributionData distributionData = (DistributionData) data;
      snapshot.inputRateTotal =
          distributionData.getCount()
              * distributionData.getMean()
              / BYTES_PER_KB
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_REQUEST_BYTES_MINUTE_VIEW
        || view == RPC_SERVER_REQUEST_BYTES_MINUTE_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.inputRateLastMinute =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_REQUEST_BYTES_HOUR_VIEW
        || view == RPC_SERVER_REQUEST_BYTES_HOUR_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.inputRateLastHour =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_VIEW || view == RPC_SERVER_RESPONSE_BYTES_VIEW) {
      DistributionData distributionData = (DistributionData) data;
      snapshot.outputRateTotal =
          distributionData.getCount()
              * distributionData.getMean()
              / BYTES_PER_KB
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_MINUTE_VIEW
        || view == RPC_SERVER_RESPONSE_BYTES_MINUTE_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.outputRateLastMinute =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_HOUR_VIEW
        || view == RPC_SERVER_RESPONSE_BYTES_HOUR_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.outputRateLastHour =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_MINUTE_VIEW
        || view == RPC_SERVER_STARTED_COUNT_MINUTE_VIEW) {
      snapshot.countLastMinute = ((CountData) data).getCount();
      snapshot.rpcRateLastMinute = snapshot.countLastMinute / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_STARTED_COUNT_HOUR_VIEW
        || view == RPC_SERVER_STARTED_COUNT_HOUR_VIEW) {
      snapshot.countLastHour = ((CountData) data).getCount();
      snapshot.rpcRateLastHour = snapshot.countLastHour / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_CUMULATIVE_VIEW
        || view == RPC_SERVER_STARTED_COUNT_CUMULATIVE_VIEW) {
      snapshot.countTotal = ((CountData) data).getCount();
      snapshot.rpcRateTotal =
          snapshot.countTotal
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } // TODO(songya): compute and store latency percentiles.
  }
49393
public function stats($alias, $field = null, $script = null)
    {
        $aggregation = new StatsAggregation($alias, $field, $script);

        $this->append($aggregation);
    }
551753
def sorted_stats(self):
        """"""
        key = self.get_key()
        return sorted(self.stats, key=lambda stat: tuple(map(
            lambda part: int(part) if part.isdigit() else part.lower(),
            re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
        )))
106470
function AggregateByKey(sc, dependencies, reducer, combiner, init, args) {
  Dataset.call(this, sc, dependencies);
  this.combiner = combiner;
  this.reducer = reducer;
  this.init = init;
  this.args = args;
  this.shuffling = true;
  this.executed = false;
  this.buffer = {};
  this.type = 'AggregateByKey';
}
850303
public void combine(WSStatistic otherStat) {
        if (!validate(otherStat))
            return;

        DoubleStatisticImpl other = (DoubleStatisticImpl) otherStat;
        count += other.count;
        //TODO: how to update lastSampleTime???
        //if (other.lastSampleTime > lastSampleTime)
        //  lastSampleTime = other.lastSampleTime;
    }
692318
public void accumulate(AverageData data,
                           Object value) {
        if (value != null) {
            data.count++;
            data.total = data.total.add( (BigDecimal) value );
        }
    }
1341378
def totals(iter, keyfunc, sumfunc):
    
    data = sorted(iter, key=keyfunc)
    res = {}

    for k, group in groupby(data, keyfunc):
        res[k] = sum([sumfunc(entry) for entry in group])

    return res