With yesterday's smooth, today is more confident, today to do is to obtain the number of interval records, for the foreground statistics chart preparation data, for example, the effect is,
In 1 days, there are xx times, within 2 days of XX times, within 3 days of XX times (excluding the previous interval of data)
Analyzed, you can manipulate the data obtained in the second step of yesterday (ttt_date_out table, data content like {id:1,times:[1,2,3,....]} ), map and reduce also write a map similar to yesterday's
function Map () {
var times = this.value.times;
if (times) {
if (Times.length > 1) {for
(var i = 0;i < times.length;i++) {
if (i! = times.length-1) {
VA R between_time = times[i]-times[i+1];
Rounding up, the 1.4,1,7 will become 2, meaning "two days"
var day = Math.ceil (Between_time/(+ *));
Emit (Day
, 1
);
}
}}}
Write reduce
function Reduce (key, values) {
var reduced = {Key:key, count:0};
Values.foreach (function (val) {
reduced.count++;
});
return reduced;
}
Get the results, to achieve expectations, but still not ideal, for only one map of data and multiple map data, the result is a little different
The company can not Google, only ask degrees Niang, no solution, their own, think of yesterday used in finalize write finalize
function Finalize (key, reduced) {
if (reduced.count) {
return reduced.count;
} else{
return reduced;
}
}
Wasted some time, but the boat small good turn, example small good blind try, the final effect