Skip to content

Instantly share code, notes, and snippets.

@biaocy
Last active January 8, 2018 13:35
Show Gist options
  • Save biaocy/3807d45c385fa3a29f8c62f749a08203 to your computer and use it in GitHub Desktop.
Save biaocy/3807d45c385fa3a29f8c62f749a08203 to your computer and use it in GitHub Desktop.
coinmarketcap.com crytocurrency change analyze
var count = document.querySelectorAll('#currencies-all > tbody > tr').length;
var data = document.querySelectorAll('#currencies-all > tbody > tr > td:nth-last-child(-n+3)');
var h1 = {'up': 0, 'down': 0, 'zero': 0}; //1 hour change
var h24 = {'up': 0, 'down': 0, 'zero': 0}; //24 hours change
var d7 = {'up': 0, 'down': 0, 'zero': 0}; //7 days change
for (let i = 0; i < data.length; i+=3) {
let a = Number(data[i].dataset.usd), b = Number(data[i+1].dataset.usd), c = Number(data[i+2].dataset.usd);
if (a > 0) h1.up++;
else if (a < 0) h1.down++;
else h1.zero++;
if (b > 0) h24.up++;
else if (b < 0) h24.down++;
else h24.zero++;
if (c > 0) d7.up++;
else if (c < 0) d7.down++;
else d7.zero++;
}
function calc(numerator, denominator=count) {
return (numerator/denominator*100).toPrecision(2);
}
console.clear();
console.log('%d currencies.', count);
console.log('Up %s%, down %s%, unchange %s% in 1 hour', calc(h1.up), calc(h1.down), calc(h1.zero));
console.log('Up %s%, down %s%, unchange %s% in 24 hours', calc(h24.up), calc(h24.down), calc(h24.zero));
console.log('Up %s%, down %s%, unchange %s% in 7 days', calc(d7.up), calc(d7.down), calc(d7.zero));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment