/** * Get total clicks */ _getTotalClicks () { const { clickers } = this.props; return _.sumBy(clickers, 'clicks'); }
calculateSubTotal() { return _.sumBy(this.items, 'price'); }
function getSessionStatsPerSegment(sessionsWithExtras, segmentSlug, timeScale) { const sessionGroups = _.groupBy(sessionsWithExtras, ({ createdAt }) => getScaledTimeByTimeScale(timeScale, moment.utc(createdAt)) ) return _.mapValues(sessionGroups, sessions => { const successfulSessions = _.filter(sessions, 'isSuccessful') return { count: sessions.length, durationSecSum: _.sumBy(sessions, 'durationSeconds'), waitSecSum: _.sumBy(sessions, 'waitSeconds'), messageSum: _.sumBy(sessions, ({ messages }) => messages.length), successfulMatches: successfulSessions.length, 'day-of-week': _.countBy(sessions, 'dayOfWeek'), 'hour-of-day': _.countBy(sessions, 'hourOfDay'), topic: _.countBy(sessions, 'type'), 'sub-topic': _.countBy(sessions, 'subTopic') } }) }
formatBytes(shape.ram * 1024 * 1024), instance.storage_attachments.length, formatBytes(_.sumBy(vols, (v) => parseInt(v.size))) ];
it("should group with tag", () => { const query = { _group: ["tag"], }; const ret = handleAggs( aggConfigs, { // fake req path: "/pets", cusQuery: query, }, { // fake res locals: { data: pets, }, setHeader: () => {}, } ); expect(ret.length).toBe(2); expect(_.sumBy(ret, "count")).toBe(pets.length); });
let totalBalanceSatoshi = _.sumBy(unspentOutputs, (x) => { return x.amountSatoshi }) // value of all unspent outputs let workingBalanceSatoshi = totalBalanceSatoshi - feeTotalSat // deduct the fee, the remainder is to be divided amongst the outputs let perOutputAmountSatoshi = _.floor(workingBalanceSatoshi / newOutputCount) // amount for each output
it("should group with month", () => { const query = { _group: ["birthAt.year", "birthAt.month"], _limit: 100, }; const ret = handleAggs( aggConfigs, { path: "/pets", cusQuery: query, }, { locals: { data: pets, }, setHeader: () => {}, } ); expect(_.sumBy(ret, "count")).toBe(pets.length); expect(_.sumBy(ret, r => r.count * r.grade)).toBe(_.sumBy(pets, "grade")); });
function getVolunteerStatsPerSegment( volunteersWithExtras, segmentSlug, timeScale ) { const volunteerGroups = _.groupBy(volunteersWithExtras, ({ createdAt }) => getScaledTimeByTimeScale(timeScale, moment.utc(createdAt)) ) return _.mapValues(volunteerGroups, volunteers => { return { count: volunteers.length, onboardedCount: _.filter( volunteers, ({ availableHours, certificationCount }) => availableHours > 0 && certificationCount > 0 ).length, certificationSum: _.sumBy(volunteers, 'certificationCount'), availableHoursAvg: parseInt(_.meanBy(volunteers, 'availableHours')) } }) }
calculateSubTotal() { return _.sumBy(this.items, 'price'); }
it("should group with month", () => { const query = { _group: ["birthAt.year", "birthAt.month"], _limit: 100, }; const ret = handleAggs( aggConfigs, { path: "/pets", cusQuery: query, }, { locals: { data: pets, }, setHeader: () => {}, } ); expect(_.sumBy(ret, "count")).toBe(pets.length); expect(_.sumBy(ret, r => r.count * r.grade)).toBe(_.sumBy(pets, "grade")); });
it("should group with tag", () => { const query = { _group: ["tag"], }; const ret = handleAggs( aggConfigs, { // fake req path: "/pets", cusQuery: query, }, { // fake res locals: { data: pets, }, setHeader: () => {}, } ); expect(ret.length).toBe(2); expect(_.sumBy(ret, "count")).toBe(pets.length); });