How to use the simple-statistics.sum function in simple-statistics

To help you get started, we’ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antvis / data-set / src / transform / percent.ts View on Github external
forIn(groups, (group) => {
    const totalSum = sum(group.map((row: any) => row[field]));
    if (totalSum === 0) {
      console.warn(`Invalid data: total sum of field ${field} is 0!`);
    }
    const innerGroups = partition(group, [dimension]);
    forIn(innerGroups, (innerGroup) => {
      const innerSum = sum(innerGroup.map((row: any) => row[field]));
      // const resultRow = pick(innerGroup[0], union(groupBy, [ dimension ]));
      const resultRow = innerGroup[0];
      // FIXME in case dimension and field is the same
      const dimensionValue = resultRow[dimension];
      resultRow[field] = innerSum;
      resultRow[dimension] = dimensionValue;
      if (totalSum === 0) {
        resultRow[as!] = 0;
      } else {
        resultRow[as!] = innerSum / totalSum;
github antvis / data-set / src / transform / percent.ts View on Github external
forIn(innerGroups, (innerGroup) => {
      const innerSum = sum(innerGroup.map((row: any) => row[field]));
      // const resultRow = pick(innerGroup[0], union(groupBy, [ dimension ]));
      const resultRow = innerGroup[0];
      // FIXME in case dimension and field is the same
      const dimensionValue = resultRow[dimension];
      resultRow[field] = innerSum;
      resultRow[dimension] = dimensionValue;
      if (totalSum === 0) {
        resultRow[as!] = 0;
      } else {
        resultRow[as!] = innerSum / totalSum;
      }
      result.push(resultRow);
    });
  });
github apinf / platform / feedback / collection / helpers.js View on Github external
sumOfVotes () {
    // Get all votes for current feedback
    const allFeedback = FeedbackVotes.find({ feedbackId: this._id }).fetch();

    // Create a list of all feedback vote values
    const votes = allFeedback.map((feedback) => {
      return feedback.vote;
    });

    // Calculate the sum of all vote values
    const sum = ss.sum(votes);
    return sum;
  },
  author () {
github apinf / platform / apinf_packages / feedback / collection / helpers.js View on Github external
sumOfVotes () {
    // Get all votes for current feedback
    const allFeedback = FeedbackVotes.find({ feedbackId: this._id }).fetch();

    // Create a list of all feedback vote values
    const votes = allFeedback.map((feedback) => {
      return feedback.vote;
    });

    // Calculate the sum of all vote values
    const sum = ss.sum(votes);
    return sum;
  },
  author () {
github electron / i18n / script / wordcount.ts View on Github external
function analyze(dir: string, title: string) {
  const files = walk(dir, { directories: false }).map(f => path.join(dir, f))
  const words = chain(files)
    .map(file => matchWords(fs.readFileSync(file, 'utf8')))
    .flatten()
    .value()
  const counts = files.map(
    f => (matchWords(fs.readFileSync(f, 'utf8')) || []).length
  )
  const { average, sum } = require('simple-statistics')

  const results: Record = {
    'total files': files.length,
    'total words': sum(counts),
    'unique words': chain(words)
      .flatten()
      .uniq()
      .value().length,
    'average words per file': Math.floor(average(counts)),
  }

  console.log(`\n## ${title}\n`)
  console.log('Stat | Value')
  console.log('---- | -----')

  Object.keys(results).forEach(stat => {
    console.log([stat, results[stat]].join(' | '))
  })
}
github Turfjs / turf / lib / sum.js View on Github external
_.each(polyFC.features, function(poly){
    if(!poly.properties){
      poly.properties = {}
    }
    var values = []
    _.each(ptFC.features, function(pt){
      if (t.inside(pt, poly)) {
        values.push(pt.properties[inField])
      }
    })
    poly.properties[outField] = ss.sum(values)
  })
github antvis / data-set / src / transform / waffle.ts View on Github external
forIn(groups, (group) => {
    const totalValue = sum(map(group, (row: any) => row[valueField]));
    let cols = Math.ceil((totalValue * scale) / rows);
    if (totalValue * scale > maxCount) {
      scale = maxCount / totalValue;
      cols = Math.ceil((totalValue * scale) / rows);
    }
    wStep = width / cols;
  });
github antvis / data-set / src / transform / kernel-smooth / regression.ts View on Github external
kernelSmoother = vectorize((x: number[]) => {
      const weights = xs.map((x_i) => weightFunc(x, x_i));
      const num = sum(weights.map((w, i) => w * ys[i]));
      const denom = sum(weights);
      if (!num || !denom) return 0;
      return num / denom;
    });
  }
github antvis / data-set / src / transform / kernel-smooth / regression.ts View on Github external
kernelSmoother = vectorize((x) => {
      const weights = xs.map((x_i) => weightFunc(x, x_i));
      const num = sum(weights);
      const denom = xCount * bandwidth;
      if (!num || !denom) return 0;
      return num / denom;
    });
  } else {