@powerhousedao/connect 1.0.17-dev.0 → 1.0.17-dev.2
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/.env +1 -1
- package/dist/assets/AnalyticsProfiler-DD1sT8NE.js +22 -0
- package/dist/assets/AnalyticsProfiler-DD1sT8NE.js.map +1 -0
- package/dist/assets/{app-BRXXLZT5.js → app-CayLrjAy.js} +8081 -3607
- package/dist/assets/app-CayLrjAy.js.map +1 -0
- package/dist/assets/{app-loader-Y-ZBJpoD.js → app-loader-Ej0QwX6c.js} +504 -230
- package/dist/assets/app-loader-Ej0QwX6c.js.map +1 -0
- package/dist/assets/browser-BfB4Waw5.js +27235 -0
- package/dist/assets/browser-BfB4Waw5.js.map +1 -0
- package/dist/assets/{ccip-7fsbpRrz.js → ccip-DBZNMhmz.js} +4 -3
- package/dist/assets/ccip-DBZNMhmz.js.map +1 -0
- package/dist/assets/{content-Bu8QyNhy.js → content-DnXO71l4.js} +5 -3
- package/dist/assets/content-DnXO71l4.js.map +1 -0
- package/dist/assets/{index-CR0CeH0z.js → index-BbMglwKh.js} +21 -15
- package/dist/assets/index-BbMglwKh.js.map +1 -0
- package/dist/assets/{index-BFxvwVpI.js → index-CCSrpy8s.js} +4 -3
- package/dist/assets/index-CCSrpy8s.js.map +1 -0
- package/dist/assets/{index-DDUCDBt7.js → index-CU3_V46J.js} +4 -3
- package/dist/assets/index-CU3_V46J.js.map +1 -0
- package/dist/assets/{main.DWnLOhnO.js → main.D0KZAQpb.js} +2 -1
- package/dist/assets/main.D0KZAQpb.js.map +1 -0
- package/dist/assets/reactor-analytics-BioFquA0.js +605 -0
- package/dist/assets/reactor-analytics-BioFquA0.js.map +1 -0
- package/dist/assets/router-BF9pgdRU.js +2177 -0
- package/dist/assets/router-BF9pgdRU.js.map +1 -0
- package/dist/external-packages.js +1 -0
- package/dist/external-packages.js.map +1 -0
- package/dist/hmr.js +1 -0
- package/dist/hmr.js.map +1 -0
- package/dist/index.html +1 -1
- package/dist/service-worker.js +1 -0
- package/dist/service-worker.js.map +1 -0
- package/dist/vite-envs.sh +1 -1
- package/package.json +10 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-loader-
|
|
2
|
-
import { _ as __vitePreload } from "./main.
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-loader-Ej0QwX6c.js","assets/main.D0KZAQpb.js","assets/app-loader-DiF8OhX3.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import { _ as __vitePreload } from "./main.D0KZAQpb.js";
|
|
3
3
|
import { createRoot } from "react-dom/client";
|
|
4
4
|
async function renderApp(element) {
|
|
5
|
-
const AppLoader = await __vitePreload(() => import("./app-loader-
|
|
5
|
+
const AppLoader = await __vitePreload(() => import("./app-loader-Ej0QwX6c.js").then((n) => n.cb), true ? __vite__mapDeps([0,1,2]) : void 0);
|
|
6
6
|
createRoot(element).render(AppLoader.default);
|
|
7
7
|
}
|
|
8
8
|
const AppElement = document.getElementById("app");
|
|
@@ -10,3 +10,4 @@ if (!AppElement) {
|
|
|
10
10
|
throw new Error("#app element not found!");
|
|
11
11
|
}
|
|
12
12
|
renderApp(AppElement).catch(console.error);
|
|
13
|
+
//# sourceMappingURL=index-CU3_V46J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":";;;AAEA,eAAe,UAAU,SAAsB;AACrC,oBAAY,MAAM,2BAAO,0BAA4B;AAC3D,aAAW,OAAO,EAAE,OAAO,UAAU,OAAO;AAChD;AAEA,MAAM,aAAa,SAAS,eAAe,KAAK;AAChD,IAAI,CAAC,YAAY;AACP,YAAI,MAAM,yBAAyB;AAC7C;AAEA,UAAU,UAAU,EAAE,MAAM,QAAQ,KAAK","names":[],"ignoreList":[],"sources":["../../src/index.ts"],"sourcesContent":["import { createRoot } from 'react-dom/client';\n\nasync function renderApp(element: HTMLElement) {\n const AppLoader = await import('./components/app-loader.js');\n createRoot(element).render(AppLoader.default);\n}\n\nconst AppElement = document.getElementById('app');\nif (!AppElement) {\n throw new Error('#app element not found!');\n}\n\nrenderApp(AppElement).catch(console.error);\n"],"file":"assets/index-CU3_V46J.js"}
|
|
@@ -99,7 +99,8 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
|
|
|
99
99
|
return baseModule().catch(handlePreloadError);
|
|
100
100
|
});
|
|
101
101
|
};
|
|
102
|
-
__vitePreload(() => import("./index-
|
|
102
|
+
__vitePreload(() => import("./index-CU3_V46J.js"), true ? [] : void 0);
|
|
103
103
|
export {
|
|
104
104
|
__vitePreload as _
|
|
105
105
|
};
|
|
106
|
+
//# sourceMappingURL=main.D0KZAQpb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBA8BA,OAAO,qBAAY","names":[],"ignoreList":[],"sources":["../../src/renderer.ts"],"sourcesContent":["/**\n * This file will automatically be loaded by vite and run in the \"renderer\" context.\n * To learn more about the differences between the \"main\" and the \"renderer\" context in\n * Electron, visit:\n *\n * https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes\n *\n * By default, Node.js integration in this file is disabled. When enabling Node.js integration\n * in a renderer process, please be aware of potential security implications. You can read\n * more about security risks here:\n *\n * https://electronjs.org/docs/tutorial/security\n *\n * To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration`\n * flag:\n *\n * ```\n * // Create the browser window.\n * mainWindow = new BrowserWindow({\n * width: 800,\n * height: 600,\n * webPreferences: {\n * nodeIntegration: true\n * }\n * });\n * ```\n */\n\n// splits app code into separate chunk to avoid circular dependencies\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nimport('./index.js');\n"],"file":"assets/main.D0KZAQpb.js"}
|
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { a3 as AnalyticsGranularity, a4 as DateTime, a5 as Interval, a6 as AnalyticsPath, a7 as CompoundOperator, a8 as QueryClient, a9 as QueryClientProvider, aa as useUnwrappedAnalyticsStore } from "./app-CayLrjAy.js";
|
|
6
|
+
import { P as PassthroughAnalyticsProfiler } from "./AnalyticsProfiler-DD1sT8NE.js";
|
|
7
|
+
import { createContext } from "react";
|
|
8
|
+
import "./main.D0KZAQpb.js";
|
|
9
|
+
import "./app-loader-Ej0QwX6c.js";
|
|
10
|
+
import "react-dom";
|
|
11
|
+
const getPeriodSeriesArray = (range) => {
|
|
12
|
+
const result = [];
|
|
13
|
+
const series = getPeriodSeries(range);
|
|
14
|
+
let next = series.next();
|
|
15
|
+
while (next) {
|
|
16
|
+
result.push(next);
|
|
17
|
+
next = series.next();
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
const getPeriodSeries = (range) => {
|
|
22
|
+
return {
|
|
23
|
+
...range,
|
|
24
|
+
next: _createFactoryFn(range)
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const _createFactoryFn = (range) => {
|
|
28
|
+
let current = range.start;
|
|
29
|
+
return () => {
|
|
30
|
+
if (current == null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
let result = null;
|
|
34
|
+
switch (range.granularity) {
|
|
35
|
+
case AnalyticsGranularity.Total:
|
|
36
|
+
result = _nextTotalPeriod(current, range.end);
|
|
37
|
+
break;
|
|
38
|
+
case AnalyticsGranularity.Annual:
|
|
39
|
+
result = _nextAnnualPeriod(current, range.end);
|
|
40
|
+
break;
|
|
41
|
+
case AnalyticsGranularity.SemiAnnual:
|
|
42
|
+
result = _nextSemiAnnualPeriod(current, range.end);
|
|
43
|
+
break;
|
|
44
|
+
case AnalyticsGranularity.Quarterly:
|
|
45
|
+
result = _nextQuarterlyPeriod(current, range.end);
|
|
46
|
+
break;
|
|
47
|
+
case AnalyticsGranularity.Monthly:
|
|
48
|
+
result = _nextMonthlyPeriod(current, range.end);
|
|
49
|
+
break;
|
|
50
|
+
case AnalyticsGranularity.Weekly:
|
|
51
|
+
result = _nextWeeklyPeriod(current, range.end);
|
|
52
|
+
break;
|
|
53
|
+
case AnalyticsGranularity.Daily:
|
|
54
|
+
result = _nextDailyPeriod(current, range.end);
|
|
55
|
+
break;
|
|
56
|
+
case AnalyticsGranularity.Hourly:
|
|
57
|
+
result = _nextHourlyPeriod(current, range.end);
|
|
58
|
+
}
|
|
59
|
+
if (result === null) {
|
|
60
|
+
current = null;
|
|
61
|
+
} else {
|
|
62
|
+
current = result.end.plus({ milliseconds: 1 });
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const _nextTotalPeriod = (nextStart, seriesEnd) => {
|
|
68
|
+
if (seriesEnd <= nextStart) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
period: "total",
|
|
73
|
+
start: nextStart,
|
|
74
|
+
end: seriesEnd
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const _nextAnnualPeriod = (nextStart, seriesEnd) => {
|
|
78
|
+
if (seriesEnd <= nextStart) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const inputUtc = nextStart.toUTC();
|
|
82
|
+
const oneYearLater = DateTime.utc(inputUtc.year, inputUtc.month, inputUtc.day).plus({ years: 1 });
|
|
83
|
+
return {
|
|
84
|
+
period: "annual",
|
|
85
|
+
start: nextStart,
|
|
86
|
+
end: oneYearLater
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const _nextSemiAnnualPeriod = (nextStart, seriesEnd) => {
|
|
90
|
+
if (seriesEnd <= nextStart) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const midYear = DateTime.utc(nextStart.year, 7, 1);
|
|
94
|
+
const endYear = DateTime.utc(nextStart.year, 12, 31, 23, 59, 59, 999);
|
|
95
|
+
let endDate;
|
|
96
|
+
if (midYear > nextStart) {
|
|
97
|
+
endDate = midYear;
|
|
98
|
+
} else {
|
|
99
|
+
endDate = endYear;
|
|
100
|
+
}
|
|
101
|
+
if (endDate > seriesEnd) {
|
|
102
|
+
endDate = seriesEnd;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
period: "semiAnnual",
|
|
106
|
+
start: nextStart,
|
|
107
|
+
end: endDate
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const _nextQuarterlyPeriod = (nextStart, seriesEnd) => {
|
|
111
|
+
if (seriesEnd <= nextStart) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
let endDate;
|
|
115
|
+
const nextStartUtc = nextStart.toUTC();
|
|
116
|
+
const startMonth = nextStartUtc.month;
|
|
117
|
+
if (startMonth < 3) {
|
|
118
|
+
endDate = DateTime.utc(nextStartUtc.year, 4, 1);
|
|
119
|
+
} else if (startMonth < 6) {
|
|
120
|
+
endDate = DateTime.utc(nextStartUtc.year, 7, 1);
|
|
121
|
+
} else if (startMonth < 9) {
|
|
122
|
+
endDate = DateTime.utc(nextStartUtc.year, 10, 1);
|
|
123
|
+
} else {
|
|
124
|
+
endDate = DateTime.utc(nextStartUtc.year, 12, 31, 23, 59, 59, 999);
|
|
125
|
+
}
|
|
126
|
+
if (endDate > seriesEnd) {
|
|
127
|
+
endDate = seriesEnd;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
period: "quarterly",
|
|
131
|
+
start: nextStart,
|
|
132
|
+
end: endDate
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
const _nextMonthlyPeriod = (nextStart, seriesEnd) => {
|
|
136
|
+
if (seriesEnd <= nextStart) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const nextStartUtc = nextStart.toUTC();
|
|
140
|
+
let endDate = DateTime.utc(nextStartUtc.year, nextStartUtc.month, nextStartUtc.day).plus({ months: 1 }).startOf("month");
|
|
141
|
+
if (endDate > seriesEnd) {
|
|
142
|
+
if (!nextStart.hasSame(seriesEnd, "month")) {
|
|
143
|
+
endDate = seriesEnd;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
period: "monthly",
|
|
148
|
+
start: nextStart,
|
|
149
|
+
end: endDate
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const _nextWeeklyPeriod = (nextStart, seriesEnd) => {
|
|
153
|
+
if (seriesEnd <= nextStart) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const nextStartUtc = nextStart.toUTC();
|
|
157
|
+
const nextWeekStartUTC = DateTime.utc(nextStartUtc.year, nextStartUtc.month, nextStartUtc.day).plus({ weeks: 1 }).startOf("week");
|
|
158
|
+
if (nextWeekStartUTC > seriesEnd) {
|
|
159
|
+
if (!nextWeekStartUTC.hasSame(seriesEnd, "day")) {
|
|
160
|
+
return {
|
|
161
|
+
period: "weekly",
|
|
162
|
+
start: nextStart,
|
|
163
|
+
end: seriesEnd
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
period: "weekly",
|
|
169
|
+
start: nextStart,
|
|
170
|
+
end: nextWeekStartUTC
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
const _nextDailyPeriod = (nextStart, seriesEnd) => {
|
|
174
|
+
if (seriesEnd <= nextStart) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const nextStartUtc = nextStart.toUTC();
|
|
178
|
+
let endDate = nextStartUtc.plus({ days: 1 }).startOf("day");
|
|
179
|
+
if (endDate > seriesEnd || endDate.hasSame(seriesEnd, "day")) {
|
|
180
|
+
endDate = seriesEnd;
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
period: "daily",
|
|
184
|
+
start: nextStart,
|
|
185
|
+
end: endDate
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
const _nextHourlyPeriod = (nextStart, seriesEnd) => {
|
|
189
|
+
if (seriesEnd <= nextStart) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const startDate = nextStart.toUTC();
|
|
193
|
+
let endDate = startDate.plus({ hours: 1 });
|
|
194
|
+
if (endDate > seriesEnd) {
|
|
195
|
+
if (nextStart.hour !== seriesEnd.hour) {
|
|
196
|
+
endDate = seriesEnd.toUTC();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
period: "hourly",
|
|
201
|
+
start: nextStart,
|
|
202
|
+
end: endDate
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
const getQuarter = (date) => {
|
|
206
|
+
return Math.floor((date.month - 1) / 3) + 1;
|
|
207
|
+
};
|
|
208
|
+
class AnalyticsDiscretizer {
|
|
209
|
+
static discretize(series, dimensions, start, end, granularity) {
|
|
210
|
+
const index = this._buildIndex(series, dimensions);
|
|
211
|
+
const periods = getPeriodSeriesArray(this._calculateRange(start, end, granularity, series));
|
|
212
|
+
const disretizedResults = this._discretizeNode(index, {}, dimensions, periods);
|
|
213
|
+
const groupedResults = this._groupResultsByPeriod(periods, disretizedResults);
|
|
214
|
+
return groupedResults;
|
|
215
|
+
}
|
|
216
|
+
static _calculateRange(start, end, granularity, results) {
|
|
217
|
+
let calculatedStart = start || null;
|
|
218
|
+
let calculatedEnd = end || null;
|
|
219
|
+
if (calculatedStart == null || calculatedEnd == null) {
|
|
220
|
+
for (const r of results) {
|
|
221
|
+
if (calculatedStart == null) {
|
|
222
|
+
calculatedStart = r.start;
|
|
223
|
+
}
|
|
224
|
+
const endValue = r.end || r.start;
|
|
225
|
+
if (calculatedEnd == null || calculatedEnd < endValue) {
|
|
226
|
+
calculatedEnd = endValue;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (calculatedStart == null || calculatedEnd == null) {
|
|
231
|
+
throw new Error("Cannot determine query start and/or end.");
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
start: calculatedStart,
|
|
235
|
+
end: calculatedEnd,
|
|
236
|
+
granularity
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
static _groupResultsByPeriod(periods, dimensionedResults) {
|
|
240
|
+
const result = {};
|
|
241
|
+
for (const p of periods) {
|
|
242
|
+
const id = p.start.toISO() + "-" + p.period;
|
|
243
|
+
const period = AnalyticsDiscretizer._getPeriodString(p);
|
|
244
|
+
result[id] = {
|
|
245
|
+
period,
|
|
246
|
+
start: p.start,
|
|
247
|
+
end: p.end,
|
|
248
|
+
rows: []
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
for (const r of dimensionedResults) {
|
|
252
|
+
for (const period of Object.keys(r.series)) {
|
|
253
|
+
result[period].rows.push({
|
|
254
|
+
dimensions: r.dimensions,
|
|
255
|
+
metric: r.metric,
|
|
256
|
+
unit: r.unit == "__NULL__" ? null : r.unit,
|
|
257
|
+
value: r.series[period].inc,
|
|
258
|
+
sum: r.series[period].sum
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return Object.values(result);
|
|
263
|
+
}
|
|
264
|
+
static _getPeriodString(p) {
|
|
265
|
+
switch (p.period) {
|
|
266
|
+
case "annual":
|
|
267
|
+
return p.start.year.toString();
|
|
268
|
+
case "semiAnnual":
|
|
269
|
+
return `${p.start.year}/${p.start.month < 7 ? "H1" : "H2"}`;
|
|
270
|
+
case "quarterly":
|
|
271
|
+
return `${p.start.year}/Q${getQuarter(p.start)}`;
|
|
272
|
+
case "monthly":
|
|
273
|
+
const month = p.start.toUTC().month;
|
|
274
|
+
const formattedMonth = month < 10 ? `0${month}` : `${month}`;
|
|
275
|
+
return `${p.start.year}/${formattedMonth}`;
|
|
276
|
+
case "weekly":
|
|
277
|
+
return `${p.start.weekYear}/W${p.start.weekNumber}`;
|
|
278
|
+
case "daily":
|
|
279
|
+
const monthD = p.start.month;
|
|
280
|
+
const day = p.start.day;
|
|
281
|
+
const formattedMonthD = monthD < 10 ? `0${monthD}` : `${monthD}`;
|
|
282
|
+
const formattedDay = day < 10 ? `0${day}` : `${day}`;
|
|
283
|
+
return `${p.start.year}/${formattedMonthD}/${formattedDay}`;
|
|
284
|
+
case "hourly":
|
|
285
|
+
const monthH = p.start.month;
|
|
286
|
+
const dayH = p.start.day;
|
|
287
|
+
const hourH = p.start.hour;
|
|
288
|
+
const formattedMonthH = monthH < 10 ? `0${monthH}` : `${monthH}`;
|
|
289
|
+
const formattedDayH = dayH < 10 ? `0${dayH}` : `${dayH}`;
|
|
290
|
+
const formattedHourH = hourH < 10 ? `0${hourH}` : `${hourH}`;
|
|
291
|
+
return `${p.start.year}/${formattedMonthH}/${formattedDayH}/${formattedHourH}`;
|
|
292
|
+
default:
|
|
293
|
+
return p.period;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
static _discretizeNode(node, dimensionValues, remainingDimensions, periods) {
|
|
297
|
+
const result = [];
|
|
298
|
+
if (remainingDimensions.length > 0) {
|
|
299
|
+
const subdimension = remainingDimensions[0];
|
|
300
|
+
Object.keys(node).forEach((subdimensionValue, index, arr) => {
|
|
301
|
+
const newDimensionValues = { ...dimensionValues };
|
|
302
|
+
newDimensionValues[subdimension] = subdimensionValue;
|
|
303
|
+
result.push(...this._discretizeNode(node[subdimensionValue], newDimensionValues, remainingDimensions.slice(1), periods));
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
Object.keys(node).forEach((metric) => {
|
|
307
|
+
result.push(...this._discretizeLeaf(node[metric], periods, metric, dimensionValues));
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
static _discretizeLeaf(leaf, periods, metric, dimensionValues) {
|
|
313
|
+
const result = [];
|
|
314
|
+
Object.keys(leaf).forEach((unit) => {
|
|
315
|
+
const metaDimensions = {};
|
|
316
|
+
Object.keys(dimensionValues).forEach((k) => {
|
|
317
|
+
metaDimensions[k] = {
|
|
318
|
+
path: leaf[unit][0].dimensions[k],
|
|
319
|
+
icon: leaf[unit][0].dimensions.icon,
|
|
320
|
+
label: leaf[unit][0].dimensions.label,
|
|
321
|
+
description: leaf[unit][0].dimensions.description
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
result.push({
|
|
325
|
+
unit,
|
|
326
|
+
metric,
|
|
327
|
+
dimensions: metaDimensions,
|
|
328
|
+
series: this._discretizeSeries(leaf[unit], periods)
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
static _discretizeSeries(series, periods) {
|
|
334
|
+
const result = {};
|
|
335
|
+
for (const s of series) {
|
|
336
|
+
let oldSum = this._getValue(s, periods[0].start);
|
|
337
|
+
for (const p of periods) {
|
|
338
|
+
const newSum = this._getValue(s, p.end);
|
|
339
|
+
const id = `${p.start.toISO()}-${p.period}`;
|
|
340
|
+
if (result[id]) {
|
|
341
|
+
result[id].inc += newSum - oldSum;
|
|
342
|
+
result[id].sum += newSum;
|
|
343
|
+
} else {
|
|
344
|
+
result[id] = {
|
|
345
|
+
inc: newSum - oldSum,
|
|
346
|
+
sum: newSum
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
oldSum = newSum;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
static _getValue(series, when) {
|
|
355
|
+
switch (series.fn) {
|
|
356
|
+
case "Single":
|
|
357
|
+
return this._getSingleValue(series, when);
|
|
358
|
+
case "DssVest":
|
|
359
|
+
return this._getVestValue(series, when);
|
|
360
|
+
default:
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
static _getSingleValue(series, when) {
|
|
365
|
+
return when >= series.start ? series.value : 0;
|
|
366
|
+
}
|
|
367
|
+
static _getVestValue(series, when) {
|
|
368
|
+
var _a;
|
|
369
|
+
const now = when;
|
|
370
|
+
const start = series.start;
|
|
371
|
+
const end = series.end;
|
|
372
|
+
const cliff = ((_a = series.params) == null ? void 0 : _a.cliff) ? DateTime.fromISO(series.params.cliff) : null;
|
|
373
|
+
if (now < start || cliff && now < cliff) {
|
|
374
|
+
return 0;
|
|
375
|
+
} else if (end && now >= end) {
|
|
376
|
+
return series.value;
|
|
377
|
+
}
|
|
378
|
+
const a = Interval.fromDateTimes(start, now);
|
|
379
|
+
const b = Interval.fromDateTimes(start, end || now);
|
|
380
|
+
return a.length() / b.length() * series.value;
|
|
381
|
+
}
|
|
382
|
+
static _buildIndex(series, dimensions) {
|
|
383
|
+
const result = {};
|
|
384
|
+
const map = {};
|
|
385
|
+
const dimName = dimensions[0] || "";
|
|
386
|
+
for (const s of series) {
|
|
387
|
+
const dimValue = s.dimensions[dimName];
|
|
388
|
+
if (void 0 === map[dimValue]) {
|
|
389
|
+
map[dimValue] = [];
|
|
390
|
+
}
|
|
391
|
+
map[dimValue].push(s);
|
|
392
|
+
}
|
|
393
|
+
if (dimensions.length > 1) {
|
|
394
|
+
const newDimensions = dimensions.slice(1);
|
|
395
|
+
Object.keys(map).forEach((k) => {
|
|
396
|
+
result[k] = this._buildIndex(map[k], newDimensions);
|
|
397
|
+
});
|
|
398
|
+
} else {
|
|
399
|
+
Object.keys(map).forEach((k) => {
|
|
400
|
+
result[k] = this._buildMetricsIndex(map[k]);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
405
|
+
static _buildMetricsIndex(series) {
|
|
406
|
+
const result = {};
|
|
407
|
+
const map = {};
|
|
408
|
+
for (const s of series) {
|
|
409
|
+
const metric = s.metric;
|
|
410
|
+
if (void 0 === map[metric]) {
|
|
411
|
+
map[metric] = [];
|
|
412
|
+
}
|
|
413
|
+
map[metric].push(s);
|
|
414
|
+
}
|
|
415
|
+
Object.keys(map).forEach((k) => result[k] = this._buildUnitIndex(map[k]));
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
static _buildUnitIndex(series) {
|
|
419
|
+
const result = {};
|
|
420
|
+
for (const s of series) {
|
|
421
|
+
const unit = s.unit || "__NULL__";
|
|
422
|
+
if (void 0 === result[unit]) {
|
|
423
|
+
result[unit] = [];
|
|
424
|
+
}
|
|
425
|
+
result[unit].push(s);
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
class AnalyticsQueryEngine {
|
|
431
|
+
constructor(_analyticsStore, profiler) {
|
|
432
|
+
__publicField(this, "_analyticsStore");
|
|
433
|
+
__publicField(this, "_profiler");
|
|
434
|
+
this._analyticsStore = _analyticsStore;
|
|
435
|
+
this._profiler = profiler ?? new PassthroughAnalyticsProfiler();
|
|
436
|
+
}
|
|
437
|
+
async executeCompound(query) {
|
|
438
|
+
let result;
|
|
439
|
+
const inputsQuery = {
|
|
440
|
+
start: query.start,
|
|
441
|
+
end: query.end,
|
|
442
|
+
granularity: query.granularity,
|
|
443
|
+
lod: query.lod,
|
|
444
|
+
select: query.select,
|
|
445
|
+
metrics: query.expression.inputs.metrics,
|
|
446
|
+
currency: query.expression.inputs.currency
|
|
447
|
+
};
|
|
448
|
+
const operandQuery = {
|
|
449
|
+
start: query.start,
|
|
450
|
+
end: query.end,
|
|
451
|
+
granularity: query.granularity,
|
|
452
|
+
lod: { priceData: 1 },
|
|
453
|
+
select: { priceData: [AnalyticsPath.fromString("atlas")] },
|
|
454
|
+
metrics: [query.expression.operand.metric],
|
|
455
|
+
currency: query.expression.operand.currency
|
|
456
|
+
};
|
|
457
|
+
const inputExecute = await this.execute(inputsQuery);
|
|
458
|
+
const operandExecute = await this.execute(operandQuery);
|
|
459
|
+
if ([CompoundOperator.VectorAdd, CompoundOperator.VectorSubtract].includes(query.expression.operator)) {
|
|
460
|
+
result = await this._profiler.record("ApplyVectorOperator", async () => await this._applyVectorOperator(inputExecute, operandExecute, query.expression.operator, query.expression.resultCurrency));
|
|
461
|
+
} else {
|
|
462
|
+
result = await this._profiler.record("ApplyScalarOperator", async () => await this._applyScalarOperator(inputExecute, operandExecute, query.expression.operator, query.expression.operand.useSum, query.expression.resultCurrency));
|
|
463
|
+
}
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
async execute(query) {
|
|
467
|
+
const seriesResults = await this._executeSeriesQuery(query);
|
|
468
|
+
const normalizedSeriesResults = this._profiler.recordSync("ApplyLODs", () => this._applyLods(seriesResults, query.lod));
|
|
469
|
+
const dimensions = Object.keys(query.select);
|
|
470
|
+
const discretizedResult = this._profiler.recordSync("Discretize", () => normalizedSeriesResults.length < 1 ? [] : AnalyticsDiscretizer.discretize(normalizedSeriesResults, dimensions, query.start, query.end, query.granularity));
|
|
471
|
+
return discretizedResult;
|
|
472
|
+
}
|
|
473
|
+
async executeMultiCurrency(query, mcc) {
|
|
474
|
+
const baseQuery = {
|
|
475
|
+
...query,
|
|
476
|
+
currency: mcc.targetCurrency
|
|
477
|
+
};
|
|
478
|
+
let result = await this.execute(baseQuery);
|
|
479
|
+
for (const conversion of mcc.conversions) {
|
|
480
|
+
const nextQuery = {
|
|
481
|
+
start: query.start,
|
|
482
|
+
end: query.end,
|
|
483
|
+
granularity: query.granularity,
|
|
484
|
+
lod: query.lod,
|
|
485
|
+
select: query.select,
|
|
486
|
+
expression: {
|
|
487
|
+
inputs: {
|
|
488
|
+
metrics: baseQuery.metrics,
|
|
489
|
+
currency: conversion.currency
|
|
490
|
+
},
|
|
491
|
+
operator: CompoundOperator.ScalarMultiply,
|
|
492
|
+
operand: {
|
|
493
|
+
metric: conversion.metric,
|
|
494
|
+
currency: mcc.targetCurrency,
|
|
495
|
+
useSum: true
|
|
496
|
+
},
|
|
497
|
+
resultCurrency: mcc.targetCurrency
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const executedCompound = await this.executeCompound(nextQuery);
|
|
501
|
+
result = await this._applyVectorOperator(result, executedCompound, CompoundOperator.VectorAdd, mcc.targetCurrency);
|
|
502
|
+
}
|
|
503
|
+
return result;
|
|
504
|
+
}
|
|
505
|
+
async _applyVectorOperator(inputsA, inputsB, operator, resultCurrency) {
|
|
506
|
+
if ([CompoundOperator.ScalarMultiply, CompoundOperator.ScalarDivide].includes(operator)) {
|
|
507
|
+
throw new Error("Invalid operator for vector operation");
|
|
508
|
+
}
|
|
509
|
+
return inputsB;
|
|
510
|
+
}
|
|
511
|
+
async _applyScalarOperator(inputs, operand, operator, useOperandSum, resultCurrency) {
|
|
512
|
+
if ([CompoundOperator.VectorAdd, CompoundOperator.VectorSubtract].includes(operator)) {
|
|
513
|
+
throw new Error("Invalid operator for scalar operation");
|
|
514
|
+
}
|
|
515
|
+
const result = [];
|
|
516
|
+
const operandMap = {};
|
|
517
|
+
const key = useOperandSum ? "sum" : "value";
|
|
518
|
+
for (const operandPeriod of operand) {
|
|
519
|
+
if (operandPeriod.rows.length > 0) {
|
|
520
|
+
operandMap[operandPeriod.period] = operandPeriod.rows[0][key];
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
for (const inputPeriod of inputs) {
|
|
524
|
+
const outputPeriod = {
|
|
525
|
+
period: inputPeriod.period,
|
|
526
|
+
start: inputPeriod.start,
|
|
527
|
+
end: inputPeriod.end,
|
|
528
|
+
rows: inputPeriod.rows.map((row) => {
|
|
529
|
+
const newRow = {
|
|
530
|
+
dimensions: row.dimensions,
|
|
531
|
+
metric: row.metric,
|
|
532
|
+
unit: resultCurrency.toString(),
|
|
533
|
+
value: this._calculateOutputValue(row.value, operator, operandMap[inputPeriod.period]),
|
|
534
|
+
sum: -1
|
|
535
|
+
};
|
|
536
|
+
return newRow;
|
|
537
|
+
})
|
|
538
|
+
};
|
|
539
|
+
result.push(outputPeriod);
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
_calculateOutputValue(input, operator, operand) {
|
|
544
|
+
switch (operator) {
|
|
545
|
+
case CompoundOperator.VectorAdd:
|
|
546
|
+
return input + operand;
|
|
547
|
+
case CompoundOperator.VectorSubtract:
|
|
548
|
+
return input - operand;
|
|
549
|
+
case CompoundOperator.ScalarMultiply:
|
|
550
|
+
return input * operand;
|
|
551
|
+
case CompoundOperator.ScalarDivide:
|
|
552
|
+
return input / operand;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async _executeSeriesQuery(query) {
|
|
556
|
+
const seriesQuery = {
|
|
557
|
+
start: query.start,
|
|
558
|
+
end: query.end,
|
|
559
|
+
currency: query.currency,
|
|
560
|
+
select: query.select,
|
|
561
|
+
metrics: query.metrics
|
|
562
|
+
};
|
|
563
|
+
return await this._analyticsStore.getMatchingSeries(seriesQuery);
|
|
564
|
+
}
|
|
565
|
+
_applyLods(series, lods) {
|
|
566
|
+
return series.map((result) => ({
|
|
567
|
+
...result,
|
|
568
|
+
dimensions: this._applyDimensionsLods(result.dimensions, lods)
|
|
569
|
+
}));
|
|
570
|
+
}
|
|
571
|
+
_applyDimensionsLods(dimensionMap, lods) {
|
|
572
|
+
const result = {};
|
|
573
|
+
for (const [dimension, lod] of Object.entries(lods)) {
|
|
574
|
+
if (lod !== null && dimensionMap[dimension]) {
|
|
575
|
+
result[dimension] = dimensionMap[dimension]["path"].applyLod(lod).toString();
|
|
576
|
+
result["icon"] = dimensionMap[dimension]["icon"].toString();
|
|
577
|
+
result["label"] = dimensionMap[dimension]["label"].toString();
|
|
578
|
+
result["description"] = dimensionMap[dimension]["description"].toString();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return result;
|
|
582
|
+
}
|
|
583
|
+
async getDimensions() {
|
|
584
|
+
return await this._analyticsStore.getDimensions();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const AnalyticsContext = createContext(null);
|
|
588
|
+
const defaultQueryClient = new QueryClient();
|
|
589
|
+
function AnalyticsProvider({ children, store, queryClient = defaultQueryClient }) {
|
|
590
|
+
const engine = new AnalyticsQueryEngine(store);
|
|
591
|
+
const content = jsx(AnalyticsContext.Provider, { value: { store, engine }, children });
|
|
592
|
+
if (queryClient === false) {
|
|
593
|
+
return content;
|
|
594
|
+
}
|
|
595
|
+
return jsx(QueryClientProvider, { client: queryClient, children: content });
|
|
596
|
+
}
|
|
597
|
+
function ReactorAnalyticsProvider({ children }) {
|
|
598
|
+
const store = useUnwrappedAnalyticsStore();
|
|
599
|
+
return store ? /* @__PURE__ */ jsx(AnalyticsProvider, { store, children }) : children;
|
|
600
|
+
}
|
|
601
|
+
export {
|
|
602
|
+
ReactorAnalyticsProvider,
|
|
603
|
+
ReactorAnalyticsProvider as default
|
|
604
|
+
};
|
|
605
|
+
//# sourceMappingURL=reactor-analytics-BioFquA0.js.map
|