1 | import { a as __extends, _ as __assign } from './tslib.es6-f952ba6f.js';
|
2 | import { U as Utils } from './Utils-38a0872e.js';
|
3 | import 'd3';
|
4 | import 'moment-timezone';
|
5 | import { C as ChartDataOptions } from './ChartDataOptions-a8fe7914.js';
|
6 |
|
7 | var TsqExpression = (function (_super) {
|
8 | __extends(TsqExpression, _super);
|
9 | function TsqExpression(instanceObject, variableObject, searchSpan, colorOrOptionsObject, alias, contextMenu) {
|
10 | var _this = this;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var optionsObject = (typeof (colorOrOptionsObject) === 'object' && !!colorOrOptionsObject)
|
20 | ? __assign(__assign({}, colorOrOptionsObject), { searchSpan: searchSpan, measureTypes: Object.keys(variableObject) }) : {
|
21 | color: colorOrOptionsObject,
|
22 | searchSpan: searchSpan,
|
23 | measureTypes: Object.keys(variableObject),
|
24 | alias: alias,
|
25 | contextMenu: contextMenu
|
26 | };
|
27 | _this = _super.call(this, optionsObject) || this;
|
28 | _this.instanceObject = instanceObject;
|
29 | _this.variableObject = variableObject;
|
30 | return _this;
|
31 | }
|
32 | TsqExpression.prototype.toTsq = function (roundFromTo, getEvents, getSeries) {
|
33 | if (roundFromTo === void 0) { roundFromTo = false; }
|
34 | if (getEvents === void 0) { getEvents = false; }
|
35 | if (getSeries === void 0) { getSeries = false; }
|
36 | var tsq = {};
|
37 | var shiftMillis = Utils.parseShift(this.timeShift, this.startAt, this.searchSpan);
|
38 | var fromMillis = this.searchSpan.from.valueOf() + shiftMillis;
|
39 | var toMillis = this.searchSpan.to.valueOf() + shiftMillis;
|
40 | if (roundFromTo) {
|
41 | var bucketSizeInMillis = Utils.parseTimeInput(this.searchSpan.bucketSize);
|
42 | var roundedFromMillis = Math.floor((fromMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
|
43 | var roundedToMillis = Math.ceil((toMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
|
44 | fromMillis = roundedFromMillis;
|
45 | toMillis = roundedToMillis;
|
46 | }
|
47 | tsq['searchSpan'] = { from: (new Date(fromMillis)).toISOString(), to: (new Date(toMillis)).toISOString() };
|
48 | tsq['timeSeriesId'] = this.instanceObject.timeSeriesId;
|
49 | if (getEvents) {
|
50 | return { getEvents: tsq };
|
51 | }
|
52 | else if (getSeries) {
|
53 | tsq['inlineVariables'] = __assign({}, this.variableObject);
|
54 | tsq['projectedVariables'] = Object.keys(this.variableObject);
|
55 | return { getSeries: tsq };
|
56 | }
|
57 | else {
|
58 | tsq['interval'] = Utils.bucketSizeToTsqInterval(this.searchSpan.bucketSize);
|
59 | tsq['inlineVariables'] = __assign({}, this.variableObject);
|
60 | tsq['projectedVariables'] = Object.keys(this.variableObject);
|
61 | return { aggregateSeries: tsq };
|
62 | }
|
63 | };
|
64 |
|
65 |
|
66 | TsqExpression.prototype.toStatsTsq = function (fromMillis, toMillis) {
|
67 | var tsq = this.toTsq();
|
68 | var shiftMillis = Utils.parseShift(this.timeShift);
|
69 | fromMillis += shiftMillis;
|
70 | toMillis += shiftMillis;
|
71 | tsq.aggregateSeries['searchSpan'] = { from: (new Date(fromMillis)).toISOString(), to: (new Date(toMillis)).toISOString() };
|
72 | tsq.aggregateSeries['interval'] = 'P1000Y';
|
73 | if (this.dataType === 'numeric') {
|
74 | var inlineVariables_1 = { min: {}, max: {}, avg: {}, stDev: {} };
|
75 | var firstVariable_1 = tsq.aggregateSeries['inlineVariables'][Object.keys(tsq.aggregateSeries['inlineVariables'])[0]];
|
76 | Object.keys(inlineVariables_1).forEach(function (k) {
|
77 | inlineVariables_1[k] = JSON.parse(JSON.stringify(firstVariable_1));
|
78 | inlineVariables_1[k].aggregation.tsx = k + "($value)";
|
79 | delete inlineVariables_1[k]['interpolation'];
|
80 | });
|
81 | tsq.aggregateSeries['inlineVariables'] = inlineVariables_1;
|
82 | tsq.aggregateSeries['projectedVariables'] = Object.keys(inlineVariables_1);
|
83 | }
|
84 | return tsq;
|
85 | };
|
86 | return TsqExpression;
|
87 | }(ChartDataOptions));
|
88 |
|
89 | export default TsqExpression;
|