Skip to content

Commit 0c44a09

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 f79e9de commit 0c44a09

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-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: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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';
10+
// import { Range } from '../models/sampling';
1111

1212
describe('HttpTspClient Deserialization', () => {
1313

@@ -349,11 +349,17 @@ describe('HttpTspClient Deserialization', () => {
349349
expect(xy.series).toHaveLength(1);
350350
for (const serie of xy.series) {
351351
expect(typeof serie.seriesId).toEqual('number');
352+
expect(serie.xValues).toBeDefined();
353+
expect(serie.xRanges).toBeUndefined();
354+
expect(serie.xCategories).toBeUndefined();
352355
expect(serie.xValues).toHaveLength(3);
353356
expect(serie.yValues).toHaveLength(3);
354-
for (const xValue of serie.xValues) {
355-
expect(typeof xValue).toEqual('bigint');
356-
}
357+
if (serie.xValues) {
358+
for (const xValue of serie.xValues) {
359+
expect(typeof xValue).toEqual('bigint');
360+
}
361+
}
362+
357363
for (const yValue of serie.yValues) {
358364
expect(typeof yValue).toEqual('number');
359365
}
@@ -370,21 +376,18 @@ describe('HttpTspClient Deserialization', () => {
370376
expect(xy.series).toHaveLength(4);
371377
for (const serie of xy.series) {
372378
expect(typeof serie.seriesId).toEqual('number');
373-
expect(serie.xValues).toHaveLength(5);
379+
expect(serie.xValues).toBeUndefined();
380+
expect(serie.xRanges).toBeDefined();
381+
expect(serie.xCategories).toBeUndefined();
382+
expect(serie.xRanges).toHaveLength(5);
374383
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})');
384+
385+
if (serie.xRanges) {
386+
for (const xValue of serie.xRanges) {
387+
expect(typeof xValue.start).toBe('bigint');
388+
expect(typeof xValue.end).toBe('bigint');
386389
}
387-
}
390+
}
388391

389392
for (const yValue of serie.yValues) {
390393
expect(typeof yValue).toEqual('number');
@@ -419,10 +422,16 @@ describe('HttpTspClient Deserialization', () => {
419422
expect(xy_categorized.series).toHaveLength(1);
420423
for (const serie of xy_categorized.series) {
421424
expect(typeof serie.seriesId).toEqual('number');
422-
expect(serie.xValues).toHaveLength(5);
425+
expect(serie.xValues).toBeUndefined();
426+
expect(serie.xRanges).toBeUndefined();
427+
expect(serie.xCategories).toBeDefined();
428+
429+
expect(serie.xCategories).toHaveLength(5);
423430
expect(serie.yValues).toHaveLength(5);
424-
for (const xValue of serie.xValues) {
425-
expect(typeof xValue).toEqual('string');
431+
if (serie.xCategories) {
432+
for (const xValue of serie.xCategories) {
433+
expect(typeof xValue).toEqual('string');
434+
}
426435
}
427436

428437
for (const yValue of serie.yValues) {

0 commit comments

Comments
 (0)