|
|
|
@ -63,25 +63,29 @@ export class Exporter {
|
|
|
|
|
console.log(`Total days: ${days}`); |
|
|
|
|
|
|
|
|
|
const stream = this._initCsvStream(); |
|
|
|
|
console.log("queryConfigs", queryConfigs); |
|
|
|
|
|
|
|
|
|
for(let day = 0; day < days; day++) { |
|
|
|
|
to = from + MS_IN_DAY; |
|
|
|
|
|
|
|
|
|
console.log(`${day} day: ${from}ms -> ${to}ms`); |
|
|
|
|
|
|
|
|
|
let columns = []; |
|
|
|
|
let metricColumns = []; |
|
|
|
|
let keyColumn; |
|
|
|
|
let rowsDict = {}; |
|
|
|
|
|
|
|
|
|
for(const queryConfig of queryConfigs) { |
|
|
|
|
const datasourceMetrics: DataTable = await queryByConfig(queryConfig, datasourceUrl, from, to, apiKey); |
|
|
|
|
columns = this._updateColumns(columns, datasourceMetrics.columns); |
|
|
|
|
if(keyColumn == undefined) { |
|
|
|
|
keyColumn = datasourceMetrics.columns[0]; |
|
|
|
|
} |
|
|
|
|
metricColumns = this._updateColumns(metricColumns, datasourceMetrics.columns); |
|
|
|
|
rowsDict = this._updateRows(rowsDict, datasourceMetrics.values, datasourceMetrics.columns); |
|
|
|
|
} |
|
|
|
|
const rows = this._getRowsFromDict(rowsDict, columns); |
|
|
|
|
// const formattedRows = rows.map((row: number[]) => [toIsoString(row[0], timeZoneName), ...row.slice(1)]);
|
|
|
|
|
const rows = this._getRowsFromDict(rowsDict, metricColumns); |
|
|
|
|
const columns = _.concat(keyColumn, metricColumns); |
|
|
|
|
const formattedRows = rows.map((row: number[]) => [toIsoString(row[0], timeZoneName), ...row.slice(1)]); |
|
|
|
|
|
|
|
|
|
if(columns.length > 0) { |
|
|
|
|
this._writeCsv(stream, { columns, rows }); |
|
|
|
|
if(metricColumns.length > 0) { |
|
|
|
|
this._writeCsv(stream, { columns, rows: formattedRows }); |
|
|
|
|
} |
|
|
|
|
await this._updateProgress({ status: ExportStatus.EXPORTING, progress: (day + 1) / days }); |
|
|
|
|
|
|
|
|
@ -98,7 +102,7 @@ export class Exporter {
|
|
|
|
|
return _.concat(columnsToUpdate, queriedColumns.slice(1)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private _updateRows(dict, queriedRows: (number | null)[][], queriedColumns: string[]): any { |
|
|
|
|
private _updateRows(dict, queriedRows: (number | null)[][], queriedColumns: string[]): { [key: number]: { [column: string]: number} } { |
|
|
|
|
const columns = queriedColumns.slice(1); |
|
|
|
|
for(const rowIdx in queriedRows) { |
|
|
|
|
const key = queriedRows[rowIdx][0]; |
|
|
|
@ -115,7 +119,7 @@ export class Exporter {
|
|
|
|
|
let keyList = _.orderBy(_.keys(dict)); |
|
|
|
|
let rows = []; |
|
|
|
|
for(const keyIdx in keyList) { |
|
|
|
|
const key = keyList[keyIdx]; |
|
|
|
|
const key = _.toNumber(keyList[keyIdx]); |
|
|
|
|
rows[keyIdx] = [key]; |
|
|
|
|
for(const column of columns) { |
|
|
|
|
const value = dict[key][column] || null; |
|
|
|
|