This file contains hidden or 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, |
This file contains hidden or 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
async function getFinalResults(kNearest,nDays) { | |
var finalResults = []; | |
var finalResult = {}; | |
await forEach(kNearest, async(date) => { | |
var dateTime = new Date(date); | |
var pastDate = dateTime.toISOString().split('T')[0]; | |
var futureDate = new Date(date); | |
futureDate.setDate(futureDate.getDate() + nDays); |
This file contains hidden or 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
async function getNearestNeighbours(similarities) { | |
// Run through, and find k(10) that are closest to 0 | |
var absSimilarities = []; | |
similarities.forEach( (similarity) => { | |
absSimilarities.push({ | |
date: similarity.date, | |
similarityScore: Math.abs(similarity.similarityScore) | |
}) | |
}) | |
absSimilarities = absSimilarities.sort(function(a,b) { |
This file contains hidden or 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
async function findMostFrequent(array, blackListArr) | |
{ | |
if(array.length == 0) | |
return null; | |
var modeMap = {}; | |
var maxEl = array[0], maxCount = 1; | |
// First go through blackList array and set maxEl to the first element that isn't in the blacklist, if every of the numbers in the array is in the blacklist, then just return generateRandom | |
var containsValidNumbers = false; |
This file contains hidden or 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
function refreshBitcoinPrices() { | |
const request = async () => { | |
var results = await fetch("https://blockchain.info/ticker"); | |
results = await results.json(); | |
bitcoinData.results = results; | |
if(bitcoinData.results) {console.log('Blockchain API works!');} | |
else console.log('Blockchain API is down at the moment.'); | |
// Get todays date |