/** * run the map/reduce * @static * @return void */ public static function mapReduce() { $map = "function () {\n var info = {}\n\n // emitted is 1 kill each run\n info[\"total\"] = 1;\n\n // create daily id\n date = this.killTime;\n date.setUTCHours(0);\n date.setUTCMinutes(0);\n date.setUTCSeconds(0);\n\n // collect the date needed for the most valuable each day\n info['topValue'] = {\n victim: this.victim,\n totalISKValue: this.totalISKValue\n }\n\n // emit info about the kill for date\n emit(date, info);\n }"; $reduce = "function (k, vals) {\n // initialize empty\n var sums = {\n total: 0,\n topValue: {\n totalISKValue: 0\n }\n };\n\n\n vals.forEach(function (info) {\n sums[\"total\"]+= info[\"total\"];\n\n // for each reduced value check if the kills totalISKValue is the higher one,\n // if so, thats the one we want in the end result.\n if (sums[\"topValue\"][\"totalISKValue\"] < info[\"topValue\"][\"totalISKValue\"]) {\n sums[\"topValue\"] = info[\"topValue\"];\n }\n });\n\n return sums;\n }"; $tr = TaskRun::findByTaskType(__CLASS__); if (is_null($tr)) { $tr = new TaskRun(); $tr->type = __CLASS__; $tr->lastrun = new MongoDate(0); } $last = $tr->lastrun; $tr->save(); $new = $tr->lastrun; $filter = array("saved" => array('$gt' => $last, '$lte' => $new)); $obj = new self(); $out = array("reduce" => $obj->_className); Mongo::mapReduce("Kingboard_Kill", $out, $map, $reduce, $filter); }