@talkpilot/core-db 1.3.1 → 1.3.4
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/.claude/settings.local.json +7 -0
- package/README.md +30 -0
- package/dist/municipal/tickets/index.d.ts +2 -1
- package/dist/municipal/tickets/index.d.ts.map +1 -1
- package/dist/municipal/tickets/index.js +1 -0
- package/dist/municipal/tickets/index.js.map +1 -1
- package/dist/municipal/tickets/tickets.constants.d.ts +7 -0
- package/dist/municipal/tickets/tickets.constants.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.constants.js +10 -0
- package/dist/municipal/tickets/tickets.constants.js.map +1 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +12 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.js +131 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.getters.d.ts +0 -11
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +0 -128
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +35 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +86 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts +7 -0
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.dates.js +40 -0
- package/dist/municipal/tickets/tickets.statistics.dates.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts +8 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js +44 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +53 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.js +112 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts +7 -0
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.utils.js +40 -0
- package/dist/municipal/tickets/tickets.statistics.utils.js.map +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts +14 -5
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.constants.d.ts +17 -0
- package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.constants.js +20 -0
- package/dist/talkpilot/calls/calls.constants.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts +28 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js +424 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +12 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js +37 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +17 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.js +33 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +39 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.js +3 -0
- package/dist/talkpilot/calls/calls.statistics.types.js.map +1 -0
- package/dist/talkpilot/calls/calls.types.d.ts +1 -2
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +0 -3
- package/dist/talkpilot/calls/calls.types.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +33 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js +131 -146
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +27 -6
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/index.d.ts +3 -0
- package/dist/talkpilot/calls/index.d.ts.map +1 -1
- package/dist/talkpilot/calls/index.js +3 -0
- package/dist/talkpilot/calls/index.js.map +1 -1
- package/dist/utils/date.utils.d.ts +49 -0
- package/dist/utils/date.utils.d.ts.map +1 -0
- package/dist/utils/date.utils.js +103 -0
- package/dist/utils/date.utils.js.map +1 -0
- package/dist/utils/statistics.aggregation.d.ts +20 -0
- package/dist/utils/statistics.aggregation.d.ts.map +1 -0
- package/dist/utils/statistics.aggregation.js +43 -0
- package/dist/utils/statistics.aggregation.js.map +1 -0
- package/package.json +1 -1
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +51 -0
- package/src/municipal/tickets/index.ts +2 -1
- package/src/municipal/tickets/tickets.constants.ts +8 -0
- package/src/municipal/tickets/tickets.getters.ts +0 -140
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +96 -0
- package/src/municipal/tickets/tickets.statistics.getters.ts +71 -0
- package/src/municipal/tickets/tickets.types.ts +19 -9
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +8 -111
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +344 -0
- package/src/talkpilot/calls/calls.constants.ts +20 -0
- package/src/talkpilot/calls/calls.statistics.getters.ts +587 -0
- package/src/talkpilot/calls/calls.statistics.types.ts +44 -0
- package/src/talkpilot/calls/calls.types.ts +4 -2
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +148 -197
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +25 -12
- package/src/talkpilot/calls/index.ts +3 -0
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +7 -0
- package/src/utils/date.utils.ts +116 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ObjectId, Sort, WithId } from "mongodb";
|
|
2
2
|
import { TranscriptionSegment } from "../results";
|
|
3
3
|
import { LeadProperty } from "../leads";
|
|
4
|
-
|
|
5
|
-
export declare const CONFERENCE_ROLE_SUPERVISOR: "supervisor";
|
|
4
|
+
import { CONFERENCE_ROLE_CUSTOMER, CONFERENCE_ROLE_SUPERVISOR } from "./calls.constants";
|
|
6
5
|
export type ConferenceRole = typeof CONFERENCE_ROLE_CUSTOMER | typeof CONFERENCE_ROLE_SUPERVISOR | null;
|
|
7
6
|
export type Call = {
|
|
8
7
|
callSid: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,
|
|
1
|
+
{"version":3,"file":"calls.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,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,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,qBAAqB,GACrB,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,GAChB,WAAW,GACX,SAAS,GACT,QAAQ,GACR,UAAU,GACV,OAAO,GACP,UAAU,GACV,KAAK,GACL,WAAW,CAAC;AAEhB,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAEnC,MAAM,MAAM,SAAS,GAAG;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,KAAK,CAAC,EAAE,IAAI,CAAC;CACd,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONFERENCE_ROLE_SUPERVISOR = exports.CONFERENCE_ROLE_CUSTOMER = void 0;
|
|
4
|
-
exports.CONFERENCE_ROLE_CUSTOMER = "customer";
|
|
5
|
-
exports.CONFERENCE_ROLE_SUPERVISOR = "supervisor";
|
|
6
3
|
//# sourceMappingURL=calls.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.types.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calls.types.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
import { DashboardReportQuery, DashboardReportResponse } from "./calls.dashboard.types";
|
|
2
|
-
|
|
2
|
+
import { CallLengthThresholds } from "src/utils/shared.types";
|
|
3
|
+
export declare function buildCallLengthBucketsPipeline(thresholds: CallLengthThresholds): {
|
|
4
|
+
$group: {
|
|
5
|
+
_id: null;
|
|
6
|
+
short: {
|
|
7
|
+
$sum: {
|
|
8
|
+
$cond: (number | {
|
|
9
|
+
$lt: (string | number)[];
|
|
10
|
+
})[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
medium: {
|
|
14
|
+
$sum: {
|
|
15
|
+
$cond: (number | {
|
|
16
|
+
$and: ({
|
|
17
|
+
$gte: (string | number)[];
|
|
18
|
+
$lte?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
$lte: (string | number)[];
|
|
21
|
+
$gte?: undefined;
|
|
22
|
+
})[];
|
|
23
|
+
})[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
long: {
|
|
27
|
+
$sum: {
|
|
28
|
+
$cond: (number | {
|
|
29
|
+
$gt: (string | number)[];
|
|
30
|
+
})[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}[];
|
|
3
35
|
export declare function getDashboardStats(params: DashboardReportQuery): Promise<DashboardReportResponse>;
|
|
4
36
|
//# sourceMappingURL=calls.dashboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calls.dashboard.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":"AAKA,OAAO,EAIL,oBAAoB,EACpB,uBAAuB,EAIxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA+E9D,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA+BjC;AAgCD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,uBAAuB,CAAC,CAkFlC"}
|
|
@@ -3,168 +3,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildCallLengthBucketsPipeline = buildCallLengthBucketsPipeline;
|
|
6
7
|
exports.getDashboardStats = getDashboardStats;
|
|
7
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
9
|
const calls_getters_1 = require("../calls.getters");
|
|
9
10
|
const clientsConfig_1 = require("../../clientsConfig");
|
|
10
11
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
11
12
|
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
12
|
-
const isoWeek_1 = __importDefault(require("dayjs/plugin/isoWeek"));
|
|
13
|
-
const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
|
|
14
13
|
const DEFAULT_KPI_DATA = {
|
|
14
|
+
totalCalls: 0,
|
|
15
|
+
totalDuration: 0,
|
|
15
16
|
completedCount: 0,
|
|
17
|
+
failedCount: 0,
|
|
18
|
+
noAnswerCount: 0,
|
|
16
19
|
busyCount: 0,
|
|
17
|
-
answeredDuration: 0,
|
|
18
20
|
};
|
|
19
21
|
dayjs_1.default.extend(utc_1.default);
|
|
20
22
|
dayjs_1.default.extend(timezone_1.default);
|
|
21
|
-
dayjs_1.default.extend(isoWeek_1.default);
|
|
22
|
-
dayjs_1.default.extend(quarterOfYear_1.default);
|
|
23
|
-
const BUCKET_UNIT = {
|
|
24
|
-
hour: "hour",
|
|
25
|
-
day: "day",
|
|
26
|
-
week: "isoWeek",
|
|
27
|
-
month: "month",
|
|
28
|
-
quarter: "quarter",
|
|
29
|
-
year: "year",
|
|
30
|
-
};
|
|
31
|
-
function formatBucketKey(bucketStart, granularity) {
|
|
32
|
-
switch (granularity) {
|
|
33
|
-
case "hour":
|
|
34
|
-
return bucketStart.format("YYYY-MM-DDTHH:00");
|
|
35
|
-
case "day":
|
|
36
|
-
case "week":
|
|
37
|
-
return bucketStart.format("YYYY-MM-DD");
|
|
38
|
-
case "month":
|
|
39
|
-
return bucketStart.format("YYYY-MM");
|
|
40
|
-
case "quarter":
|
|
41
|
-
return `${bucketStart.format("YYYY")}-Q${bucketStart.quarter()}`;
|
|
42
|
-
case "year":
|
|
43
|
-
return bucketStart.format("YYYY");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function generateBucketKeys(startDateObj, endDateObj, granularity, timezone) {
|
|
47
|
-
const unitName = BUCKET_UNIT[granularity];
|
|
48
|
-
const startOfUnit = unitName;
|
|
49
|
-
const stepUnit = (unitName === "isoWeek" ? "week" : unitName);
|
|
50
|
-
const end = (0, dayjs_1.default)(endDateObj).tz(timezone);
|
|
51
|
-
let cursor = (0, dayjs_1.default)(startDateObj).tz(timezone).startOf(startOfUnit);
|
|
52
|
-
const keys = [];
|
|
53
|
-
while (cursor.isBefore(end) || cursor.isSame(end, startOfUnit)) {
|
|
54
|
-
keys.push(formatBucketKey(cursor, granularity));
|
|
55
|
-
cursor = cursor.add(1, stepUnit);
|
|
56
|
-
}
|
|
57
|
-
return keys;
|
|
58
|
-
}
|
|
59
|
-
function fillVolumeGaps(bucketKeys, volumeDataRaw) {
|
|
60
|
-
const completedByKey = new Map(volumeDataRaw.map((d) => [d.date, d.completed]));
|
|
61
|
-
return bucketKeys.map((date) => ({
|
|
62
|
-
date,
|
|
63
|
-
completed: completedByKey.get(date) ?? 0,
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
function resolveVolumeGranularity(startDateObj, endDateObj) {
|
|
67
|
-
const spanDays = (0, dayjs_1.default)(endDateObj).diff((0, dayjs_1.default)(startDateObj), "day");
|
|
68
|
-
if (spanDays <= 2)
|
|
69
|
-
return "hour";
|
|
70
|
-
if (spanDays <= 60)
|
|
71
|
-
return "day";
|
|
72
|
-
if (spanDays <= 365)
|
|
73
|
-
return "week";
|
|
74
|
-
if (spanDays <= 730)
|
|
75
|
-
return "month";
|
|
76
|
-
if (spanDays <= 1460)
|
|
77
|
-
return "quarter";
|
|
78
|
-
return "year";
|
|
79
|
-
}
|
|
80
|
-
const VOLUME_DATE_FORMATS = {
|
|
81
|
-
hour: "%Y-%m-%dT%H:00",
|
|
82
|
-
day: "%Y-%m-%d",
|
|
83
|
-
month: "%Y-%m",
|
|
84
|
-
year: "%Y",
|
|
85
|
-
};
|
|
86
|
-
function buildVolumeBucketIdExpression(timezone, granularity) {
|
|
87
|
-
if (granularity === "week") {
|
|
88
|
-
return {
|
|
89
|
-
$dateToString: {
|
|
90
|
-
format: "%Y-%m-%d",
|
|
91
|
-
date: {
|
|
92
|
-
$dateTrunc: {
|
|
93
|
-
date: "$createdAt",
|
|
94
|
-
unit: "week",
|
|
95
|
-
timezone,
|
|
96
|
-
startOfWeek: "monday",
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
timezone,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (granularity === "quarter") {
|
|
104
|
-
return {
|
|
105
|
-
$concat: [
|
|
106
|
-
{ $toString: { $year: { date: "$createdAt", timezone } } },
|
|
107
|
-
"-Q",
|
|
108
|
-
{
|
|
109
|
-
$toString: {
|
|
110
|
-
$add: [
|
|
111
|
-
{
|
|
112
|
-
$trunc: {
|
|
113
|
-
$divide: [
|
|
114
|
-
{
|
|
115
|
-
$subtract: [
|
|
116
|
-
{ $month: { date: "$createdAt", timezone } },
|
|
117
|
-
1,
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
3,
|
|
121
|
-
],
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
1,
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
$dateToString: {
|
|
133
|
-
format: VOLUME_DATE_FORMATS[granularity],
|
|
134
|
-
date: "$createdAt",
|
|
135
|
-
timezone,
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
23
|
function buildKpisPipeline() {
|
|
140
24
|
return [
|
|
141
25
|
{
|
|
142
26
|
$group: {
|
|
143
27
|
_id: null,
|
|
28
|
+
totalCalls: { $sum: 1 },
|
|
29
|
+
totalDuration: { $sum: "$callLength" },
|
|
144
30
|
completedCount: {
|
|
145
31
|
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
146
32
|
},
|
|
33
|
+
failedCount: {
|
|
34
|
+
$sum: { $cond: [{ $eq: ["$status", "failed"] }, 1, 0] },
|
|
35
|
+
},
|
|
36
|
+
noAnswerCount: {
|
|
37
|
+
$sum: { $cond: [{ $eq: ["$status", "no-answer"] }, 1, 0] },
|
|
38
|
+
},
|
|
147
39
|
busyCount: {
|
|
148
40
|
$sum: { $cond: [{ $eq: ["$status", "busy"] }, 1, 0] },
|
|
149
41
|
},
|
|
150
|
-
answeredDuration: {
|
|
151
|
-
$sum: {
|
|
152
|
-
$cond: [
|
|
153
|
-
{ $in: ["$status", ["completed", "busy"]] },
|
|
154
|
-
"$callLength",
|
|
155
|
-
0,
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
42
|
},
|
|
160
43
|
},
|
|
161
44
|
];
|
|
162
45
|
}
|
|
163
|
-
function
|
|
46
|
+
function buildDailyDataPipeline(timezone) {
|
|
164
47
|
return [
|
|
165
48
|
{
|
|
166
49
|
$group: {
|
|
167
|
-
_id:
|
|
50
|
+
_id: {
|
|
51
|
+
$dateToString: {
|
|
52
|
+
format: "%Y-%m-%d",
|
|
53
|
+
date: "$createdAt",
|
|
54
|
+
timezone: timezone,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
count: { $sum: 1 },
|
|
168
58
|
completed: {
|
|
169
59
|
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
170
60
|
},
|
|
@@ -173,13 +63,86 @@ function buildVolumeDataPipeline(timezone, granularity) {
|
|
|
173
63
|
{ $sort: { _id: 1 } },
|
|
174
64
|
];
|
|
175
65
|
}
|
|
66
|
+
function buildHourlyDataPipeline(timezone) {
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
$group: {
|
|
70
|
+
_id: {
|
|
71
|
+
day: {
|
|
72
|
+
$dateToString: {
|
|
73
|
+
format: "%Y-%m-%d",
|
|
74
|
+
date: "$createdAt",
|
|
75
|
+
timezone: timezone,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
hour: { $hour: { date: "$createdAt", timezone: timezone } },
|
|
79
|
+
},
|
|
80
|
+
count: { $sum: 1 },
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
function buildCallLengthBucketsPipeline(thresholds) {
|
|
86
|
+
const { shortThreshold, mediumThreshold } = thresholds;
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
$group: {
|
|
90
|
+
_id: null,
|
|
91
|
+
short: {
|
|
92
|
+
$sum: { $cond: [{ $lt: ["$callLength", shortThreshold] }, 1, 0] },
|
|
93
|
+
},
|
|
94
|
+
medium: {
|
|
95
|
+
$sum: {
|
|
96
|
+
$cond: [
|
|
97
|
+
{
|
|
98
|
+
$and: [
|
|
99
|
+
{ $gte: ["$callLength", shortThreshold] },
|
|
100
|
+
{ $lte: ["$callLength", mediumThreshold] },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
1,
|
|
104
|
+
0,
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
long: {
|
|
109
|
+
$sum: { $cond: [{ $gt: ["$callLength", mediumThreshold] }, 1, 0] },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
function buildHeatmapData(hourlyDataRaw) {
|
|
116
|
+
const heatmapMap = new Map();
|
|
117
|
+
for (const bucket of hourlyDataRaw) {
|
|
118
|
+
const dayKey = bucket._id.day;
|
|
119
|
+
const hour = bucket._id.hour;
|
|
120
|
+
if (!heatmapMap.has(dayKey))
|
|
121
|
+
heatmapMap.set(dayKey, new Map());
|
|
122
|
+
heatmapMap.get(dayKey).set(hour, bucket.count);
|
|
123
|
+
}
|
|
124
|
+
const toSortedBuckets = (map) => Array.from(map.entries())
|
|
125
|
+
.sort(([a], [b]) => a - b)
|
|
126
|
+
.map(([h, c]) => ({
|
|
127
|
+
hour: h,
|
|
128
|
+
calls: c,
|
|
129
|
+
}));
|
|
130
|
+
const heatmap = {};
|
|
131
|
+
for (const [day, hourMap] of Array.from(heatmapMap.entries()).sort()) {
|
|
132
|
+
heatmap[day] = toSortedBuckets(hourMap);
|
|
133
|
+
}
|
|
134
|
+
return heatmap;
|
|
135
|
+
}
|
|
176
136
|
async function getDashboardStats(params) {
|
|
177
|
-
const { clientId, startDate, endDate
|
|
137
|
+
const { clientId, startDate, endDate } = params;
|
|
178
138
|
const clientConfig = await (0, clientsConfig_1.getClientConfig)(clientId);
|
|
179
139
|
const timezone = clientConfig?.timezone ?? "UTC";
|
|
180
|
-
const startDateObj =
|
|
181
|
-
const endDateObj =
|
|
182
|
-
const
|
|
140
|
+
const startDateObj = dayjs_1.default.tz(startDate, timezone).startOf("day").toDate();
|
|
141
|
+
const endDateObj = dayjs_1.default.tz(endDate, timezone).endOf("day").toDate();
|
|
142
|
+
const thresholds = {
|
|
143
|
+
shortThreshold: clientConfig?.callLengthThresholds?.shortThreshold ?? 60,
|
|
144
|
+
mediumThreshold: clientConfig?.callLengthThresholds?.mediumThreshold ?? 180,
|
|
145
|
+
};
|
|
183
146
|
const pipeline = [
|
|
184
147
|
{
|
|
185
148
|
$match: {
|
|
@@ -190,7 +153,9 @@ async function getDashboardStats(params) {
|
|
|
190
153
|
{
|
|
191
154
|
$facet: {
|
|
192
155
|
kpis: buildKpisPipeline(),
|
|
193
|
-
|
|
156
|
+
dailyData: buildDailyDataPipeline(timezone),
|
|
157
|
+
hourlyData: buildHourlyDataPipeline(timezone),
|
|
158
|
+
callLengthBuckets: buildCallLengthBucketsPipeline(thresholds),
|
|
194
159
|
},
|
|
195
160
|
},
|
|
196
161
|
];
|
|
@@ -199,23 +164,43 @@ async function getDashboardStats(params) {
|
|
|
199
164
|
.aggregate(pipeline)
|
|
200
165
|
.toArray();
|
|
201
166
|
const kpiData = aggregatedResult?.kpis?.[0] ?? DEFAULT_KPI_DATA;
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
167
|
+
const dailyDataRaw = aggregatedResult?.dailyData ?? [];
|
|
168
|
+
const hourlyDataRaw = aggregatedResult?.hourlyData ?? [];
|
|
169
|
+
const callLengthRaw = aggregatedResult?.callLengthBuckets?.[0] ?? {
|
|
170
|
+
short: 0,
|
|
171
|
+
medium: 0,
|
|
172
|
+
long: 0,
|
|
173
|
+
};
|
|
205
174
|
const kpis = {
|
|
206
|
-
totalCalls:
|
|
207
|
-
avgDurationSeconds:
|
|
208
|
-
|
|
175
|
+
totalCalls: kpiData.totalCalls,
|
|
176
|
+
avgDurationSeconds: kpiData.totalCalls > 0
|
|
177
|
+
? Math.round((kpiData.totalDuration ?? 0) / kpiData.totalCalls)
|
|
178
|
+
: 0,
|
|
179
|
+
timeSavedMinutes: Math.round((kpiData.totalDuration ?? 0) / 60),
|
|
180
|
+
successRate: kpiData.totalCalls > 0
|
|
181
|
+
? Math.round((kpiData.completedCount / kpiData.totalCalls) * 1000) / 10
|
|
182
|
+
: 0,
|
|
209
183
|
completedCount: kpiData.completedCount,
|
|
184
|
+
failedCount: kpiData.failedCount,
|
|
185
|
+
noAnswerCount: kpiData.noAnswerCount,
|
|
210
186
|
busyCount: kpiData.busyCount,
|
|
211
187
|
};
|
|
212
|
-
const
|
|
213
|
-
|
|
188
|
+
const volumeData = dailyDataRaw.map((d) => ({
|
|
189
|
+
date: d._id,
|
|
190
|
+
count: d.count,
|
|
191
|
+
completed: d.completed,
|
|
192
|
+
}));
|
|
193
|
+
const heatmap = buildHeatmapData(hourlyDataRaw);
|
|
214
194
|
const response = {
|
|
215
195
|
kpis,
|
|
216
196
|
charts: {
|
|
217
197
|
volumeData,
|
|
218
|
-
|
|
198
|
+
heatmap,
|
|
199
|
+
callLengthBuckets: {
|
|
200
|
+
short: callLengthRaw.short,
|
|
201
|
+
medium: callLengthRaw.medium,
|
|
202
|
+
long: callLengthRaw.long,
|
|
203
|
+
},
|
|
219
204
|
},
|
|
220
205
|
};
|
|
221
206
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":";;;;;AA8FA,wEAgCC;AAgCD,8CAoFC;AAlPD,kDAA0B;AAC1B,oDAAsD;AACtD,uDAAsD;AACtD,2DAAmC;AACnC,qEAAmD;AAanD,MAAM,gBAAgB,GAAG;IACvB,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,CAAC;IAChB,cAAc,EAAE,CAAC;IACjB,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,CAAC;CACb,CAAC;AAEF,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAc,CAAC,CAAC;AAE7B,SAAS,iBAAiB;IACxB,OAAO;QACL;YACE,MAAM,EAAE;gBACN,GAAG,EAAE,I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,IAAI;QACJ,MAAM,EAAE;YACN,UAAU;YACV,OAAO;YACP,iBAAiB,EAAE;gBACjB,KAAK,EAAE,aAAa,CAAC,KAAK;gBAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,IAAI,EAAE,aAAa,CAAC,IAAI;aACzB;SACF;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -4,42 +4,63 @@ export type DashboardHeatmapMetric = {
|
|
|
4
4
|
};
|
|
5
5
|
export type DashboardDailyTrendMetric = {
|
|
6
6
|
date: string;
|
|
7
|
+
count: number;
|
|
7
8
|
completed: number;
|
|
8
9
|
};
|
|
9
|
-
export type
|
|
10
|
+
export type DashboardDurationSegments = {
|
|
11
|
+
short: number;
|
|
12
|
+
medium: number;
|
|
13
|
+
long: number;
|
|
14
|
+
};
|
|
10
15
|
export type DashboardSummaryMetrics = {
|
|
11
16
|
totalCalls: number;
|
|
12
17
|
avgDurationSeconds: number;
|
|
13
18
|
timeSavedMinutes: number;
|
|
19
|
+
successRate: number;
|
|
14
20
|
completedCount: number;
|
|
21
|
+
failedCount: number;
|
|
22
|
+
noAnswerCount: number;
|
|
15
23
|
busyCount: number;
|
|
16
24
|
};
|
|
17
25
|
export type DashboardVisualData = {
|
|
18
26
|
volumeData: DashboardDailyTrendMetric[];
|
|
19
|
-
|
|
27
|
+
heatmap: Record<string, DashboardHeatmapMetric[]>;
|
|
28
|
+
callLengthBuckets: DashboardDurationSegments;
|
|
20
29
|
};
|
|
21
30
|
export type DashboardReportQuery = {
|
|
22
31
|
clientId: string;
|
|
23
32
|
startDate: string;
|
|
24
33
|
endDate: string;
|
|
25
|
-
granularity?: DashboardVolumeGranularity;
|
|
26
34
|
};
|
|
27
35
|
export type DashboardReportResponse = {
|
|
28
36
|
kpis: DashboardSummaryMetrics;
|
|
29
37
|
charts: DashboardVisualData;
|
|
30
38
|
};
|
|
31
39
|
type RawKpiResult = {
|
|
40
|
+
totalCalls: number;
|
|
41
|
+
totalDuration: number | null;
|
|
32
42
|
completedCount: number;
|
|
43
|
+
failedCount: number;
|
|
44
|
+
noAnswerCount: number;
|
|
33
45
|
busyCount: number;
|
|
34
|
-
answeredDuration: number | null;
|
|
35
46
|
};
|
|
36
|
-
export type
|
|
47
|
+
export type RawDailyAggregationResult = {
|
|
37
48
|
_id: string;
|
|
49
|
+
count: number;
|
|
38
50
|
completed: number;
|
|
39
51
|
};
|
|
52
|
+
export type RawHourlyAggregationResult = {
|
|
53
|
+
_id: {
|
|
54
|
+
day: string;
|
|
55
|
+
hour: number;
|
|
56
|
+
};
|
|
57
|
+
count: number;
|
|
58
|
+
};
|
|
40
59
|
export interface DashboardAggregationResult {
|
|
41
60
|
kpis: RawKpiResult[];
|
|
42
|
-
|
|
61
|
+
dailyData: RawDailyAggregationResult[];
|
|
62
|
+
hourlyData: RawHourlyAggregationResult[];
|
|
63
|
+
callLengthBuckets: DashboardDurationSegments[];
|
|
43
64
|
}
|
|
44
65
|
export {};
|
|
45
66
|
//# sourceMappingURL=calls.dashboard.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.types.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"calls.dashboard.types.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;A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AM,yBAAyB,GAAG;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,GAAG,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC,UAAU,EAAE,0BAA0B,EAAE,CAAC;IACzC,iBAAiB,EAAE,yBAAyB,EAAE,CAAC;CAChD"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export * from "./calls.constants";
|
|
1
2
|
export * from "./calls.types";
|
|
2
3
|
export * from "./calls.getters";
|
|
4
|
+
export * from "./calls.statistics.types";
|
|
5
|
+
export * from "./calls.statistics.getters";
|
|
3
6
|
export * from "./dashboard/calls.dashboard";
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./calls.constants"), exports);
|
|
17
18
|
__exportStar(require("./calls.types"), exports);
|
|
18
19
|
__exportStar(require("./calls.getters"), exports);
|
|
20
|
+
__exportStar(require("./calls.statistics.types"), exports);
|
|
21
|
+
__exportStar(require("./calls.statistics.getters"), exports);
|
|
19
22
|
__exportStar(require("./dashboard/calls.dashboard"), exports);
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC;AAChC,8DAA4C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,2DAAyC;AACzC,6DAA2C;AAC3C,8DAA4C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared timezone-aware date helpers for statistics aggregations.
|
|
3
|
+
*/
|
|
4
|
+
/** Milliseconds in a single day. */
|
|
5
|
+
export declare const DAY_MS: number;
|
|
6
|
+
/** Maps a short weekday name (as produced by Intl) to its index (Sun = 0). */
|
|
7
|
+
export declare const WEEKDAY: Record<string, number>;
|
|
8
|
+
/** Parses a `YYYY-MM-DD` string into `[year, month, day]` numbers. */
|
|
9
|
+
export declare const parseYmd: (dateStr: string) => [number, number, number];
|
|
10
|
+
/** Builds a zero-padded `YYYY-MM-DD` string from numeric parts. */
|
|
11
|
+
export declare const ymdToStr: (y: number, m: number, d: number) => string;
|
|
12
|
+
/** Parses a `YYYY-MM-DD` string as midnight UTC. */
|
|
13
|
+
export declare const toUtcDate: (dateStr: string) => Date;
|
|
14
|
+
/** Formats a date as a `YYYY-MM-DD` string in UTC. */
|
|
15
|
+
export declare const formatDate: (date: Date) => string;
|
|
16
|
+
/** Adds `days` to a `YYYY-MM-DD` string, returning the resulting `YYYY-MM-DD`. */
|
|
17
|
+
export declare const addDaysToDateStr: (dateStr: string, days: number) => string;
|
|
18
|
+
/** Next civil calendar day (proleptic Gregorian). Avoids DST 24h steps that can stall iteration. */
|
|
19
|
+
export declare const incrementYmd: (y: number, m: number, d: number) => [number, number, number];
|
|
20
|
+
/**
|
|
21
|
+
* Formats a date as the calendar day in the given timezone.
|
|
22
|
+
* `en-CA` yields ISO-8601 `YYYY-MM-DD`, which is lexicographically sortable
|
|
23
|
+
* (string compare == chronological compare) and matches MongoDB's `%Y-%m-%d`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const formatYmdInTz: (date: Date, timezone: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the calendar day in the given timezone as numeric parts.
|
|
28
|
+
* Reads parts by `type` (not string order), so `en-US` is fine here.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getYmdInTz: (date: Date, timezone: string) => {
|
|
31
|
+
y: number;
|
|
32
|
+
m: number;
|
|
33
|
+
d: number;
|
|
34
|
+
};
|
|
35
|
+
/** Weekday index (Sun = 0) of a date in the given timezone. */
|
|
36
|
+
export declare const getWeekdayInTz: (date: Date, timezone: string) => number;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the given `YYYY-MM-DD` day at noon UTC — a stable anchor inside the
|
|
39
|
+
* calendar day, far from midnight so timezone/DST shifts can't cross a date boundary.
|
|
40
|
+
*/
|
|
41
|
+
export declare const dateAtNoonUtc: (dateStr: string) => Date;
|
|
42
|
+
/**
|
|
43
|
+
* UTC instant at the start of the given `YYYY-MM-DD` calendar day in `timezone`.
|
|
44
|
+
* Binary-searches the boundary so it stays correct across DST transitions.
|
|
45
|
+
*/
|
|
46
|
+
export declare const startOfCalendarDayInTz: (dateStr: string, timezone: string) => Date;
|
|
47
|
+
/** UTC instant at the last millisecond of the given calendar day in `timezone`. */
|
|
48
|
+
export declare const endOfCalendarDayInTz: (dateStr: string, timezone: string) => Date;
|
|
49
|
+
//# sourceMappingURL=date.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.utils.d.ts","sourceRoot":"","sources":["../../src/utils/date.utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oCAAoC;AACpC,eAAO,MAAM,MAAM,QAAsB,CAAC;AAE1C,8EAA8E;AAC9E,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQ1C,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAGjE,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MACS,CAAC;AAErE,oDAAoD;AACpD,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,IACN,CAAC;AAEvC,sDAAsD;AACtD,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,MAAyC,CAAC;AAElF,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,KAAG,MACG,CAAC;AAErE,oGAAoG;AACpG,eAAO,MAAM,YAAY,GACvB,GAAG,MAAM,EACT,GAAG,MAAM,EACT,GAAG,MAAM,KACR,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAGzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,IAAI,EAAE,UAAU,MAAM,KAAG,MACU,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,UAAU,MAAM;;;;CAYtD,CAAC;AAEF,+D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