@perses-dev/core 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/calculations.js +112 -33
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/legend.js +19 -2
- package/dist/cjs/model/units/bytes.js +84 -0
- package/dist/cjs/model/units/constants.js +23 -0
- package/dist/cjs/model/units/decimal.js +62 -0
- package/dist/cjs/model/units/index.js +31 -0
- package/dist/cjs/model/units/percent.js +73 -0
- package/dist/cjs/model/units/time.js +105 -0
- package/dist/cjs/model/units/types.js +28 -0
- package/dist/cjs/model/units/units.js +101 -0
- package/dist/cjs/model/units/utils.js +42 -0
- package/dist/cjs/model/variables.js +5 -0
- package/dist/model/calculations.d.ts +29 -5
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +121 -28
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/dashboard.d.ts +1 -0
- package/dist/model/dashboard.d.ts.map +1 -1
- package/dist/model/dashboard.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +5 -0
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +15 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/thresholds.d.ts +4 -0
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/units/bytes.d.ts +13 -0
- package/dist/model/units/bytes.d.ts.map +1 -0
- package/dist/model/units/bytes.js +66 -0
- package/dist/model/units/bytes.js.map +1 -0
- package/dist/model/units/constants.d.ts +2 -0
- package/dist/model/units/constants.d.ts.map +1 -0
- package/dist/model/units/constants.js +17 -0
- package/dist/model/units/constants.js.map +1 -0
- package/dist/model/units/decimal.d.ts +13 -0
- package/dist/model/units/decimal.d.ts.map +1 -0
- package/dist/model/units/decimal.js +49 -0
- package/dist/model/units/decimal.js.map +1 -0
- package/dist/model/units/index.d.ts +5 -0
- package/dist/model/units/index.d.ts.map +1 -0
- package/dist/model/units/index.js +18 -0
- package/dist/model/units/index.js.map +1 -0
- package/dist/model/units/percent.d.ts +12 -0
- package/dist/model/units/percent.d.ts.map +1 -0
- package/dist/model/units/percent.js +60 -0
- package/dist/model/units/percent.js.map +1 -0
- package/dist/model/units/time.d.ts +22 -0
- package/dist/model/units/time.d.ts.map +1 -0
- package/dist/model/units/time.js +91 -0
- package/dist/model/units/time.js.map +1 -0
- package/dist/model/units/types.d.ts +47 -0
- package/dist/model/units/types.d.ts.map +1 -0
- package/dist/model/units/types.js +22 -0
- package/dist/model/units/types.js.map +1 -0
- package/dist/model/units/units.d.ts +40 -0
- package/dist/model/units/units.d.ts.map +1 -0
- package/dist/model/units/units.js +80 -0
- package/dist/model/units/units.js.map +1 -0
- package/dist/model/units/utils.d.ts +4 -0
- package/dist/model/units/utils.d.ts.map +1 -0
- package/dist/model/units/utils.js +32 -0
- package/dist/model/units/utils.js.map +1 -0
- package/dist/model/variables.d.ts +1 -0
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +1 -1
- package/dist/model/variables.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
UNIT_GROUP_CONFIG: ()=>UNIT_GROUP_CONFIG,
|
|
25
|
+
UNIT_CONFIG: ()=>UNIT_CONFIG,
|
|
26
|
+
formatValue: ()=>formatValue,
|
|
27
|
+
getUnitKindConfig: ()=>getUnitKindConfig,
|
|
28
|
+
getUnitGroup: ()=>getUnitGroup,
|
|
29
|
+
getUnitGroupConfig: ()=>getUnitGroupConfig,
|
|
30
|
+
isTimeUnit: ()=>isTimeUnit,
|
|
31
|
+
isPercentUnit: ()=>isPercentUnit,
|
|
32
|
+
isDecimalUnit: ()=>isDecimalUnit,
|
|
33
|
+
isBytesUnit: ()=>isBytesUnit,
|
|
34
|
+
isUnitWithDecimalPlaces: ()=>isUnitWithDecimalPlaces,
|
|
35
|
+
isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
|
|
36
|
+
});
|
|
37
|
+
const _bytes = require("./bytes");
|
|
38
|
+
const _decimal = require("./decimal");
|
|
39
|
+
const _percent = require("./percent");
|
|
40
|
+
const _time = require("./time");
|
|
41
|
+
const UNIT_GROUP_CONFIG = {
|
|
42
|
+
Time: _time.TIME_GROUP_CONFIG,
|
|
43
|
+
Percent: _percent.PERCENT_GROUP_CONFIG,
|
|
44
|
+
Decimal: _decimal.DECIMAL_GROUP_CONFIG,
|
|
45
|
+
Bytes: _bytes.BYTES_GROUP_CONFIG
|
|
46
|
+
};
|
|
47
|
+
const UNIT_CONFIG = {
|
|
48
|
+
..._time.TIME_UNIT_CONFIG,
|
|
49
|
+
..._percent.PERCENT_UNIT_CONFIG,
|
|
50
|
+
..._decimal.DECIMAL_UNIT_CONFIG,
|
|
51
|
+
..._bytes.BYTES_UNIT_CONFIG
|
|
52
|
+
};
|
|
53
|
+
function formatValue(value, unitOptions) {
|
|
54
|
+
if (unitOptions === undefined) {
|
|
55
|
+
return value.toString();
|
|
56
|
+
}
|
|
57
|
+
if (isDecimalUnit(unitOptions)) {
|
|
58
|
+
return (0, _decimal.formatDecimal)(value, unitOptions);
|
|
59
|
+
}
|
|
60
|
+
if (isTimeUnit(unitOptions)) {
|
|
61
|
+
return (0, _time.formatTime)(value, unitOptions);
|
|
62
|
+
}
|
|
63
|
+
if (isPercentUnit(unitOptions)) {
|
|
64
|
+
return (0, _percent.formatPercent)(value, unitOptions);
|
|
65
|
+
}
|
|
66
|
+
if (isBytesUnit(unitOptions)) {
|
|
67
|
+
return (0, _bytes.formatBytes)(value, unitOptions);
|
|
68
|
+
}
|
|
69
|
+
const exhaustive = unitOptions;
|
|
70
|
+
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
71
|
+
}
|
|
72
|
+
function getUnitKindConfig(unitOptions) {
|
|
73
|
+
return UNIT_CONFIG[unitOptions.kind];
|
|
74
|
+
}
|
|
75
|
+
function getUnitGroup(unitOptions) {
|
|
76
|
+
return getUnitKindConfig(unitOptions).group;
|
|
77
|
+
}
|
|
78
|
+
function getUnitGroupConfig(unitOptions) {
|
|
79
|
+
const unitConfig = getUnitKindConfig(unitOptions);
|
|
80
|
+
return UNIT_GROUP_CONFIG[unitConfig.group];
|
|
81
|
+
}
|
|
82
|
+
function isTimeUnit(unitOptions) {
|
|
83
|
+
return getUnitGroup(unitOptions) === 'Time';
|
|
84
|
+
}
|
|
85
|
+
function isPercentUnit(unitOptions) {
|
|
86
|
+
return getUnitGroup(unitOptions) === 'Percent';
|
|
87
|
+
}
|
|
88
|
+
function isDecimalUnit(unitOptions) {
|
|
89
|
+
return getUnitGroup(unitOptions) === 'Decimal';
|
|
90
|
+
}
|
|
91
|
+
function isBytesUnit(unitOptions) {
|
|
92
|
+
return getUnitGroup(unitOptions) === 'Bytes';
|
|
93
|
+
}
|
|
94
|
+
function isUnitWithDecimalPlaces(unitOptions) {
|
|
95
|
+
const groupConfig = getUnitGroupConfig(unitOptions);
|
|
96
|
+
return !!groupConfig.decimal_places;
|
|
97
|
+
}
|
|
98
|
+
function isUnitWithAbbreviate(unitOptions) {
|
|
99
|
+
const groupConfig = getUnitGroupConfig(unitOptions);
|
|
100
|
+
return !!groupConfig.abbreviate;
|
|
101
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
shouldAbbreviate: ()=>shouldAbbreviate,
|
|
25
|
+
hasDecimalPlaces: ()=>hasDecimalPlaces,
|
|
26
|
+
limitDecimalPlaces: ()=>limitDecimalPlaces
|
|
27
|
+
});
|
|
28
|
+
function shouldAbbreviate(abbreviate) {
|
|
29
|
+
return abbreviate !== false;
|
|
30
|
+
}
|
|
31
|
+
function hasDecimalPlaces(decimal_places) {
|
|
32
|
+
return typeof decimal_places === 'number';
|
|
33
|
+
}
|
|
34
|
+
function limitDecimalPlaces(num) {
|
|
35
|
+
if (!num) return num;
|
|
36
|
+
if (num < 0) {
|
|
37
|
+
num = 0;
|
|
38
|
+
} else if (num > 20) {
|
|
39
|
+
num = 20;
|
|
40
|
+
}
|
|
41
|
+
return num;
|
|
42
|
+
}
|
|
@@ -2,20 +2,44 @@ import { TimeSeriesValueTuple } from '@perses-dev/core';
|
|
|
2
2
|
export declare const CalculationsMap: {
|
|
3
3
|
First: typeof first;
|
|
4
4
|
Last: typeof last;
|
|
5
|
+
FirstNumber: typeof firstNumber;
|
|
5
6
|
LastNumber: typeof lastNumber;
|
|
6
7
|
Mean: typeof mean;
|
|
7
8
|
Sum: typeof sum;
|
|
9
|
+
Min: typeof min;
|
|
10
|
+
Max: typeof max;
|
|
8
11
|
};
|
|
9
12
|
export declare type CalculationType = keyof typeof CalculationsMap;
|
|
10
13
|
export declare type CalculationConfig = {
|
|
11
14
|
label: string;
|
|
15
|
+
description: string;
|
|
12
16
|
};
|
|
13
17
|
export declare const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>>;
|
|
14
18
|
export declare const DEFAULT_CALCULATION: CalculationType;
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
declare type CalculationValue = number | null | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Calculate a multiple values for a set of time series data.
|
|
22
|
+
*
|
|
23
|
+
* @param values - Array of time series data.
|
|
24
|
+
* @param includeCalculations - Array of calculations to include.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCalculations<IncludeCalcs extends CalculationType[]>(values: TimeSeriesValueTuple[], includeCalculations: IncludeCalcs): Record<Extract<CalculationType, IncludeCalcs[number]>, CalculationValue>;
|
|
27
|
+
/**
|
|
28
|
+
* Calculate a single value for a set of time series data.
|
|
29
|
+
*
|
|
30
|
+
* Use `getCalculations` instead if you need multiple calculations.
|
|
31
|
+
*
|
|
32
|
+
* @param values - Array of time series data.
|
|
33
|
+
* @param calculation - Name of the calculation to calculate.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType): CalculationValue;
|
|
36
|
+
declare function first(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
37
|
+
declare function last(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
38
|
+
declare function firstNumber(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
39
|
+
declare function lastNumber(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
40
|
+
declare function mean(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
41
|
+
declare function sum(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
42
|
+
declare function min(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
43
|
+
declare function max(values: TimeSeriesValueTuple[]): CalculationValue;
|
|
20
44
|
export {};
|
|
21
45
|
//# sourceMappingURL=calculations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,eAAO,MAAM,mBAAmB,EAAE,eAAuB,CAAC;AAE1D,aAAK,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,SAAS,eAAe,EAAE,EACpE,MAAM,EAAE,oBAAoB,EAAE,EAC9B,mBAAmB,EAAE,YAAY,GAChC,MAAM,CAGP,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,EAC9C,gBAAgB,CACjB,CA2EA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,oBAE1F;AAED,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE/D;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAErE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAEpE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D"}
|
|
@@ -10,63 +10,156 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import findLast from 'lodash/findLast';
|
|
14
|
-
import meanBy from 'lodash/meanBy';
|
|
15
|
-
import sumBy from 'lodash/sumBy';
|
|
16
|
-
// TODO: move this file and calculations.test.ts to @perses-dev/core
|
|
17
13
|
export const CalculationsMap = {
|
|
18
14
|
First: first,
|
|
19
15
|
Last: last,
|
|
16
|
+
FirstNumber: firstNumber,
|
|
20
17
|
LastNumber: lastNumber,
|
|
21
18
|
Mean: mean,
|
|
22
|
-
Sum: sum
|
|
19
|
+
Sum: sum,
|
|
20
|
+
Min: min,
|
|
21
|
+
Max: max
|
|
23
22
|
};
|
|
24
23
|
export const CALCULATIONS_CONFIG = {
|
|
25
24
|
First: {
|
|
26
|
-
label: 'First'
|
|
25
|
+
label: 'First',
|
|
26
|
+
description: 'First value'
|
|
27
27
|
},
|
|
28
28
|
Last: {
|
|
29
|
-
label: 'Last'
|
|
29
|
+
label: 'Last',
|
|
30
|
+
description: 'Last value'
|
|
31
|
+
},
|
|
32
|
+
FirstNumber: {
|
|
33
|
+
label: 'First *',
|
|
34
|
+
description: 'First numeric value'
|
|
30
35
|
},
|
|
31
36
|
LastNumber: {
|
|
32
|
-
label: 'Last
|
|
37
|
+
label: 'Last *',
|
|
38
|
+
description: 'Last numeric value'
|
|
33
39
|
},
|
|
34
40
|
Mean: {
|
|
35
|
-
label: '
|
|
41
|
+
label: 'Avg',
|
|
42
|
+
description: 'Average value excluding nulls'
|
|
36
43
|
},
|
|
37
44
|
Sum: {
|
|
38
|
-
label: 'Sum'
|
|
45
|
+
label: 'Sum',
|
|
46
|
+
description: 'The sum of all values'
|
|
47
|
+
},
|
|
48
|
+
Min: {
|
|
49
|
+
label: 'Min',
|
|
50
|
+
description: 'Minimum value'
|
|
51
|
+
},
|
|
52
|
+
Max: {
|
|
53
|
+
label: 'Max',
|
|
54
|
+
description: 'Maximum value'
|
|
39
55
|
}
|
|
40
56
|
};
|
|
41
57
|
export const DEFAULT_CALCULATION = 'Sum';
|
|
58
|
+
/**
|
|
59
|
+
* Calculate a multiple values for a set of time series data.
|
|
60
|
+
*
|
|
61
|
+
* @param values - Array of time series data.
|
|
62
|
+
* @param includeCalculations - Array of calculations to include.
|
|
63
|
+
*/ export function getCalculations(values, includeCalculations) {
|
|
64
|
+
const calculations = includeCalculations.reduce((initResult, calculation)=>{
|
|
65
|
+
initResult[calculation] = undefined;
|
|
66
|
+
return initResult;
|
|
67
|
+
}, {});
|
|
68
|
+
// We save these values as separate values instead of directly setting them
|
|
69
|
+
// in the calculations because they are needed by multiple calculations.
|
|
70
|
+
let nonNullCount = 0;
|
|
71
|
+
let sum = 0;
|
|
72
|
+
// We use this large function capable of performing one or more calculations
|
|
73
|
+
// in a single iteration of the data to minimize the performance impact of
|
|
74
|
+
// generating multiple calculations for large timeseries values. This is
|
|
75
|
+
// less optimized for certain single calculations when done in isolation (e.g.
|
|
76
|
+
// `Last`), but will be more performant in the more expensive cases where
|
|
77
|
+
// multiple values are being used (e.g. table legend).
|
|
78
|
+
values.forEach((tuple, i)=>{
|
|
79
|
+
const value = tuple[1];
|
|
80
|
+
if (i === 0 && 'First' in calculations) {
|
|
81
|
+
calculations.First = value;
|
|
82
|
+
}
|
|
83
|
+
if (i === values.length - 1 && 'Last' in calculations) {
|
|
84
|
+
calculations.Last = value;
|
|
85
|
+
}
|
|
86
|
+
// Handling specific to non-null values.
|
|
87
|
+
if (typeof value === 'number') {
|
|
88
|
+
nonNullCount += 1;
|
|
89
|
+
sum += value;
|
|
90
|
+
if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {
|
|
91
|
+
// Save the first number we see.
|
|
92
|
+
calculations.FirstNumber = value;
|
|
93
|
+
}
|
|
94
|
+
if ('LastNumber' in calculations) {
|
|
95
|
+
// Keep setting the numbers we see, which will eventually be set to the
|
|
96
|
+
// last number when finished iterating.
|
|
97
|
+
calculations.LastNumber = value;
|
|
98
|
+
}
|
|
99
|
+
if ('Min' in calculations) {
|
|
100
|
+
if (typeof calculations.Min !== 'number') {
|
|
101
|
+
// Init the first time we see a number
|
|
102
|
+
calculations.Min = value;
|
|
103
|
+
} else {
|
|
104
|
+
// Use lowest value once initialized
|
|
105
|
+
calculations.Min = Math.min(calculations.Min, value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if ('Max' in calculations) {
|
|
109
|
+
if (typeof calculations.Max !== 'number') {
|
|
110
|
+
// Init the first time we see a number
|
|
111
|
+
calculations.Max = value;
|
|
112
|
+
} else {
|
|
113
|
+
// Use highest value once initialized
|
|
114
|
+
calculations.Max = Math.max(calculations.Max, value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Set calculations that require iterating over all values.
|
|
120
|
+
if (nonNullCount > 0 && 'Sum' in calculations) {
|
|
121
|
+
calculations.Sum = sum;
|
|
122
|
+
}
|
|
123
|
+
if (nonNullCount > 0 && 'Mean' in calculations) {
|
|
124
|
+
calculations.Mean = sum / nonNullCount;
|
|
125
|
+
}
|
|
126
|
+
return calculations;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Calculate a single value for a set of time series data.
|
|
130
|
+
*
|
|
131
|
+
* Use `getCalculations` instead if you need multiple calculations.
|
|
132
|
+
*
|
|
133
|
+
* @param values - Array of time series data.
|
|
134
|
+
* @param calculation - Name of the calculation to calculate.
|
|
135
|
+
*/ export function getCalculation(values, calculation) {
|
|
136
|
+
return getCalculations(values, [
|
|
137
|
+
calculation
|
|
138
|
+
])[calculation];
|
|
139
|
+
}
|
|
42
140
|
function first(values) {
|
|
43
|
-
|
|
44
|
-
return tuple === undefined ? undefined : getValue(tuple);
|
|
141
|
+
return getCalculation(values, 'First');
|
|
45
142
|
}
|
|
46
143
|
function last(values) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
144
|
+
return getCalculation(values, 'Last');
|
|
145
|
+
}
|
|
146
|
+
function firstNumber(values) {
|
|
147
|
+
return getCalculation(values, 'FirstNumber');
|
|
50
148
|
}
|
|
51
149
|
function lastNumber(values) {
|
|
52
|
-
|
|
53
|
-
return tuple === undefined ? undefined : getValue(tuple);
|
|
150
|
+
return getCalculation(values, 'LastNumber');
|
|
54
151
|
}
|
|
55
152
|
function mean(values) {
|
|
56
|
-
|
|
57
|
-
return meanBy(values, getValue);
|
|
153
|
+
return getCalculation(values, 'Mean');
|
|
58
154
|
}
|
|
59
155
|
function sum(values) {
|
|
60
|
-
|
|
61
|
-
return sumBy(values, getValue);
|
|
156
|
+
return getCalculation(values, 'Sum');
|
|
62
157
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// TODO: refactor utils so null can be returned and LastNotNull supported
|
|
69
|
-
return NaN;
|
|
158
|
+
function min(values) {
|
|
159
|
+
return getCalculation(values, 'Min');
|
|
160
|
+
}
|
|
161
|
+
function max(values) {
|
|
162
|
+
return getCalculation(values, 'Max');
|
|
70
163
|
}
|
|
71
164
|
|
|
72
165
|
//# sourceMappingURL=calculations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport findLast from 'lodash/findLast';\nimport meanBy from 'lodash/meanBy';\nimport sumBy from 'lodash/sumBy';\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\n// TODO: move this file and calculations.test.ts to @perses-dev/core\nexport const CalculationsMap = {\n First: first,\n Last: last,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n};\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n },\n Last: {\n label: 'Last',\n },\n LastNumber: {\n label: 'Last number',\n },\n Mean: {\n label: 'Mean',\n },\n Sum: {\n label: 'Sum',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\nfunction first(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = values[0];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction last(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n\n const tuple = values[values.length - 1];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = findLast(values, (tuple) => isNaN(getValue(tuple)) === false);\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return meanBy(values, getValue);\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return sumBy(values, getValue);\n}\n\nfunction getValue(valueTuple: TimeSeriesValueTuple) {\n const value = valueTuple[1];\n if (value !== null) {\n return value;\n }\n // TODO: refactor utils so null can be returned and LastNotNull supported\n return NaN;\n}\n"],"names":["findLast","meanBy","sumBy","CalculationsMap","First","first","Last","last","LastNumber","lastNumber","Mean","mean","Sum","sum","CALCULATIONS_CONFIG","label","DEFAULT_CALCULATION","values","tuple","undefined","getValue","length","isNaN","valueTuple","value","NaN"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAOC,MAAM,MAAM,eAAe,CAAC;AACnC,OAAOC,KAAK,MAAM,cAAc,CAAC;AAGjC,oEAAoE;AACpE,OAAO,MAAMC,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,UAAU,EAAEC,UAAU;IACtBC,IAAI,E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F,SAAS,CAAC;IACzC,OAAOlB,MAAM,CAACgB,MAAM,EAAEG,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,SAASP,GAAG,CAACI,MAA8B,EAAsB;IAC/D,IAAIA,MAAM,CAACI,MAAM,IAAI,CAAC,EAAE,OAAOF,SAAS,CAAC;IACzC,OAAOjB,KAAK,CAACe,MAAM,EAAEG,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,SAASA,QAAQ,CAACG,UAAgC,EAAE;IAClD,MAAMC,KAAK,GAAGD,UAAU,CAAC,CAAC,CAAC,AAAC;IAC5B,IAAIC,KAAK,KAAK,IAAI,EAAE;QAClB,OAAOA,KAAK,CAAC;IACf,CAAC;IACD,yEAAyE;IACzE,OAAOC,GAAG,CAAC;AACb,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","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B,EAAoB;IAC9D,OAAOc,cAAc,CAACd,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAAShB,WAAW,CAACgB,MAA8B,EAAoB;IACrE,OAAOc,cAAc,CAACd,MAAM,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC;AAED,SAASd,UAAU,CAACc,MAA8B,EAAoB;IACpE,OAAOc,cAAc,CAACd,MAAM,EAAE,YAAY,CAAC,CAAC;AAC9C,CAAC;AAED,SAASZ,IAAI,CAACY,MAA8B,EAAoB;IAC9D,OAAOc,cAAc,CAACd,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAASV,GAAG,CAACU,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASR,GAAG,CAACQ,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASN,GAAG,CAACM,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -14,6 +14,7 @@ export interface DashboardSpec {
|
|
|
14
14
|
display?: Display;
|
|
15
15
|
datasources?: Record<string, DatasourceSpec>;
|
|
16
16
|
duration: DurationString;
|
|
17
|
+
refreshInterval: DurationString;
|
|
17
18
|
variables: VariableDefinition[];
|
|
18
19
|
layouts: LayoutDefinition[];
|
|
19
20
|
panels: Record<string, PanelDefinition>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../../src/model/dashboard.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAA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IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,QAAQ,EAAE,cAAc,CAAC;IACzB,eAAe,EAAE,cAAc,CAAC;IAChC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n\nexport interface DashboardSelector {\n project: string;\n dashboard: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n refreshInterval: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n\nexport interface DashboardSelector {\n project: string;\n dashboard: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA2BC"}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/dist/model/legend.d.ts
CHANGED
|
@@ -2,13 +2,18 @@ export declare const legendPositions: readonly ["Bottom", "Right"];
|
|
|
2
2
|
export declare type LegendPositions = (typeof legendPositions)[number];
|
|
3
3
|
export declare const legendModes: readonly ["List", "Table"];
|
|
4
4
|
export declare type LegendMode = (typeof legendModes)[number];
|
|
5
|
+
export declare const legendSizes: readonly ["Small", "Medium"];
|
|
6
|
+
export declare type LegendSize = (typeof legendSizes)[number];
|
|
5
7
|
export interface LegendOptionsBase {
|
|
6
8
|
position: LegendPositions;
|
|
7
9
|
mode?: LegendMode;
|
|
10
|
+
size?: LegendSize;
|
|
8
11
|
}
|
|
9
12
|
export declare function isValidLegendPosition(position: LegendPositions): boolean;
|
|
10
13
|
export declare function isValidLegendMode(mode: LegendMode): boolean;
|
|
14
|
+
export declare function isValidLegendSize(size: LegendSize): boolean;
|
|
11
15
|
export declare const DEFAULT_LEGEND: Required<LegendOptionsBase>;
|
|
12
16
|
export declare function getLegendPosition(position?: LegendPositions): "Bottom" | "Right";
|
|
13
17
|
export declare function getLegendMode(mode?: LegendMode): "List" | "Table";
|
|
18
|
+
export declare function getLegendSize(size?: LegendSize): "Small" | "Medium";
|
|
14
19
|
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAC5D,oBAAY,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAGtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAC5D,oBAAY,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,eAAO,MAAM,WAAW,8BAA+B,CAAC;AACxD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAGtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,iBAAiB,CAItD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,sBAQ3D;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,oBAM9C;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,sBAM9C"}
|
package/dist/model/legend.js
CHANGED
|
@@ -22,15 +22,23 @@ export const legendModes = [
|
|
|
22
22
|
'List',
|
|
23
23
|
'Table'
|
|
24
24
|
];
|
|
25
|
+
export const legendSizes = [
|
|
26
|
+
'Small',
|
|
27
|
+
'Medium'
|
|
28
|
+
];
|
|
25
29
|
export function isValidLegendPosition(position) {
|
|
26
30
|
return legendPositions.includes(position);
|
|
27
31
|
}
|
|
28
32
|
export function isValidLegendMode(mode) {
|
|
29
33
|
return legendModes.includes(mode);
|
|
30
34
|
}
|
|
35
|
+
export function isValidLegendSize(size) {
|
|
36
|
+
return legendSizes.includes(size);
|
|
37
|
+
}
|
|
31
38
|
export const DEFAULT_LEGEND = {
|
|
32
39
|
position: 'Bottom',
|
|
33
|
-
mode: 'List'
|
|
40
|
+
mode: 'List',
|
|
41
|
+
size: 'Medium'
|
|
34
42
|
};
|
|
35
43
|
export function getLegendPosition(position) {
|
|
36
44
|
if (position === undefined) {
|
|
@@ -47,5 +55,11 @@ export function getLegendMode(mode) {
|
|
|
47
55
|
}
|
|
48
56
|
return mode;
|
|
49
57
|
}
|
|
58
|
+
export function getLegendSize(size) {
|
|
59
|
+
if (!size || !isValidLegendSize(size)) {
|
|
60
|
+
return DEFAULT_LEGEND.size;
|
|
61
|
+
}
|
|
62
|
+
return size;
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
//# sourceMappingURL=legend.js.map
|
package/dist/model/legend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['List', 'Table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\n// Common legend options used across some UI components and panel specifications\nexport interface LegendOptionsBase {\n position: LegendPositions;\n mode?: LegendMode;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport const DEFAULT_LEGEND: Required<LegendOptionsBase> = {\n position: 'Bottom',\n mode: 'List',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n"],"names":["legendPositions","legendModes","isValidLegendPosition","position","includes","isValidLegendMode","mode","DEFAULT_LEGEND","getLegendPosition","undefined","getLegendMode"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sDAAsD;AACtD,4EAA4E;AAC5E,+EAA+E;AAC/E,sBAAsB;AAEtB,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAG5D,OAAO,MAAMC,WAAW,GAAG;IAAC,MAAM;IAAE,OAAO;CAAC,AAAS,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['List', 'Table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\nexport const legendSizes = ['Small', 'Medium'] as const;\nexport type LegendSize = (typeof legendSizes)[number];\n\n// Common legend options used across some UI components and panel specifications\nexport interface LegendOptionsBase {\n position: LegendPositions;\n mode?: LegendMode;\n size?: LegendSize;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport function isValidLegendSize(size: LegendSize) {\n return (legendSizes as readonly string[]).includes(size);\n}\n\nexport const DEFAULT_LEGEND: Required<LegendOptionsBase> = {\n position: 'Bottom',\n mode: 'List',\n size: 'Medium',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n\nexport function getLegendSize(size?: LegendSize) {\n if (!size || !isValidLegendSize(size)) {\n return DEFAULT_LEGEND.size;\n }\n\n return size;\n}\n"],"names":["legendPositions","legendModes","legendSizes","isValidLegendPosition","position","includes","isValidLegendMode","mode","isValidLegendSize","size","DEFAULT_LEGEND","getLegendPosition","undefined","getLegendMode","getLegendSize"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sDAAsD;AACtD,4EAA4E;AAC5E,+EAA+E;AAC/E,sBAAsB;AAEtB,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAG5D,OAAO,MAAMC,WAAW,GAAG;IAAC,MAAM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,OAAOA,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thresholds.d.ts","sourceRoot":"","sources":["../../src/model/thresholds.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"thresholds.d.ts","sourceRoot":"","sources":["../../src/model/thresholds.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/thresholds.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface StepOptions {\n value: number;\n color?: string;\n name?: string;\n}\n\nexport interface ThresholdOptions {\n mode?: 'Percent' | 'Absolute';\n default_color?: string;\n max?: number; // is this same as the max in GaugeChartOptions? can we remove?\n steps?: StepOptions[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"sources":["../../src/model/thresholds.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface StepOptions {\n value: number;\n color?: string;\n name?: string;\n}\n\nexport interface ThresholdOptions {\n mode?: 'Percent' | 'Absolute';\n default_color?: string;\n max?: number; // is this same as the max in GaugeChartOptions? can we remove?\n steps?: StepOptions[];\n}\n\nexport interface ThresholdColorPalette {\n defaultColor: string;\n palette: string[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAgBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
declare const bytesUnitKinds: readonly ["Bytes"];
|
|
3
|
+
declare type BytesUnitKind = (typeof bytesUnitKinds)[number];
|
|
4
|
+
export declare type BytesUnitOptions = {
|
|
5
|
+
kind: BytesUnitKind;
|
|
6
|
+
decimal_places?: number;
|
|
7
|
+
abbreviate?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
10
|
+
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
|
|
11
|
+
export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAOzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,UAmCnE"}
|