JSFiddle - React, Tailwind, and code Playground

by askhflajsf

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://rawgit.com/evanplaice/jquery-csv/master/src/jquery.csv.min.js"></script>

JavaScript

function simplifyData(data_set) {
  interval_length = 3600; // hourly intervals

  last_price = 0;
  idx = 0;
  while (idx < data_set.length) {

    // reset value for this interval
    volume = 0;
    price_sum = 0;
    count = 0;
    timestamp = data_set[idx]['timestamp'] + interval_length;

    // get sums for this interval
    while (data_set[idx]['timetamp'] < timestamp) {
      volume += data_set[idx]['volume'];
      price_sum += data_set[idx]['price'];
      count++;
      idx++;
      if (idx >= data_set.length)
        break;
    }

    // get average price
    price = count > 0 ? price_sum / count : last_price;
    last_price = price;

    // add new row to monotized data array
    monotized_data.append([
      timestamp: timestamp,
      volume: volume,
      price: price
    ]);
  }
}

// Format: time (UNIX timestamp), price, amount traded
// http://api.bitcoincharts.com/v1/csv/localbtcCAD.csv.gz
var complexCadCsv =...