generated from lykmapipo/iso-lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
262 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,6 +342,21 @@ const METRIC_TIMES = { | |
averageCallTime: { $avg: '$call.duration.milliseconds' }, | ||
}; | ||
|
||
const METRIC_COUNTS = { | ||
approved: { $sum: '$approved' }, | ||
assigned: { $sum: 'assigned' }, | ||
attended: { $sum: '$attended' }, | ||
completed: { $sum: '$completed' }, | ||
count: { $sum: 1 }, | ||
late: { $sum: '$late' }, | ||
new: { $sum: '$new' }, | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
reopened: { $sum: '$reopened' }, | ||
unconfirmed: { $sum: '$unconfirmed' }, | ||
verified: { $sum: '$verified' }, | ||
}; | ||
|
||
/** | ||
* @namespace OVERALL_FACET | ||
* @description Facet for service requests overall general breakdown | ||
|
@@ -354,13 +369,7 @@ const OVERALL_FACET = { | |
{ | ||
$group: { | ||
_id: null, | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
unconfirmed: { | ||
$sum: '$unconfirmed', | ||
}, | ||
late: { $sum: '$late' }, | ||
count: { $sum: 1 }, | ||
...METRIC_COUNTS, | ||
...METRIC_TIMES, | ||
}, | ||
}, | ||
|
@@ -468,13 +477,9 @@ const SERVICE_FACET = { | |
{ | ||
$group: { | ||
_id: '$service._id', | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
late: { $sum: '$late' }, | ||
unconfirmed: { $sum: '$unconfirmed' }, | ||
name: { $first: '$service.name' }, | ||
color: { $first: '$service.color' }, | ||
count: { $sum: 1 }, | ||
...METRIC_COUNTS, | ||
...METRIC_TIMES, | ||
}, | ||
}, | ||
|
@@ -787,6 +792,53 @@ const getOperatorPerformanceReport = (criteria, onResults) => { | |
return baseAggregation.facet(OPERATOR_PERFORMANCE_FACET).exec(onResults); | ||
}; | ||
|
||
/** | ||
* This is operational report based on service request | ||
* It consist of | ||
* - Total service requests per a given period | ||
* - Pending service requests | ||
* - Resolved service requests | ||
* - Assigned service requests | ||
* - In Progress service requests | ||
* - Completed service requests | ||
* - Verified Service requests | ||
* - Approved Service requests | ||
* - Service requests breakdown based on their zones | ||
* - Service requests breakdown based on their nature/service | ||
* | ||
* @author Benson Maruchu<[email protected]> | ||
* @version 0.1.0 | ||
* @since 0.4.3 | ||
*/ | ||
|
||
const OPERATIONAL_FACET = { | ||
...OVERALL_FACET, | ||
...SERVICE_FACET, | ||
}; | ||
|
||
/** | ||
* @function | ||
* @name getOperationalReport | ||
* @description Generate operational report based on provided criteria | ||
* | ||
* @param {object} criteria Criteria condition to be applied in $match | ||
* @param {object} onResults Callback when aggregation operation finishes | ||
* @returns {object} executed aggregation | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
* | ||
* @example | ||
* getOperationalReport(criteria, function(error, data){ | ||
* ... | ||
* }); | ||
*/ | ||
const getOperationalReport = (criteria, onResults) => { | ||
const baseAggregation = getBaseAggregation(criteria); | ||
|
||
return baseAggregation.facet(OPERATIONAL_FACET).exec(onResults); | ||
}; | ||
|
||
/** | ||
* @function | ||
* @name normalizeTime | ||
|
@@ -934,6 +986,7 @@ const prepareReportResponse = results => { | |
const API_VERSION = getString('API_VERSION', '1.0.0'); | ||
const PATH_OVERVIEW = '/reports/overviews'; | ||
const PATH_PERFORMANCE = '/reports/performances'; | ||
const PATH_OPERATIONAL = '/reports/operations'; | ||
const PATH_OPERATOR_PERFORMANCE = '/reports/operators'; | ||
|
||
const router = new Router({ | ||
|
@@ -1038,6 +1091,38 @@ router.get(PATH_OPERATOR_PERFORMANCE, (request, response, next) => { | |
}); | ||
}); | ||
|
||
/** | ||
* @api {get} /reports/operations Operational Report | ||
* @apiGroup Analytics | ||
* @apiName GetOperations | ||
* @apiVersion 1.0.0 | ||
* @apiDescription Return overview report | ||
* @apiUse RequestHeaders | ||
* @apiUse Operator | ||
* | ||
* @apiUse RequestHeaderExample | ||
* @apiUse OverviewSuccessResponse | ||
* @apiUse JWTError | ||
* @apiUse JWTErrorExample | ||
* @apiUse AuthorizationHeaderError | ||
* @apiUse AuthorizationHeaderErrorExample | ||
*/ | ||
router.get(PATH_OPERATIONAL, (request, response, next) => { | ||
const options = merge({}, request.mquery); | ||
|
||
const filter = options.filter || {}; | ||
|
||
getOperationalReport(filter, (error, results) => { | ||
if (error) { | ||
next(error); | ||
} else { | ||
const data = prepareReportResponse(results); | ||
response.status(200); | ||
response.json(data); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* @name majifix-analytics | ||
* @description A module for analytics and visualizations of majifix data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,21 @@ const METRIC_TIMES = { | |
averageCallTime: { $avg: '$call.duration.milliseconds' }, | ||
}; | ||
|
||
const METRIC_COUNTS = { | ||
approved: { $sum: '$approved' }, | ||
assigned: { $sum: 'assigned' }, | ||
attended: { $sum: '$attended' }, | ||
completed: { $sum: '$completed' }, | ||
count: { $sum: 1 }, | ||
late: { $sum: '$late' }, | ||
new: { $sum: '$new' }, | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
reopened: { $sum: '$reopened' }, | ||
unconfirmed: { $sum: '$unconfirmed' }, | ||
verified: { $sum: '$verified' }, | ||
}; | ||
|
||
/** | ||
* @namespace OVERALL_FACET | ||
* @description Facet for service requests overall general breakdown | ||
|
@@ -356,13 +371,7 @@ const OVERALL_FACET = { | |
{ | ||
$group: { | ||
_id: null, | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
unconfirmed: { | ||
$sum: '$unconfirmed', | ||
}, | ||
late: { $sum: '$late' }, | ||
count: { $sum: 1 }, | ||
...METRIC_COUNTS, | ||
...METRIC_TIMES, | ||
}, | ||
}, | ||
|
@@ -470,13 +479,9 @@ const SERVICE_FACET = { | |
{ | ||
$group: { | ||
_id: '$service._id', | ||
pending: { $sum: '$pending' }, | ||
resolved: { $sum: '$resolved' }, | ||
late: { $sum: '$late' }, | ||
unconfirmed: { $sum: '$unconfirmed' }, | ||
name: { $first: '$service.name' }, | ||
color: { $first: '$service.color' }, | ||
count: { $sum: 1 }, | ||
...METRIC_COUNTS, | ||
...METRIC_TIMES, | ||
}, | ||
}, | ||
|
@@ -789,6 +794,53 @@ const getOperatorPerformanceReport = (criteria, onResults) => { | |
return baseAggregation.facet(OPERATOR_PERFORMANCE_FACET).exec(onResults); | ||
}; | ||
|
||
/** | ||
* This is operational report based on service request | ||
* It consist of | ||
* - Total service requests per a given period | ||
* - Pending service requests | ||
* - Resolved service requests | ||
* - Assigned service requests | ||
* - In Progress service requests | ||
* - Completed service requests | ||
* - Verified Service requests | ||
* - Approved Service requests | ||
* - Service requests breakdown based on their zones | ||
* - Service requests breakdown based on their nature/service | ||
* | ||
* @author Benson Maruchu<[email protected]> | ||
* @version 0.1.0 | ||
* @since 0.4.3 | ||
*/ | ||
|
||
const OPERATIONAL_FACET = { | ||
...OVERALL_FACET, | ||
...SERVICE_FACET, | ||
}; | ||
|
||
/** | ||
* @function | ||
* @name getOperationalReport | ||
* @description Generate operational report based on provided criteria | ||
* | ||
* @param {object} criteria Criteria condition to be applied in $match | ||
* @param {object} onResults Callback when aggregation operation finishes | ||
* @returns {object} executed aggregation | ||
* | ||
* @version 0.1.0 | ||
* @since 0.1.0 | ||
* | ||
* @example | ||
* getOperationalReport(criteria, function(error, data){ | ||
* ... | ||
* }); | ||
*/ | ||
const getOperationalReport = (criteria, onResults) => { | ||
const baseAggregation = getBaseAggregation(criteria); | ||
|
||
return baseAggregation.facet(OPERATIONAL_FACET).exec(onResults); | ||
}; | ||
|
||
/** | ||
* @function | ||
* @name normalizeTime | ||
|
@@ -936,6 +988,7 @@ const prepareReportResponse = results => { | |
const API_VERSION = env.getString('API_VERSION', '1.0.0'); | ||
const PATH_OVERVIEW = '/reports/overviews'; | ||
const PATH_PERFORMANCE = '/reports/performances'; | ||
const PATH_OPERATIONAL = '/reports/operations'; | ||
const PATH_OPERATOR_PERFORMANCE = '/reports/operators'; | ||
|
||
const router = new expressCommon.Router({ | ||
|
@@ -1040,6 +1093,38 @@ router.get(PATH_OPERATOR_PERFORMANCE, (request, response, next) => { | |
}); | ||
}); | ||
|
||
/** | ||
* @api {get} /reports/operations Operational Report | ||
* @apiGroup Analytics | ||
* @apiName GetOperations | ||
* @apiVersion 1.0.0 | ||
* @apiDescription Return overview report | ||
* @apiUse RequestHeaders | ||
* @apiUse Operator | ||
* | ||
* @apiUse RequestHeaderExample | ||
* @apiUse OverviewSuccessResponse | ||
* @apiUse JWTError | ||
* @apiUse JWTErrorExample | ||
* @apiUse AuthorizationHeaderError | ||
* @apiUse AuthorizationHeaderErrorExample | ||
*/ | ||
router.get(PATH_OPERATIONAL, (request, response, next) => { | ||
const options = lodash.merge({}, request.mquery); | ||
|
||
const filter = options.filter || {}; | ||
|
||
getOperationalReport(filter, (error, results) => { | ||
if (error) { | ||
next(error); | ||
} else { | ||
const data = prepareReportResponse(results); | ||
response.status(200); | ||
response.json(data); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* @name majifix-analytics | ||
* @description A module for analytics and visualizations of majifix data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.