Encouraging User Participation - Some Ideas, More welcome

Played around a little with smoothing today, in case anyone wants to explore further:

    var smooth = function(data, windowSize) {
      var smoothed = [];
      var movingWindow = [];

      for(var i = 0; i < windowSize; i++) {
        movingWindow.push(data[i]);
      }

      for(var i = 0; i < data.length; i++) {
        movingWindow.push(data[i]);
        movingWindow.shift();
        smoothed.push(movingWindow.reduce((a, v) => a + v, 0) / windowSize);
      }
      return smoothed;
    }

    var samples = rawData.map(r => r.y);

    var data = {
      labels: rawData.map(r => r.x),
      datasets: [{
        data: samples,
        label: model.get('title'),
        backgroundColor: "rgba(200,220,240,0.3)",
        borderColor: "#08C"
      },{
        data: smooth(samples, 7),
        label: '7 Day Moving Average',
        backgroundColor: "rgba(0,0,0,0)",
        borderColor: "#C80"
      }]
    };
5 Likes