Skip to content

Commit

Permalink
feat: add metric times for overview facets
Browse files Browse the repository at this point in the history
This add metrics times for jurisdictions, priority, group, service
types and service facets
  • Loading branch information
BenMaruchu committed Sep 13, 2019
1 parent ce1e7f8 commit 4e33ac6
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 147 deletions.
127 changes: 19 additions & 108 deletions src/base/facets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* constants */
const times = {
const METRIC_TIMES = {
maximumAssignTime: { $max: '$assignTime' },
minimumAssignTime: { $min: '$assignTime' },
averageAssignTime: { $avg: '$assignTime' },
Expand All @@ -24,13 +24,16 @@ const times = {
maximumConfirmTime: { $max: '$confirmTime' },
minimumConfirmTime: { $min: '$confirmTime' },
averageConfirmTime: { $avg: '$confirmTime' },
maximumCallTime: { $max: '$call.duration.milliseconds' },
minimumCallTime: { $min: '$call.duration.milliseconds' },
averageCallTime: { $avg: '$call.duration.milliseconds' },
};

/**
* @namespace OVERALL_FACET
* @description Facet for service requests overall general breakdown
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const OVERALL_FACET = {
Expand All @@ -45,9 +48,7 @@ export const OVERALL_FACET = {
},
late: { $sum: '$late' },
count: { $sum: 1 },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
...times,
...METRIC_TIMES,
},
},
{
Expand All @@ -62,7 +63,7 @@ export const OVERALL_FACET = {
* @namespace PRIORITY_FACET
* @description Facet for service requests breakdown based on their priorities
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const JURISDICTION_FACET = {
Expand All @@ -79,24 +80,7 @@ export const JURISDICTION_FACET = {
phone: { $first: '$jurisdiction.phone' },
color: { $first: '$jurisdiction.color' },
count: { $sum: 1 },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
},
},
{
$project: {
_id: 1,
pending: 1,
resolved: 1,
late: 1,
unattended: 1,
name: 1,
email: 1,
phone: 1,
color: 1,
count: 1,
averageResolveTime: 1,
averageAttendTime: 1,
...METRIC_TIMES,
},
},
{
Expand Down Expand Up @@ -127,17 +111,6 @@ export const STATUS_FACET = {
resolved: { $sum: '$resolved' },
},
},
{
$project: {
_id: 1,
name: 1,
weight: 1,
color: 1,
count: 1,
pending: 1,
resolved: 1,
},
},
{ $sort: { weight: 1 } },
],
};
Expand All @@ -146,7 +119,7 @@ export const STATUS_FACET = {
* @namespace PRIORITY_FACET
* @description Facet for service requests breakdown based on their priorities
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const PRIORITY_FACET = {
Expand All @@ -161,22 +134,7 @@ export const PRIORITY_FACET = {
pending: { $sum: '$pending' },
resolved: { $sum: '$resolved' },
unattended: { $sum: '$unattended' },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
},
},
{
$project: {
_id: 1,
name: 1,
color: 1,
weight: 1,
count: 1,
pending: 1,
resolved: 1,
unattended: 1,
averageResolveTime: 1,
averageAttendTime: 1,
...METRIC_TIMES,
},
},
{
Expand All @@ -189,7 +147,7 @@ export const PRIORITY_FACET = {
* @namespace SERVICE_FACET
* @description Facet for service requests breakdown based on their services(nature)
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const SERVICE_FACET = {
Expand All @@ -204,22 +162,7 @@ export const SERVICE_FACET = {
name: { $first: '$service.name' },
color: { $first: '$service.color' },
count: { $sum: 1 },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
},
},
{
$project: {
_id: 1,
pending: 1,
resolved: 1,
late: 1,
unattended: 1,
name: 1,
color: 1,
count: 1,
averageResolveTime: 1,
averageAttendTime: 1,
...METRIC_TIMES,
},
},
{
Expand All @@ -232,7 +175,7 @@ export const SERVICE_FACET = {
* @namespace SERVICE_GROUP_FACET
* @description Facet for service requests breakdown based on their service groups
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const SERVICE_GROUP_FACET = {
Expand All @@ -247,22 +190,7 @@ export const SERVICE_GROUP_FACET = {
name: { $first: '$group.name.en' },
color: { $first: '$group.color' },
count: { $sum: 1 },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
},
},
{
$project: {
_id: 1,
pending: 1,
resolved: 1,
late: 1,
unattended: 1,
name: 1,
color: 1,
count: 1,
averageResolveTime: 1,
averageAttendTime: 1,
...METRIC_TIMES,
},
},
{
Expand All @@ -275,7 +203,7 @@ export const SERVICE_GROUP_FACET = {
* @namespace SERVICE_TYPE_FACET
* @description Facet for service requests breakdown based on their service types
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const SERVICE_TYPE_FACET = {
Expand All @@ -293,25 +221,12 @@ export const SERVICE_TYPE_FACET = {
resolved: { $sum: '$resolved' },
unattended: { $sum: '$unattended' },
late: { $sum: '$late' },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
...METRIC_TIMES,
},
},
{
$project: {
_id: 1,
name: 1,
color: 1,
code: 1,
description: 1,
abbreviation: 1,
count: 1,
pending: 1,
resolved: 1,
unattended: 1,
late: 1,
averageAttendTime: 1,
averageResolveTime: 1,
$sort: {
count: -1,
},
},
],
Expand Down Expand Up @@ -353,7 +268,7 @@ export const WORKSPACE_FACET = {
* @description Facet for service requests breakdown based on their reporting
* methods
*
* @version 0.1.0
* @version 0.2.0
* @since 0.1.0
*/
export const REPORTING_METHOD_FACET = {
Expand All @@ -364,8 +279,6 @@ export const REPORTING_METHOD_FACET = {
count: { $sum: 1 },
pending: { $sum: '$pending' },
resolved: { $sum: '$resolved' },
averageResolveTime: { $avg: '$ttr.milliseconds' },
averageAttendTime: { $avg: '$call.duration.milliseconds' },
},
},
{
Expand All @@ -374,8 +287,6 @@ export const REPORTING_METHOD_FACET = {
count: 1,
pending: 1,
resolved: 1,
averageResolveTime: 1,
averageAttendTime: 1,
},
},
{ $sort: { count: -1 } },
Expand Down
12 changes: 8 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const normalizeMetricTimes = data => {
'approveTime',
'resolveTime',
'lateTime',
'callTime',
];

const times = map(keys, key => ({
Expand Down Expand Up @@ -103,6 +104,9 @@ export const normalizeMetricTimes = data => {
'maximumConfirmTime',
'minimumConfirmTime',
'averageConfirmTime',
'maximumCallTime',
'minimumCallTime',
'averageCallTime',
]);

return merge({}, strippedObject, ...times);
Expand Down Expand Up @@ -133,19 +137,19 @@ export const prepareReportResponse = results => {
}

if (data.jurisdictions) {
data.jurisdictions = map(data.jurisdictions, normalizeObjectTimes);
data.jurisdictions = map(data.jurisdictions, normalizeMetricTimes);
}

if (data.priorities) {
data.priorities = map(data.priorities, normalizeObjectTimes);
data.priorities = map(data.priorities, normalizeMetricTimes);
}

if (data.services) {
data.services = map(data.services, normalizeObjectTimes);
data.services = map(data.services, normalizeMetricTimes);
}

if (data.groups) {
data.groups = map(data.groups, normalizeObjectTimes);
data.groups = map(data.groups, normalizeMetricTimes);
}

if (data.types) {
Expand Down
Loading

0 comments on commit 4e33ac6

Please sign in to comment.