daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest May 19th, 2017 35 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try {
  2. var cursor = (function(ctStartHoursAgo, ctEndHoursAgo, ltStartHoursAgo, ltEndHoursAgo) {
  3.   var hoursAgoUtc = function(hour) { return Math.round((new Date().getTime() / 1000) - (hour * 60 * 60)); };
  4.   var ctStartSecsAgo = hoursAgoUtc(ctStartHoursAgo);
  5.   var ctEndSecsAgo = hoursAgoUtc(ctEndHoursAgo);
  6.   var ltStartSecsAgo = hoursAgoUtc(ltStartHoursAgo);
  7.   var ltEndSecsAgo = hoursAgoUtc(ltEndHoursAgo);
  8.   var map = function() { var returnCount = (this.lt > ltStartSecsAgo && this.lt < ltEndSecsAgo) ? 1 : 0; emit(this._id.aid, {c: 1, r: returnCount }); };
  9.   var reduce = function(key, vals) { var count = 0, returns = 0; for (var i in vals) { count += vals[i].c; returns += vals[i].r; } return { c: count, r: returns }; };
  10.   var finalize = function (key, val) { var returnRate = val.r / val.c; return { returns: val.r, count: val.c, returnRate: returnRate }; };
  11.   var query = { "ct": { "$gt": ctStartSecsAgo, "$lt": ctEndSecsAgo } };
  12.   var options = { query: query, finalize: finalize };
  13.   var res = db.userAnalytic.mapReduce(map, reduce, options);
  14.   return db[res.result].find({"value.returnRate":{$gt:0},"value.count":{$gt:10}}).sort({"value.returnRate":-1});
  15. })(21,20,8,0);
  16. } catch (ex) { print(ex); }
RAW Paste Data
Top