}).then(data => { const rollup = { requests: 0, hits: 0, misses: 0, bandwidth: 0 }; const byday = data.data.data.map(function(data) { rollup.requests += data.requests; rollup.hits += data.hits; rollup.misses += data.miss; rollup.bandwidth += data.bandwidth; return { date: moment(data.start_time, "X").format("DD-MMM-YY"), requests: data.requests, hits: data.hits, misses: data.miss, cache: _.round(100 - data.misses / data.requests, 2) }; }); rollup.cache = _.round(100 - rollup.misses / rollup.requests, 2); rollup.startDate = moment(data.data.data[0].start_time, "X").format("MMMM Do"); rollup.endDate = moment(data.data.data[data.data.data.length - 1].start_time, "X").format("MMMM Do"); return { byday: byday, rollup: rollup }; });
(async () => { try { const data = parse(await fs.readFile(`${__dirname}/../valglister.csv`), { columns: true, }); const byKey = mapValues( groupBy(data, d => `${d.year}/${d.election}`), values => keyBy( values.filter(d => +d.candidateId < 5), d => `${d.name}/${d.yearBorn}` ) ); let alsoInPrev = 0; const keys = Object.keys(byKey['2015/kommunestyre']); keys.forEach(key => { if (byKey['2011/kommunestyre'][key]) { alsoInPrev++; } }); const total = keys.length; console.log({ alsoInPrev, total, percent: round((alsoInPrev * 100) / total), }); } catch (error) { console.log(error); } })();
.then(externalData => { return { USD_BTC: externalData[0], BTC_XLM: externalData[1], USD_XLM: _.round(externalData[0]*externalData[1],6), } })
function queryCategoryAmount(category, transactions) { var amounts = _.filter(transactions, {'category': category} ); var totalAmount = -1 * _.round(_.sum(amounts.map(t => {return t.amount}))); return totalAmount > 0 ? totalAmount : 0; }
rows: rows.map(function (row) { return { label: row.series.label, value: _.round(row.row.y1, 2), color: row.series.color, id: row.series.id }; })
const getAngleSection = (name, value) => { return ( <section className="angle"> <div className="angle-label">{name}</div> <span className="angle-value">{_.round(value)}°</span> </section> ) }
run(function*({ Com }) { const docs = yield Com.find({status: {$gt: 100}}) const stats = _.countBy(docs, doc => doc.status) console.log(`whole: ${docs.length}`) for (let i in stats) { const ratio = _.round((stats[i] / docs.length) * 100, 2) console.log(`${i}: ${stats[i]} (${ratio}%)`) } })
function renderMouseCoordinates() { const lat = mouseCoordinates ? _.round(mouseCoordinates.lat, DECIMAL_DEGREES_PRECISION) : ''; const lon = mouseCoordinates ? _.round(mouseCoordinates.lon, DECIMAL_DEGREES_PRECISION) : ''; return ( <EuiPanel className="mapWidgetControl mapViewControl__coordinates" paddingSize="none"> <EuiText size="xs"> <p> <strong>lat:</strong> {lat},{' '} <strong>lon:</strong> {lon} </p> </EuiText> </EuiPanel> ); }
speed: _.attempt(() => { if (_.isNumber(state.speed) && !_.isNaN(state.speed)) { // Preserve only two decimal places const PRECISION = 2 return _.round(units.bytesToMegabytes(state.speed), PRECISION) } return null })
// Format a size to px or em function cssSize(size, fontSize) { var unit = 'px'; if (_.isNumber(fontSize) && fontSize > 0) { unit = 'em'; } if (unit === 'px') { return size + 'px'; } return _.round(size / fontSize, 3) + 'em'; }
top: function (dist_bs, line_ht, bs_offset) { if (!_.isFinite(dist_bs)) { throw new Error("The first argument must be a Number"); } !_.isUndefined(line_ht) || (line_ht = line_ht_default) !_.isUndefined(bs_offset) || (bs_offset = bs_offset_default) var lead = line_ht - 1 return _.round(dist_bs - (1 - bs_offset) - lead / 2, 2) },
// jscs:disable disallowImplicitTypeConversion function getDistance(userLocation, eventLocation) { if (!userLocation) { return ''; } const distanceInMetres = geolib.getDistance(userLocation, eventLocation); const distanceInKilometres = distanceInMetres / 1000; return '' + _.round(distanceInKilometres, 1) + ' km'; }
lo.forEach(data, function (row) { class_id = row.ApexClassOrTriggerId; if (lo.has(id_to_class_map, class_id)) { var class_name = lo.toString(id_to_class_map[class_id].name); coverage_stats[class_name] = { NumLinesCovered:row.NumLinesCovered, NumLinesUncovered:row.NumLinesUncovered, TotalLines:(row.NumLinesCovered + row.NumLinesUncovered), Coverage:lo.round((((row.NumLinesCovered + row.NumLinesUncovered) - row.NumLinesUncovered)/(row.NumLinesCovered + row.NumLinesUncovered))*100, 2) }; coverage_stats['Total Org Coverage'] = { NumLinesCovered:(coverage_stats['Total Org Coverage'].NumLinesCovered + row.NumLinesCovered), NumLinesUncovered:(coverage_stats['Total Org Coverage'].NumLinesUncovered + row.NumLinesUncovered), TotalLines:(coverage_stats['Total Org Coverage'].TotalLines + row.NumLinesCovered + row.NumLinesUncovered) }; coverage_stats['Total Org Coverage'].Coverage = lo.round(((coverage_stats['Total Org Coverage'].TotalLines - coverage_stats['Total Org Coverage'].NumLinesUncovered)/coverage_stats['Total Org Coverage'].TotalLines)*100, 2) //console.log(coverage_stats['Total Org Coverage']); max_line = lo.max(lo.union(row.Coverage.coveredLines, row.Coverage.uncoveredLines)); coverage_size = lo.size(id_to_class_map[class_id].coverage); if (max_line > coverage_size) { for (i = coverage_size; i <= max_line; i += 1) { id_to_class_map[class_id].coverage.push(null); } } lo.forEach(row.Coverage.coveredLines, function (line_number) { if (id_to_class_map[class_id].coverage[line_number - 1] === null) { id_to_class_map[class_id].coverage[line_number - 1] = 1; } else { id_to_class_map[class_id].coverage[line_number - 1] += 1; } }); lo.forEach(row.Coverage.uncoveredLines, function (line_number) { if (id_to_class_map[class_id].coverage[line_number - 1] === null) { id_to_class_map[class_id].coverage[line_number - 1] = 0; } }); } });
export default function roundFormatted( weight, places = 0 ) { let rounded; if ( weight ) { rounded = _.round( weight, places ); return parseFloat( rounded ).toLocaleString(); } else { return 0; } }
handlebars.registerHelper('formatP', function(data) { if (_.isUndefined(data)) return 'FIXME:UNDEFINED!'; return ( data <= 0.00001 ? 'P < 0.00001' : data <= 0.0001 ? 'P < 0.0001' : data <= 0.001 ? 'P < 0.001' : data <= 0.01 ? 'P < 0.01' : data <= 0.05 ? 'P < 0.05' : 'P = ' + _.round(data, 2) // Round to 2 dp (0.248869 => 0.25) ); });
bars.reduce(function(acc, bar, i) { bar.ma = bar.ma || {}; if (acc == 0) { acc = bar.close * n; } else { var pre = bars[i - n] || bars[0]; acc = acc - parseFloat(pre.close) + parseFloat(bar.close); } bar.ma[n] = _.round(acc / n, 2); return acc; }, 0);
return function(acc, item) { item.ema = item.ema || {}; if (!acc) { var ema = item[field]; } else { var ema = (item[field] * 2 + acc * (n - 1)) / (n + 1); } ema = _.round(parseFloat(ema), 2); _.set(item, path, ema); return ema; }
render() { let { project } = this.props; let bar_data = [ { name: "gone", width: _.round(100 - (project.deadline / project.deadline_max) * 100, 0), color: project.deadline / project.deadline_max < 0.1 ? colors.danger : colors.warning, value: _.round(project.deadline_max - project.deadline, 0), showName: true }, { name: "days to deadline", width: _.round((project.deadline / project.deadline_max) * 100, 0), color: colors.success, value: _.round(project.deadline, 0), showName: true } ]; return project.type !== "own" ? <Bar className="deadline-bar" bar_data={bar_data} /> : " "; }
.map( fattyAcid => { let value = _.round( breakdowns[ fattyAcid ] ); if ( value ) { return ( <tr key={ `fatty-acid-prop-${ fattyAcid }` }> <td>{_.capitalize( fattyAcid )}</td> <td>{value}</td> </tr> ); } } )
export function scaleBounds(bounds) { if (!bounds) return; const scale = .5; // scale bounds by 50% const topLeft = bounds.top_left; const bottomRight = bounds.bottom_right; let latDiff = _.round(Math.abs(topLeft.lat - bottomRight.lat), 5); const lonDiff = _.round(Math.abs(bottomRight.lon - topLeft.lon), 5); //map height can be zero when vis is first created if(latDiff === 0) latDiff = lonDiff; const latDelta = latDiff * scale; let topLeftLat = _.round(topLeft.lat, 5) + latDelta; if(topLeftLat > 90) topLeftLat = 90; let bottomRightLat = _.round(bottomRight.lat, 5) - latDelta; if(bottomRightLat < -90) bottomRightLat = -90; const lonDelta = lonDiff * scale; let topLeftLon = _.round(topLeft.lon, 5) - lonDelta; if(topLeftLon < -180) topLeftLon = -180; let bottomRightLon = _.round(bottomRight.lon, 5) + lonDelta; if(bottomRightLon > 180) bottomRightLon = 180; return { 'top_left': { lat: topLeftLat, lon: topLeftLon }, 'bottom_right': { lat: bottomRightLat, lon: bottomRightLon } }; }
AppleHealthKit.getLatestLeanBodyMass({blah:true}, (err, res) => { if(this._handleHealthKitError(err, 'getLatestLeanBodyMass')){ return; } let leanMass = res.value; console.log("LEAN BODY MASS: ", leanMass); DATA.leanBodyMass = _.round(leanMass,0); self.trigger({ name: 'change:lean_body_mass', target: null, data: DATA.leanBodyMass }); });
static getDerivedStateFromProps(nextProps, prevstate) { let { happiness_real } = nextProps; if (happiness_real === prevstate.happiness_real) return false; return { bar_data: [ { name: "Happiness", width: _.round(happiness_real, 0), color: "#81CC52", value: _.round(happiness_real, 0) + "%", showName: true }, { name: "empty", width: _.round(100 - happiness_real, 0), color: "#61993D", value: "", showName: false } ] }; }
const byday = data.data.data.map(function(data) { rollup.requests += data.requests; rollup.hits += data.hits; rollup.misses += data.miss; rollup.bandwidth += data.bandwidth; return { date: moment(data.start_time, "X").format("DD-MMM-YY"), requests: data.requests, hits: data.hits, misses: data.miss, cache: _.round(100 - data.misses / data.requests, 2) }; });
bucketNames.forEach(b => { var amounts = _.filter(transactions, { "bucket": [b] }); var totalAmount = _.round(_.sum(amounts.map(t => {return t.amount}))); buckets.push({ "name": b, "value": totalAmount }); })
AppleHealthKit.getLatestBmi({blah:true}, (err, bmi) => { if(this._handleHealthKitError(err, 'getLatestBmi')){ return; } console.log("LATEST BMI: ", bmi); if(bmi && bmi.value){ DATA.bmi = _.round(bmi.value,1); self.trigger({ name: 'change:bmi', target: null, data: DATA.bmi }); } });
function handleDrop(shoe, run) { var queue = shoeQueue[getId(shoe)]; queue.queueRun(run); run.toggle(); if (processing) return; else processing = true; while (!queue.isEmpty()) { var milage = shoe.find('.miles'); if (milage.length < 0) { continue; } var run = queue.dequeueRun(); var runMilageSpan = run.find('.miles') if (!runMilageSpan[0]) { continue; } runMilageSpan = runMilageSpan[0]; spinShoe(shoe); var runMilage = parseFloat(runMilageSpan.innerHTML); milage[0].innerHTML = _.round(parseFloat(milage[0].innerHTML) + runMilage, 2); var runId = getId(run); run.remove(); $.post('/addrun', { 'run': runId, 'shoe': getId(shoe) }, function(data, status, jqxhr) { if (queue.isEmpty()) { if (timeoutId) clearTimeout(timeoutId); timeoutId = setTimeout(function() { if(spinners[getId(shoe)]) { spinners[getId(shoe)].stop(); spinners[getId(shoe)] = null; } shoe.find('p').fadeIn('slow'); }, 1500); processing = false; } }); } }
return doc => { const byCategory = getByCategory(doc) const byModel = getModelScore(doc, byCategory) const byYear = getYearSscore(doc, byCategory) const byBrand = getBrandScore(doc, byCategory) const score = weightedMean([ [byModel, 5], [byBrand, 4], [byYear, 3], [byCategory, 4] ]) return { score: round(score * 100), scoreDetail: { byCategory: round(byCategory * 100), byYear: round(byYear * 100), byBrand: round(byBrand * 100), byModel: round(byModel * 100) } } }
AppleHealthKit.getLatestWeight(options, (err, res) => { if(this._handleHealthKitError(err, 'getLatestWeight')){ return; } let weight = res.value; weight = _.round(weight,1); DATA.weight = weight; self.trigger({ name: 'change:weight', target: null, data: weight }); });
_.forEach(typeCards, (typeCard) => { let fieldValue = _.get(typeCard, fieldPath); if (fieldValue == null || fieldValue == 'X') { return true; } fieldTypeResult.count++; fieldTypeResult.total += fieldValue; fieldTypeResult.average = _.round(fieldTypeResult.total / fieldTypeResult.count, 1); fieldTypeResult.max = Math.max(fieldTypeResult.max, fieldValue); fieldTypeResult.min = Math.min(fieldTypeResult.min == null ? Infinity : fieldTypeResult.min, fieldValue); });
AppleHealthKit.getStepCount({options:"true"}, (err, steps) => { if(this._handleHealthKitError(err, 'getStepCountForToday')){ return; } console.log("STEPS : ", steps); steps = _.round(steps,0); DATA.steps = steps; self.trigger({ name: 'change:steps', target: null, data: steps }); });