-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
👌 Add Recovery Rate metric #13
Open
josephkerkhof
wants to merge
3
commits into
ahmadawais:master
Choose a base branch
from
josephkerkhof:add-recovery-rate
base: master
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Calculates the recovery rate and puts it in a nice looking string format. | ||
* | ||
* @param {int} numDeaths The number of deaths for a unit | ||
* @param {int} numRecoveries The number of recoveries for a unit | ||
* @return {String} A parsed string percentage string of recoveries rounded to one decimal place. | ||
*/ | ||
function calcRecoveryRate(numDeaths, numRecoveries) { | ||
return ((numRecoveries / (numDeaths + numRecoveries)) * 100).toFixed(1) + '%'; | ||
} | ||
|
||
/** | ||
* Calculates the recovery rate from an array of data and splices the recovery rate | ||
* into the middle of the array for table formatting. | ||
* | ||
* @param {Array} one data about the element we are processing. (e.g. state, country, etc.) | ||
* @return {Array} A spliced array almost as it was before but now with a string formatted recovery rate. | ||
*/ | ||
function spliceRecoveryRate(one) { | ||
const numRecoveries = one[5]; | ||
const numDeaths = one[3]; | ||
const oneRecovery = ((numRecoveries / (numRecoveries + numDeaths)) * 100); | ||
var oneRecoveryStr = oneRecovery.toFixed(1) + '%'; | ||
if(isNaN(oneRecovery) || oneRecovery === 0){ | ||
oneRecoveryStr = '—'; | ||
} | ||
one.splice(6, 0, oneRecoveryStr); | ||
return one; | ||
} | ||
|
||
module.exports = { | ||
/** | ||
* | ||
* @param {String} deaths A comma delineated number for number of deaths. | ||
* @param {String} recoveries A comma delineated number for number of recoveries. | ||
* @return {String} A parsed string percentage string of recoveries rounded to one decimal place. | ||
*/ | ||
calculateWorldwideRecoveryRate: function(deaths, recoveries) { | ||
const numDeaths = parseInt(deaths.replace(/,/g,'')); | ||
const numRecoveries = parseInt(recoveries.replace(/,/g,'')); | ||
return calcRecoveryRate(numDeaths, numRecoveries); | ||
}, | ||
|
||
/** | ||
* Calculates the recovery rate for a set of objects. | ||
* | ||
* @param {Array} data The objects to calculate the recovery rate on. | ||
* @return {Array} The data almost as it was before, but now has the recovery rate included. | ||
*/ | ||
calculateMultipleRecoveryRate: function(data) { | ||
return data.map(one => { | ||
return spliceRecoveryRate(one) | ||
}); | ||
}, | ||
|
||
/** | ||
* Calculates the recovery rate for a single object. (e.g. China) | ||
* | ||
* @param {Array} data A single object of data for a unit. | ||
*/ | ||
calculateSingleRecoveryRate: function(data) { | ||
return spliceRecoveryRate(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
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
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.
one
is a poor name, as a reader I have no idea what that means.Perhaps
area
would be better?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.
one
is the naming convention already in use in this project elsewhere for a single entry.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.
I believe we can make
one
better everywhere.