Skip to content

Commit

Permalink
feat: add times in overviews report
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMaruchu committed Sep 12, 2019
1 parent 6c69bef commit 29ba176
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/base/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export const TIME_FACET = {
maximumResolveTime: { $max: '$resolveTime' },
minimumResolveTime: { $min: '$resolveTime' },
averageResolveTime: { $avg: '$resolveTime' },
maximumLateTime: { $max: '$lateTime' },
minimumLateTime: { $min: '$lateTime' },
averageLateTime: { $avg: '$lateTime' },
maximumConfirmTime: { $max: '$confirmTime' },
minimumConfirmTime: { $min: '$confirmTime' },
averageConfirmTime: { $avg: '$confirmTime' },
},
},
],
Expand Down
13 changes: 12 additions & 1 deletion src/base/servicerequest.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,20 @@ const getBaseAggregation = criteria => {
},
})
.addFields({
/**
* Time difference between when service request was reported and when it was
* confirmed by an operator or responsible party.
*
* This metric calculate how much time does it take for an organization
* to confirm/respond to issues which have been reported via channels
* which doesn't involve operator intervention. i.e USSD, Mobile App, Bot
* and e.t.c
*/
confirmTime: { $subtract: ['$confirmedAt', '$createdAt'] },

/**
* Time difference between expected time to resolve the service request
* and today.
* and current date if not resolved or resolvedAt if resolved pass it SLA.
*
* This time will indicate if the service request is late or not base on
* the SLA(Service Level Agreement) time set per service request nature
Expand Down
2 changes: 2 additions & 0 deletions src/reports/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import getBaseAggregation from '../base/servicerequest.base';
import {
OVERALL_FACET,
TIME_FACET,
JURISDICTION_FACET,
STATUS_FACET,
PRIORITY_FACET,
Expand All @@ -36,6 +37,7 @@ import {

const OVERVIEW_FACET = {
...OVERALL_FACET,
...TIME_FACET,
...JURISDICTION_FACET,
...STATUS_FACET,
...PRIORITY_FACET,
Expand Down
31 changes: 29 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { head, map, isNumber } from 'lodash';
import { head, map, merge, isNumber, upperFirst } from 'lodash';
import parseMs from 'parse-ms';

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ export const normalizeObjectTimes = item => {
* @param {object} results Aggregation results
* @returns {object} Normalized response object
*
* @version 0.1.0
* @version 0.2.0
* @since 0.2.0
*/
export const prepareReportResponse = results => {
Expand All @@ -64,10 +64,37 @@ export const prepareReportResponse = results => {

data.overall = head(data.overall);

data.time = head(data.time);

if (data.overall) {
data.overall = normalizeObjectTimes(data.overall);
}

if (data.time) {
// const times = {};

const keys = [
'confirmTime',
'assignTime',
'attendTime',
'completeTime',
'verifyTime',
'approveTime',
'resolveTime',
'lateTime',
];

const times = map(keys, key => ({
[key]: {
minimum: normalizeTime(data.time[`minimum${upperFirst(key)}`]),
maximum: normalizeTime(data.time[`maximum${upperFirst(key)}`]),
average: normalizeTime(data.time[`average${upperFirst(key)}`]),
},
}));

data.overall = merge({}, data.overall, ...times);
}

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

0 comments on commit 29ba176

Please sign in to comment.