Created
December 23, 2017 22:21
-
-
Save ognjengt/f7e6856fc694da3e21e131c0784bacc6 to your computer and use it in GitHub Desktop.
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
/** | |
* Calculates the prediction | |
* Returns object containing valuable data for prediction | |
* @param {*Array} data Array of objects, containing start and end bitcoin values | |
* @param {*Float} currentBitcoinValue Current btc value | |
*/ | |
async function calculatePrediction(data,currentBitcoinValue) { | |
var finalPredictionData = { | |
raw: 0, | |
percentage: 0, | |
positive: '', | |
finalValue: 0 | |
} | |
var sum = 0; | |
await forEach(data, async (value) => { | |
sum += value.end - value.start; | |
}) | |
sum = sum / K; | |
finalPredictionData.raw = sum; | |
finalPredictionData.finalValue = currentBitcoinValue + sum; | |
finalPredictionData.positive = sum > 0 ? 'true' : 'false'; | |
finalPredictionData.percentage = ((finalPredictionData.finalValue - currentBitcoinValue) / currentBitcoinValue) * 100; | |
return finalPredictionData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment