1
- // @ts -nocheck
2
1
// @ts -ignore
3
2
import blessed from 'blessed'
4
3
import contrib from 'blessed-contrib'
@@ -39,7 +38,7 @@ export const analytics: CliSubcommand = {
39
38
}
40
39
}
41
40
42
- const analyticsFlags : { [ key : string ] : any } = {
41
+ const analyticsFlags = {
43
42
scope : {
44
43
type : 'string' ,
45
44
shortFlag : 's' ,
@@ -161,9 +160,7 @@ type AnalyticsData = {
161
160
162
161
type FormattedAnalyticsData = {
163
162
[ key : string ] : {
164
- [ key : string ] : number | {
165
- [ key : string ] : number
166
- }
163
+ [ key : string ] : number
167
164
}
168
165
}
169
166
@@ -183,8 +180,6 @@ async function fetchOrgAnalyticsData (time: number, spinner: Ora, apiKey: string
183
180
184
181
const data = formatData ( result . data , 'org' )
185
182
186
- console . log ( data )
187
-
188
183
if ( outputJson ) {
189
184
return console . log ( result . data )
190
185
}
@@ -211,24 +206,24 @@ const formatDate = (date: string) => {
211
206
return `${ months [ new Date ( date ) . getMonth ( ) ] } ${ new Date ( date ) . getDate ( ) } `
212
207
}
213
208
214
- const formatData = ( data : AnalyticsData [ ] , scope : string ) => {
209
+ const formatData = ( data : any , scope : string ) => {
215
210
let formattedData , sortedTopFivealerts
216
211
217
212
if ( scope === 'org' ) {
218
- const topFiveAlerts = data . map ( d => d . top_five_alert_types || { } )
213
+ const topFiveAlerts = data . map ( ( d : { [ k : string ] : any } ) => d [ ' top_five_alert_types' ] )
219
214
220
- const totalTopAlerts = topFiveAlerts . reduce ( ( acc , current : { [ key : string ] : number } ) => {
215
+ const totalTopAlerts : { [ key : string ] : number } = topFiveAlerts . reduce ( ( acc : { [ k : string ] : number } , current : { [ key : string ] : number } ) => {
221
216
const alertTypes = Object . keys ( current )
222
217
alertTypes . map ( ( type : string ) => {
223
218
if ( ! acc [ type ] ) {
224
- acc [ type ] = current [ type ]
219
+ acc [ type ] = current [ type ] !
225
220
} else {
226
- acc [ type ] += current [ type ]
221
+ acc [ type ] += current [ type ] !
227
222
}
228
223
return acc
229
224
} )
230
225
return acc
231
- } , { } as { [ k : string ] : any } )
226
+ } , { } as { [ k : string ] : number } )
232
227
233
228
234
229
sortedTopFivealerts = Object . entries ( totalTopAlerts )
@@ -237,32 +232,32 @@ const formatData = (data: AnalyticsData[], scope: string) => {
237
232
. reduce ( ( r , [ k , v ] ) => ( { ...r , [ k ] : v } ) , { } )
238
233
239
234
const formatData = ( label : string ) => {
240
- return data . reduce ( ( acc , current ) => {
241
- const date : string = formatDate ( current . created_at )
235
+ return data . reduce ( ( acc : { [ k : string ] : number } , current : { [ key : string ] : any } ) => {
236
+ const date : string = formatDate ( current [ ' created_at' ] )
242
237
if ( ! acc [ date ] ) {
243
- acc [ date ] = current [ label ]
238
+ acc [ date ] = current [ label ] !
244
239
} else {
245
- acc [ date ] += current [ label ]
240
+ acc [ date ] += current [ label ] !
246
241
}
247
242
return acc
248
- } , { } as { [ k : string ] : number } )
243
+ } , { } )
249
244
}
250
245
251
246
formattedData = METRICS . reduce ( ( acc , current : string ) => {
252
247
acc [ current ] = formatData ( current )
253
248
return acc
254
- } , { } as { [ k : string ] : any } )
249
+ } , { } as { [ k : string ] : number } )
255
250
256
251
} else if ( scope === 'repo' ) {
257
252
258
- const topAlerts = data . reduce ( ( acc , current ) => {
259
- const alertTypes = Object . keys ( current . top_five_alert_types )
253
+ const topAlerts : { [ key : string ] : number } = data . reduce ( ( acc : { [ key : string ] : number } , current : { [ key : string ] : any } ) => {
254
+ const alertTypes = Object . keys ( current [ ' top_five_alert_types' ] )
260
255
alertTypes . map ( type => {
261
256
if ( ! acc [ type ] ) {
262
- acc [ type ] = current . top_five_alert_types [ type ]
257
+ acc [ type ] = current [ ' top_five_alert_types' ] [ type ]
263
258
} else {
264
- if ( current . top_five_alert_types [ type ] > acc [ type ] ) {
265
- acc [ type ] = current . top_five_alert_types [ type ]
259
+ if ( current [ ' top_five_alert_types' ] [ type ] > ( acc [ type ] || 0 ) ) {
260
+ acc [ type ] = current [ ' top_five_alert_types' ] [ type ]
266
261
}
267
262
}
268
263
return acc
@@ -271,20 +266,20 @@ const formatData = (data: AnalyticsData[], scope: string) => {
271
266
} , { } as { [ key : string ] : number } )
272
267
273
268
sortedTopFivealerts = Object . entries ( topAlerts )
274
- . sort ( ( [ , a ] : [ string , number ] , [ , b ] : [ string , number ] ) => b - a )
269
+ . sort ( ( [ , a ] , [ , b ] ) => b - a )
275
270
. slice ( 0 , 5 )
276
271
. reduce ( ( r , [ k , v ] ) => ( { ...r , [ k ] : v } ) , { } )
277
272
278
- formattedData = data . reduce ( ( acc , current ) => {
279
- METRICS . forEach ( ( m : string ) => {
280
- if ( ! acc [ m ] ) {
281
- acc [ m ] = { }
282
- }
283
- acc [ m ] [ formatDate ( current . created_at ) ] = current [ m ]
273
+ formattedData = data . reduce ( ( acc : any , current : { [ key : string ] : any } ) => {
274
+ METRICS . forEach ( ( m : string ) => {
275
+ if ( ! acc [ m ] ) {
276
+ acc [ m ] = { }
277
+ }
278
+ acc [ m ] [ formatDate ( current [ 'created_at' ] ) ] = current [ m ]
279
+ return acc
280
+ } )
284
281
return acc
285
- } )
286
- return acc
287
- } , { } as { [ k : string ] : any } )
282
+ } , { } as { [ k : string ] : number } )
288
283
}
289
284
290
285
return { ...formattedData , top_five_alert_types : sortedTopFivealerts }
@@ -312,7 +307,7 @@ async function fetchRepoAnalyticsData (repo: string, time: number, spinner: Ora,
312
307
return displayAnalyticsScreen ( data )
313
308
}
314
309
315
- const displayAnalyticsScreen = ( data : FormattedAnalyticsData ) => {
310
+ const displayAnalyticsScreen = ( data : any ) => {
316
311
const screen = blessed . screen ( )
317
312
// eslint-disable-next-line
318
313
const grid = new contrib . grid ( { rows : 5 , cols : 4 , screen} )
0 commit comments