Combine stats from npmcdn.com + unpkg.com

This commit is contained in:
Michael Jackson
2016-09-12 17:07:42 -07:00
parent 855988865d
commit 469102ab52
2 changed files with 30 additions and 11 deletions

View File

@ -48,3 +48,28 @@ export const getZoneAnalyticsDashboard = (zone, since, until) =>
commonStack,
createRangeQuery(since, until)
)(`/zones/${zone.id}/analytics/dashboard`)
export const getAnalyticsDashboards = (domainNames, since, until) =>
Promise.all(
domainNames.map(domainName => getZones(domainName))
).then(
domainZones => domainZones.reduce((memo, zones) => memo.concat(zones))
).then(
zones => Promise.all(zones.map(zone => getZoneAnalyticsDashboard(zone, since, until)))
).then(
results => results.reduce(reduceResults)
)
const reduceResults = (target, results) => {
Object.keys(results).forEach(key => {
const value = results[key]
if (typeof value === 'object' && value) {
target[key] = reduceResults(target[key] || {}, value)
} else if (typeof value === 'number') {
target[key] = (target[key] || 0) + results[key]
}
})
return target
}