|
| 1 | +// @ts-nocheck |
| 2 | +// @ts-ignore |
| 3 | +import blessed from 'blessed' |
| 4 | +import contrib from 'blessed-contrib' |
1 | 5 | import chalk from 'chalk'
|
2 |
| -import meow from 'meow' |
3 |
| -import ora from 'ora' |
4 | 6 | // @ts-ignore
|
5 | 7 | import chalkTable from 'chalk-table'
|
| 8 | +import meow from 'meow' |
| 9 | +import ora from 'ora' |
6 | 10 |
|
7 | 11 | import { outputFlags, validationFlags } from '../flags'
|
8 | 12 | import { handleApiCall, handleUnsuccessfulApiResponse } from '../utils/api-helpers'
|
@@ -108,43 +112,71 @@ async function fetchOrgAnalyticsData (time: string, spinner: Ora, apiKey: string
|
108 | 112 |
|
109 | 113 | spinner.stop()
|
110 | 114 |
|
111 |
| - const data = result.data.reduce((acc: { [key: string]: any }, current) => { |
112 |
| - const formattedDate = new Date(current.created_at).toLocaleDateString() |
113 |
| - |
114 |
| - if (acc[formattedDate]) { |
115 |
| - acc[formattedDate].total_critical_alerts += current.total_critical_alerts |
116 |
| - acc[formattedDate].total_high_alerts += current.total_high_alerts |
117 |
| - acc[formattedDate].total_critical_added += current.total_critical_added |
118 |
| - acc[formattedDate].total_high_added += current.total_high_added |
119 |
| - acc[formattedDate].total_critical_prevented += current.total_critical_prevented |
120 |
| - acc[formattedDate].total_high_prevented += current.total_high_prevented |
121 |
| - acc[formattedDate].total_medium_prevented += current.total_medium_prevented |
122 |
| - acc[formattedDate].total_low_prevented += current.total_low_prevented |
123 |
| - // acc[formattedDate].top_five_alert_types += current.top_five_alert_types |
124 |
| - } else { |
125 |
| - acc[formattedDate] = current |
126 |
| - acc[formattedDate].created_at = formattedDate |
127 |
| - } |
| 115 | + // const data = result.data.reduce((acc: { [key: string]: any }, current) => { |
| 116 | + // const formattedDate = new Date(current.created_at).toLocaleDateString() |
| 117 | + |
| 118 | + // if (acc[formattedDate]) { |
| 119 | + // acc[formattedDate].total_critical_alerts += current.total_critical_alerts |
| 120 | + // acc[formattedDate].total_high_alerts += current.total_high_alerts |
| 121 | + // acc[formattedDate].total_critical_added += current.total_critical_added |
| 122 | + // acc[formattedDate].total_high_added += current.total_high_added |
| 123 | + // acc[formattedDate].total_critical_prevented += current.total_critical_prevented |
| 124 | + // acc[formattedDate].total_high_prevented += current.total_high_prevented |
| 125 | + // acc[formattedDate].total_medium_prevented += current.total_medium_prevented |
| 126 | + // acc[formattedDate].total_low_prevented += current.total_low_prevented |
| 127 | + // // acc[formattedDate].top_five_alert_types += current.top_five_alert_types |
| 128 | + // } else { |
| 129 | + // acc[formattedDate] = current |
| 130 | + // acc[formattedDate].created_at = formattedDate |
| 131 | + // } |
| 132 | + |
| 133 | + // return acc |
| 134 | + // }, {}) |
| 135 | + |
| 136 | + |
| 137 | + // const options = { |
| 138 | + // columns: [ |
| 139 | + // { field: 'created_at', name: chalk.cyan('Date') }, |
| 140 | + // { field: 'total_critical_alerts', name: chalk.cyan('Critical alerts') }, |
| 141 | + // { field: 'total_high_alerts', name: chalk.cyan('High alerts') }, |
| 142 | + // { field: 'total_critical_added', name: chalk.cyan('Critical alerts added') }, |
| 143 | + // { field: 'total_high_added', name: chalk.cyan('High alerts added') }, |
| 144 | + // { field: 'total_critical_prevented', name: chalk.cyan('Critical alerts prevented') }, |
| 145 | + // { field: 'total_medium_prevented', name: chalk.cyan('Medium alerts prevented') }, |
| 146 | + // { field: 'total_low_prevented', name: chalk.cyan('Low alerts prevented') }, |
| 147 | + // ] |
| 148 | + // } |
| 149 | + |
| 150 | + // console.log(chalk.bgMagenta.white.bold(`\n Analytics data at the organization level over the last ${time} days (indicated in total amount): \n`)) |
| 151 | + // console.log(`${chalkTable(options, Object.values(data))}\n`) |
| 152 | + |
| 153 | + const screen = blessed.screen() |
| 154 | + // eslint-disable-next-line |
| 155 | + const grid = new contrib.grid({rows: 1, cols: 2, screen}) |
| 156 | + |
| 157 | + const line = grid.set(0, 0, 1, 1, contrib.line, |
| 158 | + { style: |
| 159 | + { line: "yellow" |
| 160 | + , text: "green" |
| 161 | + , baseline: "black"} |
| 162 | + , xLabelPadding: 3 |
| 163 | + , xPadding: 5 |
| 164 | + , label: 'Stocks'}) |
| 165 | + |
| 166 | + // const map = grid.set(0, 1, 1, 1, contrib.map, {label: 'Servers Location'}) |
| 167 | + |
| 168 | + const lineData = { |
| 169 | + x: ['t1', 't2', 't3', 't4'], |
| 170 | + y: [5, 1, 7, 5] |
| 171 | + } |
128 | 172 |
|
129 |
| - return acc |
130 |
| - }, {}) |
| 173 | + line.setData([lineData]) |
131 | 174 |
|
| 175 | + screen.key(['escape', 'q', 'C-c'], function(ch, key) { |
| 176 | + return process.exit(0); |
| 177 | + }); |
132 | 178 |
|
133 |
| - const options = { |
134 |
| - columns: [ |
135 |
| - { field: 'created_at', name: chalk.cyan('Date') }, |
136 |
| - { field: 'total_critical_alerts', name: chalk.cyan('Critical alerts') }, |
137 |
| - { field: 'total_high_alerts', name: chalk.cyan('High alerts') }, |
138 |
| - { field: 'total_critical_added', name: chalk.cyan('Critical alerts added') }, |
139 |
| - { field: 'total_high_added', name: chalk.cyan('High alerts added') }, |
140 |
| - { field: 'total_critical_prevented', name: chalk.cyan('Critical alerts prevented') }, |
141 |
| - { field: 'total_medium_prevented', name: chalk.cyan('Medium alerts prevented') }, |
142 |
| - { field: 'total_low_prevented', name: chalk.cyan('Low alerts prevented') }, |
143 |
| - ] |
144 |
| - } |
145 |
| - |
146 |
| - console.log(chalk.bgMagenta.white.bold(`\n Analytics data at the organization level over the last ${time} days (indicated in total amount): \n`)) |
147 |
| - console.log(`${chalkTable(options, Object.values(data))}\n`) |
| 179 | + screen.render() |
148 | 180 | }
|
149 | 181 |
|
150 | 182 | async function fetchRepoAnalyticsData (repo: string, time: string, spinner: Ora, apiKey: string): Promise<void> {
|
|
0 commit comments