Created
August 16, 2017 20:12
-
-
Save chronick/e0a0ad752141f82d7ce2808467c2d713 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(require => { | |
const moment = require('moment'); | |
const d3 = require('d3'); | |
// const parseTime = d3.timeParse('%Y%m%d'); | |
const generateData = () => { | |
let data = []; | |
let n = 1; | |
let planned = 0; | |
let actual = 0; | |
const start = moment([2017, 0, 1]); | |
const end = moment([2017, 6, 31]); | |
for (let date = moment(start); date.diff(end) < 0; date.add(1, 'd')) { | |
let est = rand(0, 1) < 0.8 ? 0.0 : toFixed(rand(0, 7)); | |
let avg = toFixed(rand(0, 1)); | |
planned = toFixed(planned + (est * 1000)); | |
actual = toFixed(actual + (avg * 1000)); | |
data.push({ | |
date: date.unix(), | |
est, | |
avg, | |
actual: date.month() > 3 ? null : actual, | |
planned | |
}); | |
} | |
return data; | |
} | |
const rand = (min, max) => { | |
return Math.random() * (max - min) + min; | |
} | |
const toFixed = (n) => { | |
return Math.round(n * 100) / 100; | |
} | |
return generateData; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment