Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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);
});
});
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 () {
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 () {
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(' | '))
})
}
_.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)
})
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;
});
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;
});
}
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 {