add more analytics
This commit is contained in:
@@ -206,10 +206,24 @@ async function getApprovalMetrics() {
|
|||||||
(item) => item.accelaStatus === "APPROVED"
|
(item) => item.accelaStatus === "APPROVED"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const issuedCountByClient = {};
|
||||||
|
const issuedCountByCounty = {};
|
||||||
|
|
||||||
const approvalDurationClient = {};
|
const approvalDurationClient = {};
|
||||||
const approvalDurationCounty = {};
|
const approvalDurationCounty = {};
|
||||||
|
|
||||||
|
const approvalDurationByPermitTypeClient = {};
|
||||||
|
const approvalDurationByPermitTypeCounty = {};
|
||||||
|
|
||||||
for (const permit of approvedPermits) {
|
for (const permit of approvedPermits) {
|
||||||
|
if (!issuedCountByClient[permit.clientData?.name])
|
||||||
|
issuedCountByClient[permit.clientData?.name] = 0;
|
||||||
|
issuedCountByClient[permit.clientData?.name]++;
|
||||||
|
|
||||||
|
if (!issuedCountByCounty[permit.county?.name])
|
||||||
|
issuedCountByCounty[permit.county?.name] = 0;
|
||||||
|
issuedCountByCounty[permit.county?.name]++;
|
||||||
|
|
||||||
const diff = dateDiff(permit.issuedDate, permit.openDate);
|
const diff = dateDiff(permit.issuedDate, permit.openDate);
|
||||||
|
|
||||||
if (!approvalDurationClient[permit.clientData?.name])
|
if (!approvalDurationClient[permit.clientData?.name])
|
||||||
@@ -219,6 +233,38 @@ async function getApprovalMetrics() {
|
|||||||
if (!approvalDurationCounty[permit.county?.name])
|
if (!approvalDurationCounty[permit.county?.name])
|
||||||
approvalDurationCounty[permit.county?.name] = [];
|
approvalDurationCounty[permit.county?.name] = [];
|
||||||
approvalDurationCounty[permit.county?.name]?.push(diff);
|
approvalDurationCounty[permit.county?.name]?.push(diff);
|
||||||
|
|
||||||
|
if (!approvalDurationByPermitTypeClient[permit.clientData?.name])
|
||||||
|
approvalDurationByPermitTypeClient[permit.clientData?.name] = {};
|
||||||
|
|
||||||
|
if (
|
||||||
|
!approvalDurationByPermitTypeClient[permit.clientData?.name][
|
||||||
|
permit.recordType
|
||||||
|
]
|
||||||
|
)
|
||||||
|
approvalDurationByPermitTypeClient[permit.clientData?.name][
|
||||||
|
permit.recordType
|
||||||
|
] = [];
|
||||||
|
|
||||||
|
approvalDurationByPermitTypeClient[permit.clientData?.name][
|
||||||
|
permit.recordType
|
||||||
|
]?.push(diff);
|
||||||
|
|
||||||
|
if (!approvalDurationByPermitTypeCounty[permit.county?.name])
|
||||||
|
approvalDurationByPermitTypeCounty[permit.county?.name] = {};
|
||||||
|
|
||||||
|
if (
|
||||||
|
!approvalDurationByPermitTypeCounty[permit.county?.name][
|
||||||
|
permit.recordType
|
||||||
|
]
|
||||||
|
)
|
||||||
|
approvalDurationByPermitTypeCounty[permit.county?.name][
|
||||||
|
permit.recordType
|
||||||
|
] = [];
|
||||||
|
|
||||||
|
approvalDurationByPermitTypeCounty[permit.county?.name][
|
||||||
|
permit.recordType
|
||||||
|
]?.push(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const client in approvalDurationClient) {
|
for (const client in approvalDurationClient) {
|
||||||
@@ -233,17 +279,37 @@ async function getApprovalMetrics() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const client in approvalDurationByPermitTypeClient) {
|
||||||
|
for (const type in approvalDurationByPermitTypeClient[client]) {
|
||||||
|
approvalDurationByPermitTypeClient[client][type] = calculateAverages(
|
||||||
|
approvalDurationByPermitTypeClient[client][type]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const county in approvalDurationByPermitTypeCounty) {
|
||||||
|
for (const type in approvalDurationByPermitTypeCounty[county]) {
|
||||||
|
approvalDurationByPermitTypeCounty[county][type] = calculateAverages(
|
||||||
|
approvalDurationByPermitTypeCounty[county][type]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalApproved: approvedPermits.length,
|
totalApproved: approvedPermits.length,
|
||||||
|
issuedCountByClient,
|
||||||
|
issuedCountByCounty,
|
||||||
approvalDurationClient,
|
approvalDurationClient,
|
||||||
approvalDurationCounty,
|
approvalDurationCounty,
|
||||||
|
approvalDurationByPermitTypeClient,
|
||||||
|
approvalDurationByPermitTypeCounty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await mongoose.connect(process.env.DB_URI);
|
await mongoose.connect(process.env.DB_URI);
|
||||||
|
|
||||||
const startDate = new Date(Date.now() - 3600 * 24 * 30 * 1000);
|
const startDate = new Date(Date.now() - 3600 * 24 * 500 * 1000);
|
||||||
const endDate = new Date();
|
const endDate = new Date();
|
||||||
|
|
||||||
const recentPermits = await permitModel
|
const recentPermits = await permitModel
|
||||||
@@ -251,7 +317,7 @@ async function getApprovalMetrics() {
|
|||||||
openDate: { $gte: startDate, $lte: endDate },
|
openDate: { $gte: startDate, $lte: endDate },
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
"clientData county openDate issuedDate accelaStatus status manualStatus cleanStatus"
|
"clientData county openDate issuedDate accelaStatus status manualStatus cleanStatus recordType"
|
||||||
);
|
);
|
||||||
|
|
||||||
const recentProcessed = await processedModel
|
const recentProcessed = await processedModel
|
||||||
@@ -259,7 +325,7 @@ async function getApprovalMetrics() {
|
|||||||
openDate: { $gte: startDate, $lte: endDate },
|
openDate: { $gte: startDate, $lte: endDate },
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
"clientData county openDate issuedDate accelaStatus status manualStatus cleanStatus"
|
"clientData county openDate issuedDate accelaStatus status manualStatus cleanStatus recordType"
|
||||||
);
|
);
|
||||||
|
|
||||||
combinedPermits = [...recentPermits, ...recentProcessed];
|
combinedPermits = [...recentPermits, ...recentProcessed];
|
||||||
|
|||||||
Reference in New Issue
Block a user