Browse Source

fix missing column

pull/12/head
vargburz 2 years ago
parent
commit
322620952d
  1. 24
      src/services/exporter.ts

24
src/services/exporter.ts

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

Loading…
Cancel
Save