@talkpilot/core-db 1.2.2 → 1.3.0
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/.cursor/rules/development.mdc +65 -65
- package/DEVELOPMENT.md +98 -98
- package/README.md +169 -139
- package/README_OLD.md +160 -160
- 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 +45 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +98 -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 +9 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js +55 -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 +10 -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 +19 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js +375 -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 +3 -3
- 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/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/jest.config.js +19 -19
- package/package.json +46 -46
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +104 -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 +113 -0
- package/src/municipal/tickets/tickets.statistics.getters.ts +93 -0
- package/src/municipal/tickets/tickets.types.ts +14 -9
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +281 -0
- package/src/talkpilot/calls/calls.constants.ts +20 -0
- package/src/talkpilot/calls/calls.statistics.getters.ts +525 -0
- package/src/talkpilot/calls/calls.statistics.types.ts +44 -0
- package/src/talkpilot/calls/calls.types.ts +6 -3
- package/src/talkpilot/calls/index.ts +3 -0
- package/src/utils/date.utils.ts +116 -0
- package/tsconfig.json +23 -23
- package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
- package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.dashboard.js +0 -191
- package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared timezone-aware date helpers for statistics aggregations.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Milliseconds in a single day. */
|
|
6
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
|
|
8
|
+
/** Maps a short weekday name (as produced by Intl) to its index (Sun = 0). */
|
|
9
|
+
export const WEEKDAY: Record<string, number> = {
|
|
10
|
+
Sun: 0,
|
|
11
|
+
Mon: 1,
|
|
12
|
+
Tue: 2,
|
|
13
|
+
Wed: 3,
|
|
14
|
+
Thu: 4,
|
|
15
|
+
Fri: 5,
|
|
16
|
+
Sat: 6,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Parses a `YYYY-MM-DD` string into `[year, month, day]` numbers. */
|
|
20
|
+
export const parseYmd = (dateStr: string): [number, number, number] => {
|
|
21
|
+
const [y, m, d] = dateStr.split("-").map(Number);
|
|
22
|
+
return [y, m, d];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Builds a zero-padded `YYYY-MM-DD` string from numeric parts. */
|
|
26
|
+
export const ymdToStr = (y: number, m: number, d: number): string =>
|
|
27
|
+
`${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
28
|
+
|
|
29
|
+
/** Parses a `YYYY-MM-DD` string as midnight UTC. */
|
|
30
|
+
export const toUtcDate = (dateStr: string): Date =>
|
|
31
|
+
new Date(`${dateStr}T00:00:00.000Z`);
|
|
32
|
+
|
|
33
|
+
/** Formats a date as a `YYYY-MM-DD` string in UTC. */
|
|
34
|
+
export const formatDate = (date: Date): string => date.toISOString().slice(0, 10);
|
|
35
|
+
|
|
36
|
+
/** Adds `days` to a `YYYY-MM-DD` string, returning the resulting `YYYY-MM-DD`. */
|
|
37
|
+
export const addDaysToDateStr = (dateStr: string, days: number): string =>
|
|
38
|
+
formatDate(new Date(toUtcDate(dateStr).getTime() + days * DAY_MS));
|
|
39
|
+
|
|
40
|
+
/** Next civil calendar day (proleptic Gregorian). Avoids DST 24h steps that can stall iteration. */
|
|
41
|
+
export const incrementYmd = (
|
|
42
|
+
y: number,
|
|
43
|
+
m: number,
|
|
44
|
+
d: number,
|
|
45
|
+
): [number, number, number] => {
|
|
46
|
+
const next = new Date(Date.UTC(y, m - 1, d + 1));
|
|
47
|
+
return [next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate()];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Formats a date as the calendar day in the given timezone.
|
|
52
|
+
* `en-CA` yields ISO-8601 `YYYY-MM-DD`, which is lexicographically sortable
|
|
53
|
+
* (string compare == chronological compare) and matches MongoDB's `%Y-%m-%d`.
|
|
54
|
+
*/
|
|
55
|
+
export const formatYmdInTz = (date: Date, timezone: string): string =>
|
|
56
|
+
new Intl.DateTimeFormat("en-CA", { timeZone: timezone }).format(date);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the calendar day in the given timezone as numeric parts.
|
|
60
|
+
* Reads parts by `type` (not string order), so `en-US` is fine here.
|
|
61
|
+
*/
|
|
62
|
+
export const getYmdInTz = (date: Date, timezone: string) => {
|
|
63
|
+
const parts = Object.fromEntries(
|
|
64
|
+
new Intl.DateTimeFormat("en-US", {
|
|
65
|
+
timeZone: timezone,
|
|
66
|
+
year: "numeric",
|
|
67
|
+
month: "numeric",
|
|
68
|
+
day: "numeric",
|
|
69
|
+
})
|
|
70
|
+
.formatToParts(date)
|
|
71
|
+
.map((p) => [p.type, Number(p.value)]),
|
|
72
|
+
);
|
|
73
|
+
return { y: parts.year, m: parts.month, d: parts.day };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Weekday index (Sun = 0) of a date in the given timezone. */
|
|
77
|
+
export const getWeekdayInTz = (date: Date, timezone: string): number =>
|
|
78
|
+
WEEKDAY[
|
|
79
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone, weekday: "short" }).format(
|
|
80
|
+
date,
|
|
81
|
+
)
|
|
82
|
+
] ?? 0;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the given `YYYY-MM-DD` day at noon UTC — a stable anchor inside the
|
|
86
|
+
* calendar day, far from midnight so timezone/DST shifts can't cross a date boundary.
|
|
87
|
+
*/
|
|
88
|
+
export const dateAtNoonUtc = (dateStr: string): Date => {
|
|
89
|
+
const [y, m, d] = parseYmd(dateStr);
|
|
90
|
+
return new Date(Date.UTC(y, m - 1, d, 12, 0, 0));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* UTC instant at the start of the given `YYYY-MM-DD` calendar day in `timezone`.
|
|
95
|
+
* Binary-searches the boundary so it stays correct across DST transitions.
|
|
96
|
+
*/
|
|
97
|
+
export const startOfCalendarDayInTz = (dateStr: string, timezone: string): Date => {
|
|
98
|
+
const anchor = dateAtNoonUtc(dateStr).getTime();
|
|
99
|
+
let low = anchor - 2 * DAY_MS;
|
|
100
|
+
let high = anchor + DAY_MS;
|
|
101
|
+
|
|
102
|
+
while (high - low > 1 /* ms */) {
|
|
103
|
+
const mid = Math.floor((low + high) / 2);
|
|
104
|
+
if (formatYmdInTz(new Date(mid), timezone) >= dateStr) high = mid;
|
|
105
|
+
else low = mid;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return new Date(high);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** UTC instant at the last millisecond of the given calendar day in `timezone`. */
|
|
112
|
+
export const endOfCalendarDayInTz = (dateStr: string, timezone: string): Date => {
|
|
113
|
+
const [y, m, d] = parseYmd(dateStr);
|
|
114
|
+
const nextDay = new Date(Date.UTC(y, m - 1, d + 1)).toISOString().slice(0, 10);
|
|
115
|
+
return new Date(startOfCalendarDayInTz(nextDay, timezone).getTime() - 1);
|
|
116
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"outDir": "dist",
|
|
11
|
-
"rootDir": "src",
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"resolveJsonModule": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true,
|
|
19
|
-
"baseUrl": "."
|
|
20
|
-
},
|
|
21
|
-
"include": ["src/**/*"],
|
|
22
|
-
"exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"emitDecoratorMetadata": true,
|
|
19
|
+
"baseUrl": "."
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*"],
|
|
22
|
+
"exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
|
|
23
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,oBAAoB,EAAE,oBAAoB,EAAiD,MAAM,eAAe,CAAC;AAmGtJ,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAuG/B"}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDashboardStats = getDashboardStats;
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
const calls_getters_1 = require("./calls.getters");
|
|
9
|
-
const clientsConfig_1 = require("../clientsConfig");
|
|
10
|
-
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
11
|
-
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
12
|
-
dayjs_1.default.extend(utc_1.default);
|
|
13
|
-
dayjs_1.default.extend(timezone_1.default);
|
|
14
|
-
function buildKpisPipeline() {
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
$group: {
|
|
18
|
-
_id: null,
|
|
19
|
-
totalCalls: { $sum: 1 },
|
|
20
|
-
totalDuration: { $sum: "$callLength" },
|
|
21
|
-
completedCount: {
|
|
22
|
-
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
23
|
-
},
|
|
24
|
-
failedCount: {
|
|
25
|
-
$sum: { $cond: [{ $eq: ["$status", "failed"] }, 1, 0] },
|
|
26
|
-
},
|
|
27
|
-
noAnswerCount: {
|
|
28
|
-
$sum: { $cond: [{ $eq: ["$status", "no-answer"] }, 1, 0] },
|
|
29
|
-
},
|
|
30
|
-
busyCount: {
|
|
31
|
-
$sum: { $cond: [{ $eq: ["$status", "busy"] }, 1, 0] },
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
function buildDailyDataPipeline(timezone) {
|
|
38
|
-
return [
|
|
39
|
-
{
|
|
40
|
-
$group: {
|
|
41
|
-
_id: {
|
|
42
|
-
$dateToString: {
|
|
43
|
-
format: "%Y-%m-%d",
|
|
44
|
-
date: "$createdAt",
|
|
45
|
-
timezone: timezone,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
count: { $sum: 1 },
|
|
49
|
-
completed: {
|
|
50
|
-
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
{ $sort: { _id: 1 } },
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
function buildHourlyDataPipeline(timezone) {
|
|
58
|
-
return [
|
|
59
|
-
{
|
|
60
|
-
$group: {
|
|
61
|
-
_id: {
|
|
62
|
-
day: {
|
|
63
|
-
$dateToString: {
|
|
64
|
-
format: "%Y-%m-%d",
|
|
65
|
-
date: "$createdAt",
|
|
66
|
-
timezone: timezone,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
hour: { $hour: { date: "$createdAt", timezone: timezone } },
|
|
70
|
-
},
|
|
71
|
-
count: { $sum: 1 },
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
function buildCallLengthBucketsPipeline() {
|
|
77
|
-
return [
|
|
78
|
-
{
|
|
79
|
-
$group: {
|
|
80
|
-
_id: null,
|
|
81
|
-
short: { $sum: { $cond: [{ $lt: ["$callLength", 60] }, 1, 0] } },
|
|
82
|
-
medium: {
|
|
83
|
-
$sum: {
|
|
84
|
-
$cond: [
|
|
85
|
-
{
|
|
86
|
-
$and: [
|
|
87
|
-
{ $gte: ["$callLength", 60] },
|
|
88
|
-
{ $lte: ["$callLength", 180] },
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
1,
|
|
92
|
-
0,
|
|
93
|
-
],
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
long: { $sum: { $cond: [{ $gt: ["$callLength", 180] }, 1, 0] } },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
];
|
|
100
|
-
}
|
|
101
|
-
async function getDashboardStats(params) {
|
|
102
|
-
const { clientId, startDate, endDate } = params;
|
|
103
|
-
const clientConfig = await (0, clientsConfig_1.getClientConfig)(clientId);
|
|
104
|
-
const timezone = clientConfig?.timezone ?? "UTC";
|
|
105
|
-
const startDateObj = dayjs_1.default.tz(startDate, timezone).startOf("day").toDate();
|
|
106
|
-
const endDateObj = dayjs_1.default.tz(endDate, timezone).endOf("day").toDate();
|
|
107
|
-
const pipeline = [
|
|
108
|
-
{
|
|
109
|
-
$match: {
|
|
110
|
-
clientId,
|
|
111
|
-
createdAt: { $gte: startDateObj, $lte: endDateObj },
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
$facet: {
|
|
116
|
-
kpis: buildKpisPipeline(),
|
|
117
|
-
dailyData: buildDailyDataPipeline(timezone),
|
|
118
|
-
hourlyData: buildHourlyDataPipeline(timezone),
|
|
119
|
-
callLengthBuckets: buildCallLengthBucketsPipeline(),
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
];
|
|
123
|
-
const callsCollection = (0, calls_getters_1.getCallsCollection)();
|
|
124
|
-
const [aggregatedResult] = await callsCollection
|
|
125
|
-
.aggregate(pipeline)
|
|
126
|
-
.toArray();
|
|
127
|
-
const kpiData = aggregatedResult?.kpis?.[0] ?? {
|
|
128
|
-
totalCalls: 0,
|
|
129
|
-
totalDuration: 0,
|
|
130
|
-
completedCount: 0,
|
|
131
|
-
failedCount: 0,
|
|
132
|
-
noAnswerCount: 0,
|
|
133
|
-
busyCount: 0,
|
|
134
|
-
};
|
|
135
|
-
const dailyDataRaw = aggregatedResult?.dailyData ?? [];
|
|
136
|
-
const hourlyDataRaw = aggregatedResult?.hourlyData ?? [];
|
|
137
|
-
const callLengthRaw = aggregatedResult?.callLengthBuckets?.[0] ?? {
|
|
138
|
-
short: 0,
|
|
139
|
-
medium: 0,
|
|
140
|
-
long: 0,
|
|
141
|
-
};
|
|
142
|
-
const count = kpiData.totalCalls;
|
|
143
|
-
const totalLen = kpiData.totalDuration;
|
|
144
|
-
const completed = kpiData.completedCount;
|
|
145
|
-
const kpis = {
|
|
146
|
-
totalCalls: count,
|
|
147
|
-
avgDurationSeconds: count > 0 ? Math.round(totalLen / count) : 0,
|
|
148
|
-
timeSavedMinutes: Math.round(totalLen / 60),
|
|
149
|
-
successRate: count > 0 ? Math.round((completed / count) * 1000) / 10 : 0,
|
|
150
|
-
completedCount: completed,
|
|
151
|
-
failedCount: kpiData.failedCount,
|
|
152
|
-
noAnswerCount: kpiData.noAnswerCount,
|
|
153
|
-
busyCount: kpiData.busyCount,
|
|
154
|
-
};
|
|
155
|
-
const volumeData = dailyDataRaw.map((d) => ({
|
|
156
|
-
date: d._id,
|
|
157
|
-
count: d.count,
|
|
158
|
-
completed: d.completed,
|
|
159
|
-
}));
|
|
160
|
-
const heatmapMap = new Map();
|
|
161
|
-
for (const bucket of hourlyDataRaw) {
|
|
162
|
-
const dayKey = bucket._id.day;
|
|
163
|
-
const hour = bucket._id.hour;
|
|
164
|
-
if (!heatmapMap.has(dayKey))
|
|
165
|
-
heatmapMap.set(dayKey, new Map());
|
|
166
|
-
heatmapMap.get(dayKey).set(hour, bucket.count);
|
|
167
|
-
}
|
|
168
|
-
const toSortedBuckets = (map) => Array.from(map.entries())
|
|
169
|
-
.sort(([a], [b]) => a - b)
|
|
170
|
-
.map(([h, c]) => ({
|
|
171
|
-
hour: `${String(h).padStart(2, "0")}:00`,
|
|
172
|
-
calls: c,
|
|
173
|
-
}));
|
|
174
|
-
const heatmap = {};
|
|
175
|
-
for (const [day, hourMap] of Array.from(heatmapMap.entries()).sort()) {
|
|
176
|
-
heatmap[day] = toSortedBuckets(hourMap);
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
kpis,
|
|
180
|
-
charts: {
|
|
181
|
-
volumeData,
|
|
182
|
-
heatmap,
|
|
183
|
-
callLengthBuckets: {
|
|
184
|
-
short: callLengthRaw.short,
|
|
185
|
-
medium: callLengthRaw.medium,
|
|
186
|
-
long: callLengthRaw.long,
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
//# sourceMappingURL=calls.dashboard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.dashboard.ts"],"names":[],"mappings":";;;;;AAqGA,8CAyGC;AA9MD,kDAA0B;AAC1B,mDAAqD;AAErD,oDAAmD;AACnD,2DAAmC;AACnC,qEAAmD;AAEnD,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAc,CAAC,CAAC;AAC7B,SAAS,iBAAiB;IACxB,OAAO;QACL;YACE,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI;gBACT,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;gBACvB,aAAa,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;gBACtC,cAAc,EAAE;oBACd,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;iBAC3D;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,EAA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