-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashboard metrics implementation #202
Open
tremainebuchanan
wants to merge
5
commits into
develop
Choose a base branch
from
call-metric-impl
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb036bd
Removed stats to common.js file
tremainebuchanan cf926f4
Dashboard metrics completed
tremainebuchanan df77b23
Removed unimplemented code
tremainebuchanan d7a7cb1
Changed labels above the dashboard performance
tremainebuchanan b0263c3
Removed performance metrics for demands and pending transactions.
tremainebuchanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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 |
---|---|---|
|
@@ -40,4 +40,4 @@ module.exports = router; | |
*/ | ||
function dummyStub(req, res) { | ||
res.end({info: "unimplemented"}); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
/** | ||
* Created by matjames007 on 4/29/15. | ||
*/ | ||
var model = require('../../models/db'); | ||
var Address = model.Address; | ||
var Parish = model.Parish; | ||
var Farmer = model.Farmer; | ||
var Buyer = model.Buyer; | ||
var Unit = model.Unit; | ||
var Demand = model.Demand; | ||
var Crop = model.Crop; | ||
var Commodity = model.Commodity; | ||
var District = model.District; | ||
var model = require('../../models/db'), | ||
Address = model.Address, | ||
Parish = model.Parish, | ||
Farmer = model.Farmer, | ||
Buyer = model.Buyer, | ||
Unit = model.Unit, | ||
Demand = model.Demand, | ||
Crop = model.Crop, | ||
Commodity = model.Commodity, | ||
District = model.District, | ||
CallLog = model.CallLog, | ||
Transaction = model.Transaction, | ||
moment = require('moment'); | ||
|
||
/** | ||
* Check if user is logged in. | ||
|
@@ -397,3 +400,76 @@ exports.batchPushDistricts = function(req, res) { | |
} | ||
}) | ||
}; | ||
/** | ||
* Generates the dashboard performance metrics from the database | ||
* by counting the number of calls, demands or transactions | ||
* made within a period of time. | ||
* @param {[type]} req [description] | ||
* @param {[type]} res [description] | ||
*/ | ||
exports.getStats = function(req, res){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paradoxxjm gosh we need to put in a test suite on this... hard to go through this in the code review :( |
||
var start_of_prev_week = moment().startOf('day').day(1).subtract(7, 'days'), | ||
last_week = moment().day(moment().day()).subtract(7, 'days'), | ||
current_week = moment().startOf('week'), | ||
today = moment(), | ||
prev_week_query = {$gte: start_of_prev_week.toDate(), $lt:last_week.toDate()}, | ||
current_week_query = {$gte: current_week.toDate(), $lt:today.toDate()}; | ||
CallLog.count({cc_date: prev_week_query}).exec(function(err, prev_call_count){ | ||
if(err){ | ||
handleDBError(err, res); | ||
}else{ | ||
CallLog.count({cc_date: current_week_query}).exec(function(err, current_call_count){ | ||
if(err){ | ||
handleDBError(err, res); | ||
}else{ | ||
Transaction | ||
.count({tr_status: 'Completed', tr_date_created: prev_week_query}) | ||
.exec(function(err, prev_completed_trans_count){ | ||
if(err){ | ||
handleDBError(err, res); | ||
}else{ | ||
Transaction | ||
.count({tr_status: 'Completed', tr_date_created: current_week_query}) | ||
.exec(function(err, current_completed_trans_count){ | ||
if(err){ | ||
handleDBError(err, res); | ||
}else{ | ||
var stats = { completed_trans: { current_week: current_completed_trans_count, | ||
previous_week: prev_completed_trans_count }, | ||
call: { current_week: current_call_count, | ||
previous_week: prev_call_count }}//end of object | ||
formatandSendStats(stats, res); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Determines if there has been any change week on week | ||
* for performance metrics. | ||
* @param {[type]} stats Calculated performance metrics | ||
* @param {[type]} res [description] | ||
*/ | ||
formatandSendStats = function(stats, res){ | ||
stats.completed_trans.changes = getStatisticChange(stats.completed_trans.current_week, stats.completed_trans.previous_week); | ||
stats.call.changes = getStatisticChange(stats.call.current_week, stats.call.previous_week); | ||
res.send(stats); | ||
} | ||
/** | ||
* Determines change in performance metrics. The function | ||
* attempts to return whether there is an increase, decrease or | ||
* no change in a performance metric. | ||
* @param {[type]} current Current week's count of a particular metric | ||
* @param {[type]} prev Previous week's count of a particular metric | ||
*/ | ||
getStatisticChange = function(current, prev){ | ||
var stat_change = {}; | ||
current === prev ? stat_change.change = "none" : | ||
current > prev ? stat_change.change = "increase" : stat_change.change = "decrease"; | ||
stat_change.changed_by = Math.abs(current - prev); | ||
return stat_change; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tremainebuchanan you need some documentation here... be careful how you use the entity comparison. If you are expecting boolean try and use boolean
true
and the==
comparator.