Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Last active November 5, 2018 21:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkgokul/79b2d01a4128b3716ec725d444ec83ee to your computer and use it in GitHub Desktop.
Save nkgokul/79b2d01a4128b3716ec725d444ec83ee to your computer and use it in GitHub Desktop.
Sample data from Bitcoin Dominance Chart on https://coinmarketcap.com/charts/
dominanceChart = Highcharts.charts[2];
coinsForDominance = ['Bitcoin','Ethereum','Bitcoin Cash', 'Ripple', 'Others'];
datesForDominance = ['Jan 25 2017', 'March 10 2017', 'March 26 2017', 'May 18 2017', 'June 13 2017', 'August 03 2017', 'November 06 2017', 'November 12 2017', 'Dec 8 2017', 'Jan 04 2018', 'Jan 14 2018', 'May 3 2018', 'July 05 2018'];
coinDateDominanceMatrix = [];
coinsForDominanceData = dominanceChart.series.filter(coin => {return coinsForDominance.indexOf(coin.name) != -1});
csvString = "Date, " + coinsForDominance.join();
mediumArticleString = "";
firstDateTime = coinsForDominanceData[0].xData[0];
date = new Date(firstDateTime);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
difference = firstDateTime - date.getTime();
datesForDominance.forEach(function(relevantDate){
csvString+= "\n" + relevantDate + ", ";
mediumArticleString= relevantDate + " - ";
coinDateDominanceMatrix[relevantDate] = [];
coinsForDominanceData.forEach(function(coin){
timestring = Date.parse(relevantDate)+difference;
coinDominance = coin.yData[coin.xData.indexOf(timestring)];
var dominanceValue = Math.round(coinDominance * 100) / 100;
coinDateDominanceMatrix[relevantDate][coin.name]= dominanceValue;
csvString+=dominanceValue + ", ";
mediumArticleString+=coin.name + " : " + dominanceValue + " , ";
});
});
console.table(coinDateDominanceMatrix);
console.log(csvString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment