Lumenize Work In Progress via TimeInstStateCalculator
by Trever Shick
HTML
<script src="https://storage.googleapis.com/versions.lumenize.com/v0.6.8/Lumenize-min.js"></script>
<script src="http://maccherone.com/share/1000-snapshots-overlap-with-Feb-2012.json"></script>
<script>
var dataArray = [
{
"_ValidFrom": "2012-01-20T00:08:26.943Z",
"_ValidTo": "2012-01-21T01:32:47.208Z",
"ObjectID": 4655449709,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:25:10.653Z",
"_ValidTo": "2012-01-20T00:31:22.132Z",
"ObjectID": 5003297332,
"ScheduleState": "Defined"
},
{
"_ValidFrom": "2012-01-20T00:30:57.586Z",
"_ValidTo": "2012-04-18T20:28:41.799Z",
"ObjectID": 5236240164,
"ScheduleState": "Idea"
},
{
"_ValidFrom": "2012-01-20T00:31:22.132Z",
"_ValidTo": "2012-01-20T00:37:08.989Z",
"ObjectID": 5003297332,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:37:08.989Z",
"_ValidTo": "2012-01-20T00:37:21.259Z",
"ObjectID": 5003297332,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:37:21.259Z",
"_ValidTo": "2012-01-20T00:47:36.685Z",
"ObjectID": 5003297332,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:45:22.939Z",
"_ValidTo": "2012-01-20T00:46:29.377Z",
"ObjectID": 4976055895,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:46:29.377Z",
"_ValidTo": "2012-01-20T00:54:04.724Z",
"ObjectID": 4976055895,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:47:36.685Z",
"_ValidTo": "2012-01-20T02:54:50.988Z",
"ObjectID": 5003297332,
"ScheduleState": "In-Progress"
},
{
"_ValidFrom": "2012-01-20T00:54:04.724Z",
"_ValidTo": "2012-01-20T00:54:11.069Z",
"ObjectID": 4976055895,
...
CoffeeScript
lumenize = require('./lumenize')
filtered = _.filter(dataArray, (x) ->
return x.ScheduleState == "In-Progress"
)
granularity = 'day'
tz = 'America/New_York'
## didn't do holidays... but it's simple enough
config = # default work days and holidays
granularity: granularity
tz: tz
endBefore: '2012-02-29T00:00:00.000'
workDayStartOn: {hour: 7, minute: 0}
workDayEndBefore: {hour: 4, minute: 0}
validFromField: '_ValidFrom'
validToField: '_ValidTo'
uniqueIDField: 'ObjectID'
holidays: [
{month: 1, day: 1},
{month: 1, day: 10},
{month: 1, day: 19}
]
#trackLastValueForTheseFields: ['ObjectID', 'ScheduleState']
startOn = '2012-01-01T00:00:00.000Z'
endBefore = '2012-02-29T00:00:00.000Z'
tisc = new lumenize.TimeInStateCalculator(config)
tisc.addSnapshots(filtered, startOn, endBefore)
x = tisc.getResults()
noZerosX = _.filter(x, (x) ->
return x.ticks > 0
)
lumenize.utils.log(JSON.stringify(noZerosX));
_.each(noZerosX, (z) ->
lumenize.utils.log("#{z.ObjectID} #{z.ticks}")
)
###
tl = new lumenize.Timeline({
startOn: '2012-01-01',
endBefore: '2012-02-29',
holidays: [
{month: 1, day: 1},
{month: 1, day: 10},
{month: 1, day: 19}
]
})
config =
deriveFieldsOnInput: [{
field: 'workInProgressDays',
f: (row) ->
if row.ScheduleState != "In-Progress" then 0 else tl.ticksThatIntersect(row._ValidFrom, row._ValidTo,'GMT').length
}]
metrics: [{field: 'workInProgressDays', f: 'sum'}]
dimensions: [{field: 'ObjectID'}]
cube = new lumenize.OLAPCube(config, dataArray)
lumenize.utils.log(cube.toString(null, null, 'workInProgressDays_sum'))
###