Skip to content

Commit

Permalink
chore(build): bundle library for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMaruchu committed Sep 13, 2019
1 parent eecd42f commit c9fcafe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 228 deletions.
143 changes: 29 additions & 114 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const getBaseAggregation = criteria => {
};

/* constants */
const times = {
const METRIC_TIMES = {
maximumAssignTime: { $max: '$assignTime' },
minimumAssignTime: { $min: '$assignTime' },
averageAssignTime: { $avg: '$assignTime' },
Expand All @@ -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 = {
Expand All @@ -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,
},
},
{
Expand All @@ -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 = {
Expand All @@ -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,
},
},
{
Expand Down Expand Up @@ -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 } },
],
};
Expand All @@ -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 = {
Expand All @@ -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,
},
},
{
Expand All @@ -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 = {
Expand All @@ -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,
},
},
{
Expand All @@ -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 = {
Expand All @@ -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,
},
},
{
Expand All @@ -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 = {
Expand All @@ -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,
},
},
],
Expand Down Expand Up @@ -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 = {
Expand All @@ -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' },
},
},
{
Expand All @@ -687,8 +600,6 @@ const REPORTING_METHOD_FACET = {
count: 1,
pending: 1,
resolved: 1,
averageResolveTime: 1,
averageAttendTime: 1,
},
},
{ $sort: { count: -1 } },
Expand Down Expand Up @@ -943,6 +854,7 @@ const normalizeMetricTimes = data => {
'approveTime',
'resolveTime',
'lateTime',
'callTime',
];

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

return merge({}, strippedObject, ...times);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1151,7 +1066,7 @@ router.get(PATH_OPERATOR_PERFORMANCE, (request, response, next) => {
* @author Benson Maruchu <[email protected]>
* @author lally elias <[email protected]>
* @since 0.1.0
* @version 0.1.0
* @version 0.2.0
* @license MIT
* @example
*
Expand All @@ -1178,4 +1093,4 @@ const info = pkg(
// extract api version
const apiVersion = router.version;

export { apiVersion, info, router };
export { router as analyticRouter, apiVersion, info };
Loading

0 comments on commit c9fcafe

Please sign in to comment.