Skip to content

Commit 49ac085

Browse files
committed
Further fix parsing of sampling to match tsp specification
The server was modified to comply to tsp specification for sampling, update accordingly here. There are now 3 different arrays for x values: xValues (legacy xy for timestamps), xCategories (array of string) and xRanges (array of StartEndRanges). Note that StartEndRange is now an object with start and end attributes. Before it was an array with 2 values. Contributes to fix: eclipse-tracecompass-incubator/org.eclipse.tracecompass.incubator#236 Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 29336d2 commit 49ac085

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

tsp-typescript-client/fixtures/tsp-client/fetch-generic-xy-0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"seriesId": 3,
77
"seriesName": "15652",
8-
"xValues": [
8+
"xRanges": [
99
{
1010
"start": 0,
1111
"end": 604229397
@@ -60,7 +60,7 @@
6060
{
6161
"seriesId": 4,
6262
"seriesName": "15653",
63-
"xValues": [
63+
"xRanges": [
6464
{
6565
"start": 0,
6666
"end": 604229397
@@ -115,7 +115,7 @@
115115
{
116116
"seriesId": 2,
117117
"seriesName": "15646",
118-
"xValues": [
118+
"xRanges": [
119119
{
120120
"start": 0,
121121
"end": 604229397
@@ -170,7 +170,7 @@
170170
{
171171
"seriesId": 1,
172172
"seriesName": "15647",
173-
"xValues": [
173+
"xRanges": [
174174
{
175175
"start": 0,
176176
"end": 604229397

tsp-typescript-client/fixtures/tsp-client/fetch-generic-xy-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"seriesId": 3,
77
"seriesName": "15652",
8-
"xValues": [
8+
"xCategories": [
99
"red",
1010
"blue",
1111
"green",

tsp-typescript-client/src/models/xy.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { array, assertNumber, createNormalizer, toBigInt } from '../protocol/serialization';
22
import { AxisDomain } from './axis-domain';
33
import { DataType } from './data-type';
44
import { Entry } from './entry';
5-
import { Sampling } from './sampling';
5+
import { StartEndRange } from './sampling';
66
import { OutputElementStyle } from "./styles";
77

88
export const XYAxisDescription = createNormalizer<XYAxisDescription>({
@@ -11,7 +11,8 @@ export const XYAxisDescription = createNormalizer<XYAxisDescription>({
1111

1212
export const XYSeries = createNormalizer<XYSeries>({
1313
seriesId: assertNumber,
14-
xValues: Sampling,
14+
xValues: array(toBigInt),
15+
xRanges: array(StartEndRange),
1516
yValues: array(assertNumber),
1617
tags: array(assertNumber),
1718
style: OutputElementStyle,
@@ -53,8 +54,11 @@ export interface XYSeries {
5354
/**
5455
* Series' X values
5556
*/
56-
xValues: Sampling;
57+
xValues?: bigint[];
5758

59+
xRanges?: StartEndRange[];
60+
61+
xCategories?: string[];
5862
/**
5963
* Series' Y values
6064
*/

tsp-typescript-client/src/protocol/tsp-client.test.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { DataType } from '../models/data-type';
77
import { ConfigurationParameterDescriptor } from '../models/configuration-source';
88
import { QueryHelper } from '../models/query/query-helper';
99
import { isAxisDomainCategorical, isAxisDomainRange } from '../models/axis-domain';
10-
import { StartEndRange } from '../models/sampling';
1110

1211
describe('HttpTspClient Deserialization', () => {
1312

@@ -349,11 +348,17 @@ describe('HttpTspClient Deserialization', () => {
349348
expect(xy.series).toHaveLength(1);
350349
for (const serie of xy.series) {
351350
expect(typeof serie.seriesId).toEqual('number');
351+
expect(serie.xValues).toBeDefined();
352+
expect(serie.xRanges).toBeUndefined();
353+
expect(serie.xCategories).toBeUndefined();
352354
expect(serie.xValues).toHaveLength(3);
353355
expect(serie.yValues).toHaveLength(3);
354-
for (const xValue of serie.xValues) {
355-
expect(typeof xValue).toEqual('bigint');
356-
}
356+
if (serie.xValues) {
357+
for (const xValue of serie.xValues) {
358+
expect(typeof xValue).toEqual('bigint');
359+
}
360+
}
361+
357362
for (const yValue of serie.yValues) {
358363
expect(typeof yValue).toEqual('number');
359364
}
@@ -370,21 +375,18 @@ describe('HttpTspClient Deserialization', () => {
370375
expect(xy.series).toHaveLength(4);
371376
for (const serie of xy.series) {
372377
expect(typeof serie.seriesId).toEqual('number');
373-
expect(serie.xValues).toHaveLength(5);
378+
expect(serie.xValues).toBeUndefined();
379+
expect(serie.xRanges).toBeDefined();
380+
expect(serie.xCategories).toBeUndefined();
381+
expect(serie.xRanges).toHaveLength(5);
374382
expect(serie.yValues).toHaveLength(5);
375-
for (const xValue of serie.xValues) {
376-
if (
377-
typeof xValue === 'object' &&
378-
xValue !== null &&
379-
!Array.isArray(xValue)
380-
) {
381-
const rangeObject = xValue as StartEndRange;
382-
expect(typeof rangeObject.start).toBe('bigint');
383-
expect(typeof rangeObject.end).toBe('bigint');
384-
} else {
385-
throw new Error('xValue is not a valid StartEndRange object ({start, end})');
383+
384+
if (serie.xRanges) {
385+
for (const xValue of serie.xRanges) {
386+
expect(typeof xValue.start).toBe('bigint');
387+
expect(typeof xValue.end).toBe('bigint');
386388
}
387-
}
389+
}
388390

389391
for (const yValue of serie.yValues) {
390392
expect(typeof yValue).toEqual('number');
@@ -419,10 +421,16 @@ describe('HttpTspClient Deserialization', () => {
419421
expect(xy_categorized.series).toHaveLength(1);
420422
for (const serie of xy_categorized.series) {
421423
expect(typeof serie.seriesId).toEqual('number');
422-
expect(serie.xValues).toHaveLength(5);
424+
expect(serie.xValues).toBeUndefined();
425+
expect(serie.xRanges).toBeUndefined();
426+
expect(serie.xCategories).toBeDefined();
427+
428+
expect(serie.xCategories).toHaveLength(5);
423429
expect(serie.yValues).toHaveLength(5);
424-
for (const xValue of serie.xValues) {
425-
expect(typeof xValue).toEqual('string');
430+
if (serie.xCategories) {
431+
for (const xValue of serie.xCategories) {
432+
expect(typeof xValue).toEqual('string');
433+
}
426434
}
427435

428436
for (const yValue of serie.yValues) {

0 commit comments

Comments
 (0)