diff --git a/es/index.js b/es/index.js index 880a755..97a76f2 100644 --- a/es/index.js +++ b/es/index.js @@ -312,7 +312,7 @@ const getBaseAggregation = criteria => { }; /* constants */ -const times = { +const METRIC_TIMES = { maximumAssignTime: { $max: '$assignTime' }, minimumAssignTime: { $min: '$assignTime' }, averageAssignTime: { $avg: '$assignTime' }, @@ -337,13 +337,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 */ const OVERALL_FACET = { @@ -358,9 +361,7 @@ const OVERALL_FACET = { }, late: { $sum: '$late' }, count: { $sum: 1 }, - averageResolveTime: { $avg: '$ttr.milliseconds' }, - averageAttendTime: { $avg: '$call.duration.milliseconds' }, - ...times, + ...METRIC_TIMES, }, }, { @@ -375,7 +376,7 @@ 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 */ const JURISDICTION_FACET = { @@ -392,24 +393,7 @@ 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, }, }, { @@ -440,17 +424,6 @@ const STATUS_FACET = { resolved: { $sum: '$resolved' }, }, }, - { - $project: { - _id: 1, - name: 1, - weight: 1, - color: 1, - count: 1, - pending: 1, - resolved: 1, - }, - }, { $sort: { weight: 1 } }, ], }; @@ -459,7 +432,7 @@ 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 */ const PRIORITY_FACET = { @@ -474,22 +447,7 @@ 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, }, }, { @@ -502,7 +460,7 @@ 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 */ const SERVICE_FACET = { @@ -517,22 +475,7 @@ 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, }, }, { @@ -545,7 +488,7 @@ 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 */ const SERVICE_GROUP_FACET = { @@ -560,22 +503,7 @@ 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, }, }, { @@ -588,7 +516,7 @@ 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 */ const SERVICE_TYPE_FACET = { @@ -606,25 +534,12 @@ 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, }, }, ], @@ -666,7 +581,7 @@ 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 */ const REPORTING_METHOD_FACET = { @@ -677,8 +592,6 @@ const REPORTING_METHOD_FACET = { count: { $sum: 1 }, pending: { $sum: '$pending' }, resolved: { $sum: '$resolved' }, - averageResolveTime: { $avg: '$ttr.milliseconds' }, - averageAttendTime: { $avg: '$call.duration.milliseconds' }, }, }, { @@ -687,8 +600,6 @@ const REPORTING_METHOD_FACET = { count: 1, pending: 1, resolved: 1, - averageResolveTime: 1, - averageAttendTime: 1, }, }, { $sort: { count: -1 } }, @@ -943,6 +854,7 @@ const normalizeMetricTimes = data => { 'approveTime', 'resolveTime', 'lateTime', + 'callTime', ]; const times = map(keys, key => ({ @@ -978,6 +890,9 @@ const normalizeMetricTimes = data => { 'maximumConfirmTime', 'minimumConfirmTime', 'averageConfirmTime', + 'maximumCallTime', + 'minimumCallTime', + 'averageCallTime', ]); return merge({}, strippedObject, ...times); @@ -1008,19 +923,19 @@ 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) { @@ -1151,7 +1066,7 @@ router.get(PATH_OPERATOR_PERFORMANCE, (request, response, next) => { * @author Benson Maruchu * @author lally elias * @since 0.1.0 - * @version 0.1.0 + * @version 0.2.0 * @license MIT * @example * @@ -1178,4 +1093,4 @@ const info = pkg( // extract api version const apiVersion = router.version; -export { apiVersion, info, router }; +export { router as analyticRouter, apiVersion, info }; diff --git a/lib/index.js b/lib/index.js index e6b5ef0..c025422 100644 --- a/lib/index.js +++ b/lib/index.js @@ -314,7 +314,7 @@ const getBaseAggregation = criteria => { }; /* constants */ -const times = { +const METRIC_TIMES = { maximumAssignTime: { $max: '$assignTime' }, minimumAssignTime: { $min: '$assignTime' }, averageAssignTime: { $avg: '$assignTime' }, @@ -339,13 +339,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 */ const OVERALL_FACET = { @@ -360,9 +363,7 @@ const OVERALL_FACET = { }, late: { $sum: '$late' }, count: { $sum: 1 }, - averageResolveTime: { $avg: '$ttr.milliseconds' }, - averageAttendTime: { $avg: '$call.duration.milliseconds' }, - ...times, + ...METRIC_TIMES, }, }, { @@ -377,7 +378,7 @@ 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 */ const JURISDICTION_FACET = { @@ -394,24 +395,7 @@ 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, }, }, { @@ -442,17 +426,6 @@ const STATUS_FACET = { resolved: { $sum: '$resolved' }, }, }, - { - $project: { - _id: 1, - name: 1, - weight: 1, - color: 1, - count: 1, - pending: 1, - resolved: 1, - }, - }, { $sort: { weight: 1 } }, ], }; @@ -461,7 +434,7 @@ 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 */ const PRIORITY_FACET = { @@ -476,22 +449,7 @@ 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, }, }, { @@ -504,7 +462,7 @@ 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 */ const SERVICE_FACET = { @@ -519,22 +477,7 @@ 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, }, }, { @@ -547,7 +490,7 @@ 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 */ const SERVICE_GROUP_FACET = { @@ -562,22 +505,7 @@ 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, }, }, { @@ -590,7 +518,7 @@ 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 */ const SERVICE_TYPE_FACET = { @@ -608,25 +536,12 @@ 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, }, }, ], @@ -668,7 +583,7 @@ 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 */ const REPORTING_METHOD_FACET = { @@ -679,8 +594,6 @@ const REPORTING_METHOD_FACET = { count: { $sum: 1 }, pending: { $sum: '$pending' }, resolved: { $sum: '$resolved' }, - averageResolveTime: { $avg: '$ttr.milliseconds' }, - averageAttendTime: { $avg: '$call.duration.milliseconds' }, }, }, { @@ -689,8 +602,6 @@ const REPORTING_METHOD_FACET = { count: 1, pending: 1, resolved: 1, - averageResolveTime: 1, - averageAttendTime: 1, }, }, { $sort: { count: -1 } }, @@ -945,6 +856,7 @@ const normalizeMetricTimes = data => { 'approveTime', 'resolveTime', 'lateTime', + 'callTime', ]; const times = lodash.map(keys, key => ({ @@ -980,6 +892,9 @@ const normalizeMetricTimes = data => { 'maximumConfirmTime', 'minimumConfirmTime', 'averageConfirmTime', + 'maximumCallTime', + 'minimumCallTime', + 'averageCallTime', ]); return lodash.merge({}, strippedObject, ...times); @@ -1010,19 +925,19 @@ const prepareReportResponse = results => { } if (data.jurisdictions) { - data.jurisdictions = lodash.map(data.jurisdictions, normalizeObjectTimes); + data.jurisdictions = lodash.map(data.jurisdictions, normalizeMetricTimes); } if (data.priorities) { - data.priorities = lodash.map(data.priorities, normalizeObjectTimes); + data.priorities = lodash.map(data.priorities, normalizeMetricTimes); } if (data.services) { - data.services = lodash.map(data.services, normalizeObjectTimes); + data.services = lodash.map(data.services, normalizeMetricTimes); } if (data.groups) { - data.groups = lodash.map(data.groups, normalizeObjectTimes); + data.groups = lodash.map(data.groups, normalizeMetricTimes); } if (data.types) { @@ -1153,7 +1068,7 @@ router.get(PATH_OPERATOR_PERFORMANCE, (request, response, next) => { * @author Benson Maruchu * @author lally elias * @since 0.1.0 - * @version 0.1.0 + * @version 0.2.0 * @license MIT * @example * @@ -1180,6 +1095,6 @@ const info = common.pkg( // extract api version const apiVersion = router.version; +exports.analyticRouter = router; exports.apiVersion = apiVersion; exports.info = info; -exports.router = router;