本文整理汇总了TypeScript中src/shared/parsing/flux/response.parseResponse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parseResponse函数的具体用法?TypeScript parseResponse怎么用?TypeScript parseResponse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseResponse函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: extractCol
export function extractCol(
resp: ExecuteFluxQueryResult,
colName: string
): string[] {
const tables = parseResponse(resp.csv)
const data = get(tables, '0.data', [])
if (!data.length) {
return []
}
const colIndex = data[0].findIndex(d => d === colName)
if (colIndex === -1) {
throw new Error(`could not find column "${colName}" in response`)
}
const colValues = []
for (let i = 1; i < data.length; i++) {
colValues.push(data[i][colIndex])
}
return colValues
}
示例2: it
it('can parse identical series in different results', () => {
const resp = `#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,0,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:58Z,4906213376,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:54:08Z,5860683776,active,mem,oox4k.local
#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,1,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:48Z,4589981696,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:40:18Z,4318040064,active,mem,oox4k.local
`
const fluxTables = parseResponse(resp)
const actual = fluxTablesToDygraph(fluxTables)
expect(actual.dygraphsData).toEqual([
[new Date('2018-12-10T18:29:48.000Z'), null, 4589981696],
[new Date('2018-12-10T18:29:58.000Z'), 4906213376, null],
[new Date('2018-12-10T18:40:18.000Z'), null, 4318040064],
[new Date('2018-12-10T18:54:08.000Z'), 5860683776, null],
])
expect(actual.labels).toEqual([
'time',
'_value[result=0][_field=active][_measurement=mem][host=oox4k.local]',
'_value[result=1][_field=active][_measurement=mem][host=oox4k.local]',
])
})
示例3: test
test('uses the result name from the default annotation if result columns are empty', () => {
const resp = `#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,max,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:58Z,4906213376,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:54:08Z,5860683776,active,mem,oox4k.local
,,0,2018-12-10T19:00:00Z,2018-12-10T19:21:52.748859Z,2018-12-10T19:11:58Z,5115428864,active,mem,oox4k.local
#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,min,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:48Z,4589981696,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:40:18Z,4318040064,active,mem,oox4k.local
,,0,2018-12-10T19:00:00Z,2018-12-10T19:21:52.748859Z,2018-12-10T19:13:58Z,4131692544,active,mem,oox4k.local
`
const actual = parseResponse(resp)
expect(actual).toHaveLength(2)
expect(actual[0].result).toBe('max')
expect(actual[1].result).toBe('min')
})
示例4: async
export const executeQueryAsync = async (
query: string,
type: Query.TypeEnum = Query.TypeEnum.Influxql
): Promise<QueryResponse> => {
try {
const dialect = {
header: true,
annotations: [
Dialect.AnnotationsEnum.Datatype,
Dialect.AnnotationsEnum.Group,
Dialect.AnnotationsEnum.Default,
],
delimiter: ',',
}
const {data} = await queryAPI.queryPost(
'text/csv',
'application/json',
null,
null,
{type, query, dialect}
)
const tables = parseResponse(data)
const status = responseStatus(tables)
return {tables, status}
} catch (error) {
console.error(error)
return {
tables: [],
status: SearchStatus.SourceError,
}
}
}
示例5: test
test('with a schema conflict', () => {
const CSV = `#group,false,false,true,true,false,false,true,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,cpu,host
,,0,2019-02-01T23:38:32.524234Z,2019-02-01T23:39:02.524234Z,2019-02-01T23:38:33Z,10,usage_guest,cpu,cpu-total,oox4k.local
,,0,2019-02-01T23:38:32.524234Z,2019-02-01T23:39:02.524234Z,2019-02-01T23:38:43Z,20,usage_guest,cpu,cpu-total,oox4k.local
#group,false,false,true,true,false,false,true,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,string
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,cpu,host
,,1,2019-02-01T23:38:32.524234Z,2019-02-01T23:39:02.524234Z,2019-02-01T23:38:33Z,30,usage_guest,cpu,cpu0,oox4k.local
,,1,2019-02-01T23:38:32.524234Z,2019-02-01T23:39:02.524234Z,2019-02-01T23:38:43Z,40,usage_guest,cpu,cpu0,oox4k.local`
const tables = parseResponse(CSV)
const actual = toMinardTable(tables)
const expected = {
table: {
columns: {
result: {
data: ['_result', '_result', '_result', '_result'],
type: 'string',
},
_start: {
data: [1549064312524, 1549064312524, 1549064312524, 1549064312524],
type: 'time',
},
_stop: {
data: [1549064342524, 1549064342524, 1549064342524, 1549064342524],
type: 'time',
},
_time: {
data: [1549064313000, 1549064323000, 1549064313000, 1549064323000],
type: 'time',
},
_value: {data: [10, 20, undefined, undefined], type: 'float'},
_field: {
data: ['usage_guest', 'usage_guest', 'usage_guest', 'usage_guest'],
type: 'string',
},
_measurement: {data: ['cpu', 'cpu', 'cpu', 'cpu'], type: 'string'},
cpu: {
data: ['cpu-total', 'cpu-total', 'cpu0', 'cpu0'],
type: 'string',
},
host: {
data: ['oox4k.local', 'oox4k.local', 'oox4k.local', 'oox4k.local'],
type: 'string',
},
},
length: 4,
},
schemaConflicts: ['_value'],
}
expect(actual).toEqual(expected)
})
示例6: test
test('the last value returned does not depend on the ordering of series', () => {
const respA = `#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,0,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:58Z,1,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:54:08Z,2,active,mem,oox4k.local
#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,1,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:48Z,3,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:40:18Z,4,active,mem,oox4k.local
`
const respB = `#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,1,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:48Z,3,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:40:18Z,4,active,mem,oox4k.local
#group,false,false,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string
#default,0,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,host
,,0,2018-12-10T18:21:52.748859Z,2018-12-10T18:30:00Z,2018-12-10T18:29:58Z,1,active,mem,oox4k.local
,,0,2018-12-10T18:30:00Z,2018-12-10T19:00:00Z,2018-12-10T18:54:08Z,2,active,mem,oox4k.local
`
const lastValueA = lastValue(parseResponse(respA))
const lastValueB = lastValue(parseResponse(respB))
expect(lastValueA).toEqual(2)
expect(lastValueB).toEqual(2)
})