Last active
January 2, 2018 07:58
-
-
Save chernjie/d0ffa9d45a3d7b7c48ace432a1ad8385 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
#!/usr/bin/env node | |
// time csvtojson data/order-interval-20180102.csv | node mockup/order-interval.js | |
var stdin = require('../../ppdg/ppdg-elk/src/stdinjson.js'); | |
var lodash = require('lodash'); | |
stdin(_process); | |
function _process (err, data) { | |
return lodash(data) | |
.filter((el) => { | |
return el.store_id != 13; | |
}) | |
// .filter((el) => { | |
// return '2017-11-18' != el.created_at.split(' ')[0] | |
// }) | |
// .filter((el) => { | |
// return new Date(el.created_at) > new Date('2017-11-18') | |
// }) | |
.sortBy([(el) => { | |
return new Date(el.created_at); | |
}]) | |
.groupBy((el) => { | |
return ["5", "11", "12", "13"].indexOf(el.store_id) !== -1 ? 'ebay' : 'ppdg'; | |
}) | |
.map((el, store) => { | |
var maxtime = lodash(el) | |
.reduce((max, el) => { | |
if (max.last) { | |
var interval_ms = new Date(el.created_at) - new Date(max.last); | |
if (max.max < interval_ms && interval_ms < 1440 * 60 * 1000) { | |
max.max = interval_ms; | |
max.pair = [ max.last, el.created_at ]; | |
} | |
} | |
max.last = el.created_at; | |
return max; | |
}, { | |
max:0, | |
last:0, | |
pair: [], | |
}); | |
// set time to minutes | |
maxtime.max /= 1000; | |
maxtime.max /= 60; | |
maxtime.max = parseInt(maxtime.max); | |
console.log(store, maxtime.max, maxtime.pair[0], maxtime.pair[1]); | |
return { | |
store: store, | |
max: maxtime.max, | |
}; | |
}, {}) | |
.value() | |
} |
Author
chernjie
commented
Mar 22, 2017
store | maxtime |
---|---|
1 | 61.38333333333333 |
2 | 256.65 |
3 | 71.96666666666667 |
5 | 62.81666666666667 |
6 | 2664.7166666666667 |
8 | 219.28333333333333 |
9 | 1463.6666666666667 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment