| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 |
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
51×
1×
45×
1×
1×
46×
1×
46×
1×
3×
1×
55×
1×
3×
1×
5×
1×
39×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
16×
16×
16×
1×
1×
1×
1×
1×
16×
1×
30×
30×
30×
1×
1×
30×
1×
1×
1×
1×
| "use strict";
var immutable_1 = require('immutable');
var immutable_class_1 = require('immutable-class');
var chronoshift_1 = require('chronoshift');
var plywood_1 = require('plywood');
var general_1 = require('../../utils/general/general');
var split_combine_1 = require('../split-combine/split-combine');
var DEFAULT_GRANULARITY = chronoshift_1.Duration.fromJS('P1D');
function getBestGranularity(timeRange) {
var len = timeRange.end.valueOf() - timeRange.start.valueOf();
Iif (len > 95 * chronoshift_1.day.canonicalLength) {
return chronoshift_1.Duration.fromJS('P1W');
}
else Iif (len > 8 * chronoshift_1.day.canonicalLength) {
return chronoshift_1.Duration.fromJS('P1D');
}
else Eif (len > 8 * chronoshift_1.hour.canonicalLength) {
return chronoshift_1.Duration.fromJS('PT1H');
}
else if (len > 3 * chronoshift_1.hour.canonicalLength) {
return chronoshift_1.Duration.fromJS('PT5M');
}
else {
return chronoshift_1.Duration.fromJS('PT1M');
}
}
function withholdSplit(splits, split, allowIndex) {
return splits.filter(function (s, i) {
return i === allowIndex || !s.equalsByExpression(split);
});
}
function swapSplit(splits, split, other, allowIndex) {
return splits.map(function (s, i) {
return (i === allowIndex || !s.equalsByExpression(split)) ? s : other;
});
}
var check;
var Splits = (function () {
function Splits(parameters) {
this.splitCombines = parameters;
}
Splits.isSplits = function (candidate) {
return immutable_class_1.isInstanceOf(candidate, Splits);
};
Splits.fromSplitCombine = function (splitCombine) {
return new Splits(immutable_1.List([splitCombine]));
};
Splits.fromJS = function (parameters, context) {
if (typeof parameters === 'string')
parameters = [parameters];
return new Splits(immutable_1.List(parameters.map(function (splitCombine) { return split_combine_1.SplitCombine.fromJS(splitCombine, context); })));
};
Splits.prototype.valueOf = function () {
return this.splitCombines;
};
Splits.prototype.toJS = function () {
return this.splitCombines.toArray().map(function (splitCombine) { return splitCombine.toJS(); });
};
Splits.prototype.toJSON = function () {
return this.toJS();
};
Splits.prototype.toString = function () {
return this.splitCombines.map(function (splitCombine) { return splitCombine.toString(); }).join(',');
};
Splits.prototype.equals = function (other) {
return Splits.isSplits(other) &&
general_1.listsEqual(this.splitCombines, other.splitCombines);
};
Splits.prototype.replaceByIndex = function (index, replace) {
var splitCombines = this.splitCombines;
if (splitCombines.size === index)
return this.insertByIndex(index, replace);
var replacedSplit = splitCombines.get(index);
splitCombines = splitCombines.map(function (s, i) { return i === index ? replace : s; });
splitCombines = swapSplit(splitCombines, replace, replacedSplit, index);
return new Splits(splitCombines);
};
Splits.prototype.insertByIndex = function (index, insert) {
var splitCombines = this.splitCombines;
splitCombines = splitCombines.splice(index, 0, insert);
splitCombines = withholdSplit(splitCombines, insert, index);
return new Splits(splitCombines);
};
Splits.prototype.addSplit = function (split) {
var splitCombines = this.splitCombines;
return this.insertByIndex(splitCombines.size, split);
};
Splits.prototype.removeSplit = function (split) {
return new Splits(this.splitCombines.filter(function (s) { return s !== split; }));
};
Splits.prototype.changeSortAction = function (sort) {
return new Splits(this.splitCombines.map(function (s) { return s.changeSortAction(sort); }));
};
Splits.prototype.getTitle = function (dimensions) {
return this.splitCombines.map(function (s) { return s.getDimension(dimensions).title; }).join(', ');
};
Splits.prototype.length = function () {
return this.splitCombines.size;
};
Splits.prototype.forEach = function (sideEffect, context) {
return this.splitCombines.forEach(sideEffect, context);
};
Splits.prototype.get = function (index) {
return this.splitCombines.get(index);
};
Splits.prototype.first = function () {
return this.splitCombines.first();
};
Splits.prototype.last = function () {
return this.splitCombines.last();
};
Splits.prototype.findSplitForDimension = function (dimension) {
var dimensionExpression = dimension.expression;
return this.splitCombines.find(function (s) { return s.expression.equals(dimensionExpression); });
};
Splits.prototype.hasSplitOn = function (dimension) {
return Boolean(this.findSplitForDimension(dimension));
};
Splits.prototype.replace = function (search, replace) {
return new Splits(this.splitCombines.map(function (s) { return s.equals(search) ? replace : s; }));
};
Splits.prototype.map = function (mapper, context) {
return new Splits(this.splitCombines.map(mapper, context));
};
Splits.prototype.toArray = function () {
return this.splitCombines.toArray();
};
Splits.prototype.updateWithTimeRange = function (timeAttribute, timeRange, timezone, force) {
var changed = false;
var granularity = timeRange ? getBestGranularity(timeRange) : DEFAULT_GRANULARITY;
var newSplitCombines = this.splitCombines.map(function (splitCombine) {
Iif (!splitCombine.expression.equals(timeAttribute))
return splitCombine;
var bucketAction = splitCombine.bucketAction;
Iif (bucketAction) {
if (!force)
return splitCombine;
if (bucketAction instanceof plywood_1.TimeBucketAction && !bucketAction.duration.equals(granularity)) {
changed = true;
return splitCombine.changeBucketAction(new plywood_1.TimeBucketAction({
timezone: bucketAction.timezone,
duration: granularity
}));
}
else {
return splitCombine;
}
}
else {
changed = true;
return splitCombine.changeBucketAction(new plywood_1.TimeBucketAction({
timezone: timezone,
duration: granularity
}));
}
});
return changed ? new Splits(newSplitCombines) : this;
};
Splits.prototype.constrainToDimensions = function (dimensions) {
var hasChanged = false;
var splitCombines = [];
this.splitCombines.forEach(function (split) {
Eif (split.getDimension(dimensions)) {
splitCombines.push(split);
}
else {
hasChanged = true;
}
});
return hasChanged ? new Splits(immutable_1.List(splitCombines)) : this;
};
return Splits;
}());
exports.Splits = Splits;
check = Splits;
Splits.EMPTY = new Splits(immutable_1.List());
|