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 MAXCARD = 150000;
|
8 | var AggregateExpression = (function (_super) {
|
9 | __extends(AggregateExpression, _super);
|
10 | function AggregateExpression(predicateObject, measureObject, measureTypes, searchSpan, splitByObject, colorOrOptionsObject, alias, contextMenu) {
|
11 | if (splitByObject === void 0) { splitByObject = null; }
|
12 | var _this = _super.call(this, (typeof (colorOrOptionsObject) === 'object' && !!colorOrOptionsObject) ? __assign(__assign({}, colorOrOptionsObject), { searchSpan: searchSpan, measureTypes: measureTypes }) : { color: colorOrOptionsObject, searchSpan: searchSpan, measureTypes: measureTypes, alias: alias, contextMenu: contextMenu }) || this;
|
13 | _this.visibleSplitByCap = 10;
|
14 | _this.predicate = predicateObject;
|
15 | _this.splitByObject = splitByObject;
|
16 | _this.measureObject = ((measureTypes.length == 1 && measureTypes[0] == 'count') || measureObject.property == 'Events Count') ? { count: {} } : { input: measureObject };
|
17 | return _this;
|
18 | }
|
19 | AggregateExpression.prototype.toTsx = function (roundFromTo) {
|
20 | var _this = this;
|
21 | if (roundFromTo === void 0) { roundFromTo = false; }
|
22 | var tsx = {};
|
23 | var shiftMillis = Utils.parseShift(this.timeShift, this.startAt, this.searchSpan);
|
24 | var fromMillis = this.searchSpan.from.valueOf() + shiftMillis;
|
25 | var toMillis = this.searchSpan.to.valueOf() + shiftMillis;
|
26 | var bucketSizeInMillis = Utils.parseTimeInput(this.searchSpan.bucketSize);
|
27 | var roundedFromMillis = Math.floor((fromMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
|
28 | var roundedToMillis = Math.ceil((toMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
|
29 | if (roundFromTo) {
|
30 | fromMillis = roundedFromMillis;
|
31 | toMillis = roundedToMillis;
|
32 | }
|
33 | tsx['searchSpan'] = { from: (new Date(fromMillis)).toISOString(), to: (new Date(toMillis)).toISOString() };
|
34 |
|
35 | var measures = (this.measureObject.hasOwnProperty('count')) ? [{ count: {} }]
|
36 | : this.measureTypes.reduce(function (p, c) {
|
37 | var measureObject = {};
|
38 | if (c == 'count')
|
39 | measureObject = { count: {} };
|
40 | else
|
41 | measureObject[c] = _this['measureObject'];
|
42 | p.push(measureObject);
|
43 | return p;
|
44 | }, []);
|
45 | var aggregateObject = {};
|
46 | var dimensionObject = { dateHistogram: { input: { builtInProperty: "$ts" }, breaks: { size: this.searchSpan.bucketSize } } };
|
47 | if (this.splitByObject != null) {
|
48 | var bucketsCeil = Math.ceil((roundedToMillis - roundedFromMillis) / bucketSizeInMillis);
|
49 | aggregateObject['dimension'] = { uniqueValues: { input: this.splitByObject, take: Math.floor(MAXCARD / bucketsCeil) } };
|
50 | aggregateObject['aggregate'] = { dimension: dimensionObject, measures: measures };
|
51 | }
|
52 | else {
|
53 | aggregateObject['dimension'] = dimensionObject;
|
54 | aggregateObject['measures'] = measures;
|
55 | }
|
56 | var aggregates = [aggregateObject];
|
57 | tsx['aggregates'] = aggregates;
|
58 |
|
59 | var predicate;
|
60 | if (!this.measureObject.hasOwnProperty('count'))
|
61 | predicate = { and: [this.predicate, { not: { eq: { left: this.measureObject.input, right: { 'double': null } } } }] };
|
62 | else
|
63 | predicate = this.predicate;
|
64 | tsx['predicate'] = predicate;
|
65 | return tsx;
|
66 | };
|
67 | return AggregateExpression;
|
68 | }(ChartDataOptions));
|
69 |
|
70 | export default AggregateExpression;
|