Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMaruchu committed Sep 17, 2019
2 parents 6d9900b + 6d1f13f commit 17d8773
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 37 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#### 0.6.0 (2019-09-17)

##### Chores

* **package:** update package version to 0.6.0 ([3d7ac903](https://github.com/anzalab/majifix-analytics/commit/3d7ac903e32dc8ac3b7cc620a885a542ffca9374))
* **build:**
* bundle library for testing ([58a7a6ce](https://github.com/anzalab/majifix-analytics/commit/58a7a6ce0a164d3eae6ecea1ff472f875a08459d))
* bundle library for testing ([f39b5173](https://github.com/anzalab/majifix-analytics/commit/f39b5173f85e509c697616d0ca653a06a2e69b8e))

##### New Features

* add operational report router ([0bb7bada](https://github.com/anzalab/majifix-analytics/commit/0bb7badadac9c3a7a0f41fda105a0f7f4e58b396))

##### Refactors

* extract metric counts to a const variable ([93127f00](https://github.com/anzalab/majifix-analytics/commit/93127f00e87fb0d840eb7fa2f4cc14028cc86e1c))

#### 0.5.2 (2019-09-16)

##### Chores
Expand Down
109 changes: 97 additions & 12 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
109 changes: 97 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codetanzania/majifix-analytics",
"version": "0.5.2",
"version": "0.6.0",
"description": "Majifix module for analytics and reports",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
29 changes: 17 additions & 12 deletions src/base/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
Expand All @@ -41,13 +56,7 @@ export 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,
},
},
Expand Down Expand Up @@ -155,13 +164,9 @@ export 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,
},
},
Expand Down
Loading

0 comments on commit 17d8773

Please sign in to comment.