fix(ui): handle flux tables with no time column

pull/5997/head
Pavel Zavora 2022-08-16 19:43:50 +02:00
parent 0433845c26
commit f89482808c
1 changed files with 54 additions and 50 deletions

View File

@ -42,64 +42,68 @@ export const parseTablesByTime = (
const allColumnNames = [] const allColumnNames = []
const nonNumericColumns = [] const nonNumericColumns = []
const tablesByTime = tables.map(table => { const tablesByTime = tables
const header = table.data[0] as string[] .map(table => {
const columnNames: {[k: number]: string} = {} const header = table.data[0] as string[]
const columnNames: {[k: number]: string} = {}
for (let i = 0; i < header.length; i++) { for (let i = 0; i < header.length; i++) {
const columnName = header[i] const columnName = header[i]
const dataType = table.dataTypes[columnName] const dataType = table.dataTypes[columnName]
if (COLUMN_BLACKLIST.has(columnName)) { if (COLUMN_BLACKLIST.has(columnName)) {
continue continue
}
if (table.groupKey[columnName]) {
continue
}
if (!NUMERIC_DATATYPES.includes(dataType)) {
nonNumericColumns.push(columnName)
continue
}
const uniqueColumnName = fluxTableKey(table, columnName)
columnNames[i] = uniqueColumnName
allColumnNames.push(uniqueColumnName)
} }
if (table.groupKey[columnName]) { let timeIndex = header.indexOf('_time')
continue
let isTimeFound = true
if (timeIndex < 0) {
timeIndex = header.indexOf('_stop')
if (timeIndex < 0) {
return undefined
}
isTimeFound = false
} }
if (!NUMERIC_DATATYPES.includes(dataType)) { const result = {}
nonNumericColumns.push(columnName) for (let i = 1; i < table.data.length; i++) {
continue const row = table.data[i]
const timeValue = row[timeIndex]
let time: string
if (isTimeFound) {
time = timeValue.toString()
} else {
// _stop and _start have values in date string format instead of number
time = Date.parse(timeValue as string).toString()
}
result[time] = Object.entries(columnNames).reduce(
(acc, [valueIndex, columnName]) => ({
...acc,
[columnName]: row[valueIndex],
}),
{}
)
} }
const uniqueColumnName = fluxTableKey(table, columnName) return result
})
columnNames[i] = uniqueColumnName .filter(x => x !== undefined)
allColumnNames.push(uniqueColumnName)
}
let timeIndex = header.indexOf('_time')
let isTimeFound = true
if (timeIndex < 0) {
timeIndex = header.indexOf('_stop')
isTimeFound = false
}
const result = {}
for (let i = 1; i < table.data.length; i++) {
const row = table.data[i]
const timeValue = row[timeIndex]
let time = ''
if (isTimeFound) {
time = timeValue.toString()
} else {
// _stop and _start have values in date string format instead of number
time = Date.parse(timeValue as string).toString()
}
result[time] = Object.entries(columnNames).reduce(
(acc, [valueIndex, columnName]) => ({
...acc,
[columnName]: row[valueIndex],
}),
{}
)
}
return result
})
return {nonNumericColumns, tablesByTime, allColumnNames} return {nonNumericColumns, tablesByTime, allColumnNames}
} }