@powerhousedao/analytics-engine-core 0.6.1 → 0.6.3

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.
Files changed (42) hide show
  1. package/dist/src/index.js +5553 -7
  2. package/package.json +9 -4
  3. package/dist/src/AnalyticsDiscretizer.js +0 -237
  4. package/dist/src/AnalyticsDiscretizer.js.map +0 -1
  5. package/dist/src/AnalyticsPath.js +0 -166
  6. package/dist/src/AnalyticsPath.js.map +0 -1
  7. package/dist/src/AnalyticsPeriod.js +0 -214
  8. package/dist/src/AnalyticsPeriod.js.map +0 -1
  9. package/dist/src/AnalyticsProfiler.js +0 -76
  10. package/dist/src/AnalyticsProfiler.js.map +0 -1
  11. package/dist/src/AnalyticsQuery.js +0 -30
  12. package/dist/src/AnalyticsQuery.js.map +0 -1
  13. package/dist/src/AnalyticsQueryEngine.js +0 -173
  14. package/dist/src/AnalyticsQueryEngine.js.map +0 -1
  15. package/dist/src/AnalyticsQueryResult.js +0 -3
  16. package/dist/src/AnalyticsQueryResult.js.map +0 -1
  17. package/dist/src/AnalyticsSubscriptionManager.js +0 -162
  18. package/dist/src/AnalyticsSubscriptionManager.js.map +0 -1
  19. package/dist/src/AnalyticsTimeSlicer.js +0 -212
  20. package/dist/src/AnalyticsTimeSlicer.js.map +0 -1
  21. package/dist/src/IAnalyticsCache.js +0 -2
  22. package/dist/src/IAnalyticsCache.js.map +0 -1
  23. package/dist/src/IAnalyticsStore.js +0 -3
  24. package/dist/src/IAnalyticsStore.js.map +0 -1
  25. package/dist/src/index.js.map +0 -1
  26. package/dist/test/AnalyticsTimeSlicer.spec.d.ts +0 -2
  27. package/dist/test/AnalyticsTimeSlicer.spec.d.ts.map +0 -1
  28. package/dist/test/AnalyticsTimeSlicer.spec.js +0 -448
  29. package/dist/test/AnalyticsTimeSlicer.spec.js.map +0 -1
  30. package/dist/test/Subscriptions.test.d.ts +0 -2
  31. package/dist/test/Subscriptions.test.d.ts.map +0 -1
  32. package/dist/test/Subscriptions.test.js +0 -151
  33. package/dist/test/Subscriptions.test.js.map +0 -1
  34. package/dist/test/vitest.setup.d.ts +0 -2
  35. package/dist/test/vitest.setup.d.ts.map +0 -1
  36. package/dist/test/vitest.setup.js +0 -2
  37. package/dist/test/vitest.setup.js.map +0 -1
  38. package/dist/tsconfig.tsbuildinfo +0 -1
  39. package/dist/vitest.config.d.ts +0 -3
  40. package/dist/vitest.config.d.ts.map +0 -1
  41. package/dist/vitest.config.js +0 -11
  42. package/dist/vitest.config.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/analytics-engine-core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,11 +9,15 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "exports": "./dist/src/index.js",
13
- "types": "dist/src/index.d.ts",
14
12
  "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/src/index.d.ts",
16
+ "default": "./dist/src/index.js"
17
+ }
18
+ },
15
19
  "files": [
16
- "dist"
20
+ "dist/src"
17
21
  ],
18
22
  "dependencies": {
19
23
  "date-fns": "4.1.0",
@@ -25,6 +29,7 @@
25
29
  },
26
30
  "scripts": {
27
31
  "dev": "pnpm tsc -b -w",
32
+ "bundle": "bun run ./bundle.ts",
28
33
  "test": "vitest --run ./**/*.test.ts"
29
34
  }
30
35
  }
@@ -1,237 +0,0 @@
1
- import { AnalyticsGranularity, } from "./AnalyticsQuery.js";
2
- import { getPeriodSeriesArray, } from "./AnalyticsTimeSlicer.js";
3
- import { DateTime, Interval } from "luxon";
4
- export const getQuarter = (date) => {
5
- return Math.floor((date.month - 1) / 3) + 1;
6
- };
7
- export class AnalyticsDiscretizer {
8
- static discretize(series, dimensions, start, end, granularity) {
9
- const index = this._buildIndex(series, dimensions);
10
- const periods = getPeriodSeriesArray(this._calculateRange(start, end, granularity, series));
11
- const disretizedResults = this._discretizeNode(index, {}, dimensions, periods);
12
- const groupedResults = this._groupResultsByPeriod(periods, disretizedResults);
13
- return groupedResults;
14
- }
15
- static _calculateRange(start, end, granularity, results) {
16
- let calculatedStart = start || null;
17
- let calculatedEnd = end || null;
18
- if (calculatedStart == null || calculatedEnd == null) {
19
- for (const r of results) {
20
- if (calculatedStart == null) {
21
- calculatedStart = r.start;
22
- }
23
- const endValue = r.end || r.start;
24
- if (calculatedEnd == null || calculatedEnd < endValue) {
25
- calculatedEnd = endValue;
26
- }
27
- }
28
- }
29
- if (calculatedStart == null || calculatedEnd == null) {
30
- throw new Error("Cannot determine query start and/or end.");
31
- }
32
- return {
33
- start: calculatedStart,
34
- end: calculatedEnd,
35
- granularity,
36
- };
37
- }
38
- static _groupResultsByPeriod(periods, dimensionedResults) {
39
- const result = {};
40
- for (const p of periods) {
41
- const id = p.start.toISO() + "-" + p.period;
42
- const period = AnalyticsDiscretizer._getPeriodString(p);
43
- result[id] = {
44
- period: period,
45
- start: p.start,
46
- end: p.end,
47
- rows: [],
48
- };
49
- }
50
- for (const r of dimensionedResults) {
51
- for (const period of Object.keys(r.series)) {
52
- result[period].rows.push({
53
- dimensions: r.dimensions,
54
- metric: r.metric,
55
- unit: r.unit == "__NULL__" ? null : r.unit,
56
- value: r.series[period].inc,
57
- sum: r.series[period].sum,
58
- });
59
- }
60
- }
61
- return Object.values(result);
62
- }
63
- static _getPeriodString(p) {
64
- switch (p.period) {
65
- case "annual":
66
- return p.start.year.toString();
67
- case "semiAnnual":
68
- return `${p.start.year}/${p.start.month < 7 ? "H1" : "H2"}`;
69
- case "quarterly":
70
- return `${p.start.year}/Q${getQuarter(p.start)}`;
71
- case "monthly":
72
- const month = p.start.toUTC().month;
73
- const formattedMonth = month < 10 ? `0${month}` : `${month}`;
74
- return `${p.start.year}/${formattedMonth}`;
75
- case "weekly":
76
- return `${p.start.weekYear}/W${p.start.weekNumber}`;
77
- case "daily":
78
- const monthD = p.start.month;
79
- const day = p.start.day;
80
- const formattedMonthD = monthD < 10 ? `0${monthD}` : `${monthD}`;
81
- const formattedDay = day < 10 ? `0${day}` : `${day}`;
82
- return `${p.start.year}/${formattedMonthD}/${formattedDay}`;
83
- case "hourly":
84
- const monthH = p.start.month;
85
- const dayH = p.start.day;
86
- const hourH = p.start.hour;
87
- const formattedMonthH = monthH < 10 ? `0${monthH}` : `${monthH}`;
88
- const formattedDayH = dayH < 10 ? `0${dayH}` : `${dayH}`;
89
- const formattedHourH = hourH < 10 ? `0${hourH}` : `${hourH}`;
90
- return `${p.start.year}/${formattedMonthH}/${formattedDayH}/${formattedHourH}`;
91
- default:
92
- return p.period;
93
- }
94
- }
95
- static _discretizeNode(node, dimensionValues, remainingDimensions, periods) {
96
- const result = [];
97
- if (remainingDimensions.length > 0) {
98
- const subdimension = remainingDimensions[0];
99
- Object.keys(node).forEach((subdimensionValue, index, arr) => {
100
- const newDimensionValues = { ...dimensionValues };
101
- newDimensionValues[subdimension] = subdimensionValue;
102
- result.push(...this._discretizeNode(node[subdimensionValue], newDimensionValues, remainingDimensions.slice(1), periods));
103
- });
104
- }
105
- else {
106
- Object.keys(node).forEach((metric) => {
107
- result.push(...this._discretizeLeaf(node[metric], periods, metric, dimensionValues));
108
- });
109
- }
110
- return result;
111
- }
112
- static _discretizeLeaf(leaf, periods, metric, dimensionValues) {
113
- const result = [];
114
- Object.keys(leaf).forEach((unit) => {
115
- const metaDimensions = {};
116
- Object.keys(dimensionValues).forEach((k) => {
117
- metaDimensions[k] = {
118
- path: leaf[unit][0].dimensions[k],
119
- icon: leaf[unit][0].dimensions.icon,
120
- label: leaf[unit][0].dimensions.label,
121
- description: leaf[unit][0].dimensions.description,
122
- };
123
- });
124
- result.push({
125
- unit,
126
- metric,
127
- dimensions: metaDimensions,
128
- series: this._discretizeSeries(leaf[unit], periods),
129
- });
130
- });
131
- return result;
132
- }
133
- static _discretizeSeries(series, periods) {
134
- const result = {};
135
- for (const s of series) {
136
- let oldSum = this._getValue(s, periods[0].start);
137
- for (const p of periods) {
138
- const newSum = this._getValue(s, p.end);
139
- const id = `${p.start.toISO()}-${p.period}`;
140
- // const id = p.period;
141
- if (result[id]) {
142
- result[id].inc += newSum - oldSum;
143
- result[id].sum += newSum;
144
- }
145
- else {
146
- result[id] = {
147
- inc: newSum - oldSum,
148
- sum: newSum,
149
- };
150
- }
151
- oldSum = newSum;
152
- }
153
- }
154
- return result;
155
- }
156
- static _getValue(series, when) {
157
- switch (series.fn) {
158
- case "Single":
159
- return this._getSingleValue(series, when);
160
- case "DssVest":
161
- return this._getVestValue(series, when);
162
- default:
163
- // todo: logging interface
164
- //console.error(`Unknown analytics series function: '${series.fn}'`);
165
- return 0.0;
166
- }
167
- }
168
- static _getSingleValue(series, when) {
169
- return when >= series.start ? series.value : 0.0;
170
- }
171
- static _getVestValue(series, when) {
172
- const now = when;
173
- const start = series.start;
174
- const end = series.end;
175
- const cliff = series.params?.cliff
176
- ? DateTime.fromISO(series.params.cliff)
177
- : null;
178
- if (now < start || (cliff && now < cliff)) {
179
- return 0.0;
180
- }
181
- else if (end && now >= end) {
182
- return series.value;
183
- }
184
- const a = Interval.fromDateTimes(start, now);
185
- const b = Interval.fromDateTimes(start, end || now);
186
- return (a.length() / b.length()) * series.value;
187
- }
188
- static _buildIndex(series, dimensions) {
189
- const result = {};
190
- const map = {};
191
- const dimName = dimensions[0] || "";
192
- for (const s of series) {
193
- const dimValue = s.dimensions[dimName];
194
- if (undefined === map[dimValue]) {
195
- map[dimValue] = [];
196
- }
197
- map[dimValue].push(s);
198
- }
199
- if (dimensions.length > 1) {
200
- const newDimensions = dimensions.slice(1);
201
- Object.keys(map).forEach((k) => {
202
- result[k] = this._buildIndex(map[k], newDimensions);
203
- });
204
- }
205
- else {
206
- Object.keys(map).forEach((k) => {
207
- result[k] = this._buildMetricsIndex(map[k]);
208
- });
209
- }
210
- return result;
211
- }
212
- static _buildMetricsIndex(series) {
213
- const result = {};
214
- const map = {};
215
- for (const s of series) {
216
- const metric = s.metric;
217
- if (undefined === map[metric]) {
218
- map[metric] = [];
219
- }
220
- map[metric].push(s);
221
- }
222
- Object.keys(map).forEach((k) => (result[k] = this._buildUnitIndex(map[k])));
223
- return result;
224
- }
225
- static _buildUnitIndex(series) {
226
- const result = {};
227
- for (const s of series) {
228
- const unit = s.unit || "__NULL__";
229
- if (undefined === result[unit]) {
230
- result[unit] = [];
231
- }
232
- result[unit].push(s);
233
- }
234
- return result;
235
- }
236
- }
237
- //# sourceMappingURL=AnalyticsDiscretizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnalyticsDiscretizer.js","sourceRoot":"","sources":["../../src/AnalyticsDiscretizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,GAErB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,EAAE;IAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC,CAAC;AAqBF,MAAM,OAAO,oBAAoB;IACxB,MAAM,CAAC,UAAU,CACtB,MAAiC,EACjC,UAAoB,EACpB,KAAsB,EACtB,GAAoB,EACpB,WAAiC;QAEjC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,oBAAoB,CAClC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,CACtD,CAAC;QACF,MAAM,iBAAiB,GAAG,IAAI,CAAC,eAAe,CAC5C,KAAK,EACL,EAAE,EACF,UAAU,EACV,OAAO,CACR,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,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;YAED,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,eAAe,CAC3B,MAAiC;QAEjC,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,UAAU,CAAC;YAClC,IAAI,SAAS,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACpB,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -1,166 +0,0 @@
1
- import { AnalyticsSerializerTypes } from "./AnalyticsPeriod.js";
2
- export class AnalyticsPath {
3
- get segments() {
4
- return this._segments;
5
- }
6
- _segments;
7
- static fromString(path) {
8
- const segments = parseSeparatedList(path, "/").map((segment) => AnalyticsPathSegment.fromString(segment));
9
- return new AnalyticsPath(segments);
10
- }
11
- static fromStringArray(segments) {
12
- return new AnalyticsPath(segments.map((segment) => AnalyticsPathSegment.fromString(segment)));
13
- }
14
- static fromArray(segments) {
15
- return new AnalyticsPath(segments);
16
- }
17
- static fromJSON(json) {
18
- const segments = json._v
19
- .split("/")
20
- .map((segment) => AnalyticsPathSegment.fromString(segment));
21
- return new AnalyticsPath(segments);
22
- }
23
- constructor(segments) {
24
- this._segments = segments;
25
- }
26
- toJSON() {
27
- return {
28
- _t: AnalyticsSerializerTypes.AnalyticsPath,
29
- _v: this.toString(),
30
- };
31
- }
32
- toString(tail = "") {
33
- return this._segments.map((s) => s.toString()).join("/") + tail;
34
- }
35
- firstSegment() {
36
- return this._segments.length > 0
37
- ? this._segments[0]
38
- : new AnalyticsPathSegment();
39
- }
40
- reduce() {
41
- const result = this._segments.slice(1);
42
- if (result.length < 1) {
43
- result.push(new AnalyticsPathSegment());
44
- }
45
- return new AnalyticsPath(result);
46
- }
47
- applyLod(levelOfDetail) {
48
- const segments = [...this._segments];
49
- while (segments.length < levelOfDetail) {
50
- segments.push(new AnalyticsPathSegment());
51
- }
52
- return new AnalyticsPath(segments.slice(0, levelOfDetail));
53
- }
54
- }
55
- export class AnalyticsPathSegment {
56
- get filters() {
57
- return this._filters;
58
- }
59
- get groups() {
60
- return this._groups;
61
- }
62
- _filters = null;
63
- _groups = null;
64
- static fromString(segment) {
65
- const elements = parseSeparatedList(segment, ":");
66
- let filtersArg;
67
- if (elements[0] === "*") {
68
- filtersArg = null;
69
- }
70
- else {
71
- filtersArg = parseSeparatedList(elements[0], ",").map((f) => AnalyticsPathSegment.unescape(f));
72
- }
73
- let groupsArg;
74
- if (elements[1] === undefined || elements[1].length < 1) {
75
- groupsArg = [];
76
- }
77
- else if (elements[1] === "*") {
78
- groupsArg = null;
79
- }
80
- else {
81
- groupsArg = parseSeparatedList(elements[1], ",").map((g) => AnalyticsPathSegment.unescape(g));
82
- }
83
- return new AnalyticsPathSegment(filtersArg, groupsArg);
84
- }
85
- static escape(segment) {
86
- // Put a backslash in front of the control characters \ : / and ,
87
- return segment.replace(/(\\|:|\/|,)/gi, "\\$1");
88
- }
89
- static unescape(segment) {
90
- // Remove backslashes in front of any character
91
- return segment.replace(/\\(.)/gi, "$1");
92
- }
93
- constructor(filters = null, groups = []) {
94
- this._filters = filters;
95
- this._groups = groups;
96
- }
97
- toJSON() {
98
- return {
99
- _t: AnalyticsSerializerTypes.AnalyticsPathSegment,
100
- _v: this.toString(),
101
- };
102
- }
103
- toString() {
104
- let result = "";
105
- if (this._filters === null) {
106
- result += "*";
107
- }
108
- else {
109
- result += this._filters
110
- .map((f) => AnalyticsPathSegment.escape(f))
111
- .join(",");
112
- }
113
- if (this._groups === null) {
114
- result += ":*";
115
- }
116
- else if (this._groups.length > 0) {
117
- result +=
118
- ":" + this._groups.map((g) => AnalyticsPathSegment.escape(g)).join(",");
119
- }
120
- return result;
121
- }
122
- }
123
- // Defining constant regexes instead of dynamic patterns for compiler optimization
124
- const unescapedSeparatorPattern = {
125
- ":": /(?<!\\):/,
126
- ",": /(?<!\\),/,
127
- "/": /(?<!\\)\//,
128
- };
129
- function parseSeparatedList(list, separator) {
130
- /*
131
- The basic mechanism is that we split the string by commas that
132
- aren't escaped with a backslash, using the unescapedSeparatorPattern:
133
-
134
- - abc,def becomes ['abc', 'def']
135
- - abc\,def becomes ['abc,def']
136
-
137
- However, we need to deal with an edge case where the backslash
138
- itself is escaped with a backslash:
139
-
140
- - abc\\,def must result in ['abc\\', 'def']
141
- - whereas unescapedCommaPattern would result in ['abc\\,def']
142
-
143
- For this edge case, we are first replacing all double backslashes with @@
144
-
145
- - abc\\,def is first transformed to abc@@,def
146
- - unescapedCommaPattern would now result in ['abc@@', 'def']
147
- - substituting @@ with \\ again now gives the intended result ['abc\\', 'def']
148
-
149
- However, we still want to support the literal string @@ in the input too.
150
- So, instead of always using @@ as a replacement, we're going to determine a unique
151
- string first by adding as many @ as needed.
152
-
153
- - If the original string has @@ in it, we'll use @@@
154
- - If the original string has @@ and @@@ in it, we'll use @@@@
155
- - Etc.
156
- */
157
- let substituteString = "@@";
158
- while (list.indexOf(substituteString) > -1) {
159
- substituteString += "@";
160
- }
161
- return list
162
- .replaceAll("\\\\", substituteString)
163
- .split(unescapedSeparatorPattern[separator])
164
- .map((e) => e.replaceAll(substituteString, "\\\\"));
165
- }
166
- //# sourceMapping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C,IAAY,EAAE,SAAwB;IAChE;;;;;;;;;;;;;;;;;;;;;;;;;;QA0BI;IAEJ,IAAI,gBAAgB,GAAG,IAAI,CAAC;IAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC3C,gBAAgB,IAAI,GAAG,CAAC;IAC1B,CAAC;IAED,OAAO,IAAI;SACR,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAAC;SACpC,KAAK,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -1,214 +0,0 @@
1
- export var AnalyticsSerializerTypes;
2
- (function (AnalyticsSerializerTypes) {
3
- AnalyticsSerializerTypes[AnalyticsSerializerTypes["AnalyticsPath"] = 0] = "AnalyticsPath";
4
- AnalyticsSerializerTypes[AnalyticsSerializerTypes["AnalyticsPathSegment"] = 1] = "AnalyticsPathSegment";
5
- AnalyticsSerializerTypes[AnalyticsSerializerTypes["AnalyticsPeriod"] = 2] = "AnalyticsPeriod";
6
- })(AnalyticsSerializerTypes || (AnalyticsSerializerTypes = {}));
7
- export var AnalyticsPeriodType;
8
- (function (AnalyticsPeriodType) {
9
- AnalyticsPeriodType[AnalyticsPeriodType["Year"] = 0] = "Year";
10
- AnalyticsPeriodType[AnalyticsPeriodType["Quarter"] = 1] = "Quarter";
11
- AnalyticsPeriodType[AnalyticsPeriodType["Month"] = 2] = "Month";
12
- })(AnalyticsPeriodType || (AnalyticsPeriodType = {}));
13
- export class AnalyticsPeriod {
14
- get type() {
15
- return this._type;
16
- }
17
- get year() {
18
- return this._year;
19
- }
20
- get quarter() {
21
- return this._quarter;
22
- }
23
- get month() {
24
- return this._month;
25
- }
26
- _type = AnalyticsPeriodType.Year;
27
- _year = 1970;
28
- _quarter = null;
29
- _month = null;
30
- toJSON() {
31
- return {
32
- _t: AnalyticsSerializerTypes.AnalyticsPeriod,
33
- _v: this.toString(),
34
- };
35
- }
36
- static fromString(period) {
37
- let result;
38
- if (period.length === 4) {
39
- result = new AnalyticsPeriod(Number.parseInt(period));
40
- }
41
- else if (period.length === 7) {
42
- if (period[4] !== "/") {
43
- throw new Error(`Invalid period string: '${period}'`);
44
- }
45
- else if (period[5] === "Q") {
46
- result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), Number.parseInt(period[6]));
47
- }
48
- else {
49
- result = new AnalyticsPeriod(Number.parseInt(period.slice(0, 4)), undefined, Number.parseInt(period.slice(5)));
50
- }
51
- }
52
- else {
53
- throw new Error(`Invalid period string: '${period}'`);
54
- }
55
- return result;
56
- }
57
- static fillRange(p1, p2) {
58
- const obj1 = typeof p1 === "string" ? AnalyticsPeriod.fromString(p1) : p1, obj2 = typeof p2 === "string" ? AnalyticsPeriod.fromString(p2) : p2;
59
- if (obj1.type !== obj2.type) {
60
- throw new Error(`Cannot fill range of different type periods ${obj1.toString()} and ${obj2.toString()}.`);
61
- }
62
- const [first, last] = obj1.comesBefore(obj2) ? [obj1, obj2] : [obj2, obj1];
63
- const result = [first];
64
- let next = first.nextPeriod();
65
- while (next.comesBefore(last)) {
66
- result.push(next);
67
- next = next.nextPeriod();
68
- }
69
- if (!last.equals(first)) {
70
- result.push(last);
71
- }
72
- return result;
73
- }
74
- static normalizeQuarters(year, quarter) {
75
- const newYear = year + Math.floor((quarter - 1) / 4);
76
- const newQuarter = moduloButWithoutBugs(quarter - 1, 4) + 1;
77
- return [newYear, newQuarter, undefined];
78
- }
79
- static normalizeMonths(year, month) {
80
- const newYear = year + Math.floor((month - 1) / 12);
81
- const newMonth = moduloButWithoutBugs(month - 1, 12) + 1;
82
- const newQuarter = Math.floor((newMonth - 1) / 3) + 1;
83
- return [newYear, newQuarter, newMonth];
84
- }
85
- constructor(year, quarter, month) {
86
- this._initAsYear(year);
87
- if (quarter !== undefined) {
88
- this._initAsQuarter(quarter);
89
- }
90
- if (month !== undefined) {
91
- this._initAsMonth(month);
92
- }
93
- }
94
- equals(period) {
95
- return (this.toString() ===
96
- (typeof period === "string" ? period : period.toString()));
97
- }
98
- toString() {
99
- let result = this._year + (this._type === AnalyticsPeriodType.Year ? "" : "/");
100
- if (this._type === AnalyticsPeriodType.Quarter) {
101
- result += "Q" + this._quarter;
102
- }
103
- else if (this._type === AnalyticsPeriodType.Month) {
104
- if (this._month < 10) {
105
- result += "0";
106
- }
107
- result += this._month;
108
- }
109
- return result;
110
- }
111
- startAsSqlDate() {
112
- let result = this._year + "-";
113
- switch (this._type) {
114
- case AnalyticsPeriodType.Month:
115
- result += (this._month < 10 ? "0" : "") + this.month;
116
- break;
117
- case AnalyticsPeriodType.Quarter:
118
- const firstMonth = (this._quarter - 1) * 3 + 1;
119
- result += (firstMonth < 10 ? "0" : "") + firstMonth;
120
- break;
121
- case AnalyticsPeriodType.Year:
122
- result += "01";
123
- break;
124
- }
125
- return result + "-01";
126
- }
127
- comesAfter(period) {
128
- return this._start() > period._end();
129
- }
130
- comesBefore(period) {
131
- return period._start() > this._end();
132
- }
133
- contains(period) {
134
- return this._start() <= period._start() && this._end() >= period._end();
135
- }
136
- firstMonth() {
137
- let month = this._month || 1;
138
- if (this._type === AnalyticsPeriodType.Quarter) {
139
- month = (this._quarter - 1) * 3 + 1;
140
- }
141
- return new AnalyticsPeriod(this._year, undefined, month);
142
- }
143
- lastMonth() {
144
- let month = this._month || 12;
145
- if (this._type === AnalyticsPeriodType.Quarter) {
146
- month = this._quarter * 3;
147
- }
148
- return new AnalyticsPeriod(this._year, undefined, month);
149
- }
150
- nextPeriod(n = 1) {
151
- return this._addPeriods(n);
152
- }
153
- previousPeriod(n = 1) {
154
- return this._addPeriods(-n);
155
- }
156
- _start() {
157
- return this._getNumericComparator(false);
158
- }
159
- _end() {
160
- return this._getNumericComparator(true);
161
- }
162
- _getNumericComparator(endOfPeriod) {
163
- const defaultQuarter = endOfPeriod ? 4 : 1, defaultMonth = ((this._quarter || defaultQuarter) - 1) * 3 + (endOfPeriod ? 3 : 1), result = this._year * 1000 +
164
- (this._quarter || defaultQuarter) * 100 +
165
- (this._month || defaultMonth);
166
- return result;
167
- }
168
- _addPeriods(periods) {
169
- let result;
170
- if (this._type === AnalyticsPeriodType.Year) {
171
- result = new AnalyticsPeriod(this._year + periods);
172
- }
173
- else if (this._type === AnalyticsPeriodType.Quarter) {
174
- const [y, q] = AnalyticsPeriod.normalizeQuarters(this._year, this._quarter + periods);
175
- result = new AnalyticsPeriod(y, q);
176
- }
177
- else {
178
- const [y, _, m] = AnalyticsPeriod.normalizeMonths(this._year, this._month + periods);
179
- result = new AnalyticsPeriod(y, undefined, m);
180
- }
181
- return result;
182
- }
183
- _initAsYear(year) {
184
- if (year < 1970 || year > 2100) {
185
- throw new Error(`Invalid period year: '${year}'`);
186
- }
187
- this._year = year;
188
- }
189
- _initAsQuarter(quarter) {
190
- if (quarter < 1 || quarter > 4) {
191
- throw new Error(`Invalid period quarter: ${quarter}`);
192
- }
193
- this._quarter = quarter;
194
- this._type = AnalyticsPeriodType.Quarter;
195
- }
196
- _initAsMonth(month) {
197
- if (month < 1 || month > 12) {
198
- throw new Error(`Invalid period month: ${month}`);
199
- }
200
- if (this.quarter == null) {
201
- this._initAsQuarter(Math.floor((month - 1) / 3) + 1);
202
- }
203
- else if (this.quarter !== Math.floor((month - 1) / 3) + 1) {
204
- throw new Error(`Period month ${month} outside of quarter ${this.quarter}`);
205
- }
206
- this._month = month;
207
- this._type = AnalyticsPeriodType.Month;
208
- }
209
- }
210
- // See https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers
211
- function moduloButWithoutBugs(base, n) {
212
- return ((base % n) + n) % n;
213
- }
214
- //# sourceMappingURL=AnalyticsPeriod.js.map