@@ -118,31 +118,33 @@ async function fetchOrgAnalyticsData (time, spinner) {
118
118
return handleUnsuccessfulApiResponse ( 'getOrgAnalytics' , result , spinner )
119
119
}
120
120
121
- // const formattedData = result.data.map(d => {
122
- // const formattedDate = new Date(d.created_at).toLocaleDateString()
123
- // return {
124
- // ...d,
125
- // created_at: formattedDate,
126
- // }
127
- // })
128
- // const data = { ...formattedData.flat(1) }
129
-
130
- // const test = result.data.reduce((acc, current) => {
131
- // if (acc[current.created_at]) {
132
- // acc[current.created_at].total_critical_alerts += acc[current.created_at].total_critical_alerts
133
- // } else {
134
- // acc[current.created_at] = current
135
- // }
136
-
137
- // return acc
138
- // }, {})
139
-
140
- // console.log(test)
141
-
142
- // console.log('\n')
143
- // console.table(data, ['created_at', 'repository_name', 'total_critical_alerts', 'total_high_alerts', 'top_five_alert_types'])
144
- // console.table(data, ['created_at', 'repository_name', 'total_critical_added', 'total_high_added'])
145
- // console.table(data, ['created_at', 'repository_name', 'total_critical_prevented', 'total_high_prevented', 'total_medium_prevented', 'total_low_prevented'])
121
+ spinner . stop ( )
122
+
123
+ const data = result . data . reduce ( ( /** @type {{ [key: string]: any } } */ acc , current ) => {
124
+ const formattedDate = new Date ( current . created_at ) . toLocaleDateString ( )
125
+
126
+ if ( acc [ formattedDate ] ) {
127
+ acc [ formattedDate ] . total_critical_alerts += current . total_critical_alerts
128
+ acc [ formattedDate ] . total_high_alerts += current . total_high_alerts
129
+ acc [ formattedDate ] . total_critical_added += current . total_critical_added
130
+ acc [ formattedDate ] . total_high_added += current . total_high_added
131
+ acc [ formattedDate ] . total_critical_prevented += current . total_critical_prevented
132
+ acc [ formattedDate ] . total_high_prevented += current . total_high_prevented
133
+ acc [ formattedDate ] . total_medium_prevented += current . total_medium_prevented
134
+ acc [ formattedDate ] . total_low_prevented += current . total_low_prevented
135
+ // acc[formattedDate].top_five_alert_types += current.top_five_alert_types
136
+ } else {
137
+ acc [ formattedDate ] = current
138
+ acc [ formattedDate ] . created_at = formattedDate
139
+ }
140
+
141
+ return acc
142
+ } , { } )
143
+
144
+ console . log ( chalk . bgMagenta . white . bold ( `\n Analytics data for the organization over the last ${ time } days: \n` ) )
145
+ console . table ( data , [ 'repository_name' , 'total_critical_alerts' , 'total_high_alerts' , 'top_five_alert_types' ] )
146
+ console . table ( data , [ 'repository_name' , 'total_critical_added' , 'total_high_added' ] )
147
+ console . table ( data , [ 'repository_name' , 'total_critical_prevented' , 'total_high_prevented' , 'total_medium_prevented' , 'total_low_prevented' ] )
146
148
}
147
149
148
150
/**
0 commit comments