-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathget-list-summary-numbers.js
46 lines (35 loc) · 1.29 KB
/
get-list-summary-numbers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import statuses from '~/helpers/statuses'
export default function ( appList ) {
if ( !Array.isArray( appList ) ) {
throw new Error(`List must be an array but is ${typeof appList}`)
}
const totalApps = appList.length
// Create a totals object to collect amounts
const totals = {}
// Get status slugs from statuses
Object.entries(statuses).forEach( ([_, statusSlug]) => {
totals[statusSlug] = 0
})
// Count uses of each status
appList.forEach( app => {
// console.log('app.status', app.status)
for (const statusKey in statuses) {
if (app.status === statuses[statusKey]) {
totals[app.status]++
break
}
}
})
// console.log('totals', totals)
const nativePercent = Number((( totals['native'] / totalApps ) * 100).toFixed(1))
const rosettaPercent = Number((( totals['rosetta'] / totalApps ) * 100).toFixed(1))
const unreportedPercent = Number((( totals['unreported'] / totalApps ) * 100).toFixed(1))
const unsupportedPercent = Number((100 - (nativePercent + rosettaPercent + unreportedPercent)).toFixed(1))
return {
total: totalApps,
nativePercent,
rosettaPercent,
unreportedPercent,
unsupportedPercent,
}
}