Arrow playground

by felixp

HTML

<!DOCTYPE html>
<html>

  <head>
    <!-- breaking changes in latest (v9) API -->
    <script src="https://unpkg.com/[email protected]/Arrow.es2015.min.js"></script>
    <!-- jsFiddle will insert css and js -->
  </head>

  <body>
  </body>
</html>

JavaScript

// Sample data
const LENGTH = 1000;
const rainAmounts = Float32Array.from({
    length: LENGTH
  },
  () => Number((Math.random() * 20).toFixed(1)));

const rainDates = Array.from({
    length: LENGTH
  },
  (_, i) => new Date(Date.now() - 1000 * 60 * 60 * 24 * i));

/* const rainfall = Arrow.tableFromArrays({
    precipitation: rainAmounts,
    date: rainDates
}); */

const rainfall = Arrow.Table.new(
  [Arrow.FloatVector.from(rainAmounts), Arrow.DateVector.from(rainDates)],
  ['precipitation', 'date']
);



// Stats
function columnStats(table, name) {
  // Get the column withe the given name
  // const column = table.getChild(name); // v9.0 API
  const column = table.getColumn(name);

  // Use it's iterator to find the max and min values
  let max = column.get(0),
    min = max;
  for (let value of column) {
    if (value > max) max = value;
    else if (value < min) min = value;
  }

  return {
    name,
    max,
    min,
    range: max - min
  };
}
console.log(columnStats(rainfall, 'precipitation'));

// Filter
debugger;
const dry = rainfall
    	.filter(Arrow.predicate.col('precipitation').lt(4));
const output = Array.from(dry, p => p.precipitation);

console.log(output);

// Async
async function grabData() {
  // Scrabble
  const url = 'https://gist.githubusercontent.com/TheNeuralBit/64d8cc13050c9b5743281dcf66059de5/raw/c146baf28a8e78cfe982c6ab5015207c4cbd84e3/scrabble.arrow';
  console.log('start download')
  //const data = await ;
  const scrabble = await Arrow.Table.from(fetch(url));
    console.log('complete download')


  // Get col names
  console.log(scrabble.schema.fields.map((d) => d.name));
  
  // Aggregate
  console.log(scrabble.countBy('winnername'));

}

// grabData();