예제 #1
0
 /**
  * run the map/reduce
  * @static
  * @return void
  */
 public static function mapReduce()
 {
     $map = "function () {\n            var info = {}\n            info[this.victim.shipType] = 1;\n            info[\"total\"] = 1;\n            emit(this.victim.shipType, info);\n        }";
     $reduce = "function (k, vals) {\n            var sums = {}\n            var total = 0;\n            vals.forEach(function (info) {\n                info[\"total\"] = 0;\n                for (var key in info) {\n                    if(sums[key] === undefined)\n                        sums[key] = 0;\n                    sums[key] += info[key];\n                    total += info[key];\n                }\n            });\n            sums[\"total\"] = total;\n            return sums;\n        }";
     $tr = \Kingboard\Model\TaskRun::findByTaskType(__CLASS__);
     if (is_null($tr)) {
         $tr = new \Kingboard\Model\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);
     \King23\Mongo\Mongo::mapReduce("Kingboard_Kill", $out, $map, $reduce, $filter);
 }
예제 #2
0
 public static function mapReduce()
 {
     $map = "function () {\n            var info = {};\n            info['group'] = {};\n            info['ship'] = {}\n            info['ship'][this.victim.shipType] = 1;\n            info['total'] = 1;\n            var done = {};\n            this.attackers.forEach(function (attacker) {\n                if(done[attacker.factionID] === undefined)\n                    emit(attacker.factionID, info);\n                done[attacker.factionID] = true;\n            });\n        }";
     $reduce = "function (k, vals) {\n            var sums = {}\n            sums['group'] = {}\n            sums['ship'] = {}\n            sums['total'] = 0;\n            var total = 0;\n            vals.forEach(function (info) {\n                sums['total'] += info['total'];\n\n                for (var key in info['group']) {\n                    if(sums['group'][key] === undefined)\n                        sums['group'][key] = 0;\n                    sums['group'][key] += info['group'][key];\n                }\n\n                for (var key in info['ship']) {\n                    if(sums['ship'][key] === undefined)\n                        sums['ship'][key] = 0;\n                    sums['ship'][key] += info['ship'][key];\n                }\n\n            });\n            return sums;\n        }";
     $tr = \Kingboard\Model\TaskRun::findByTaskType(__CLASS__);
     if (is_null($tr)) {
         $tr = new \Kingboard\Model\TaskRun();
         $tr->type = __CLASS__;
         $tr->lastrun = new \MongoDate(0);
     }
     $last = $tr->lastrun;
     $tr->save();
     $new = $tr->lastrun;
     $filter = array('$and' => array(array('saved' => array('$gt' => $last, '$lte' => $new)), array('attackers.factionID' => array('$ne' => 0))));
     $obj = new self();
     $out = array("reduce" => $obj->_className);
     return \King23\Mongo\Mongo::mapReduce("Kingboard_Kill", $out, $map, $reduce, $filter);
 }
예제 #3
0
 /**
  * @static
  */
 public static function mapReduce()
 {
     $map = "function () {\n            emit(this.victim.characterName, {id: this.victim.characterID, type: \"character\"});\n            emit(this.victim.factionName, {id: this.victim.factionID, type: \"faction\"});\n            emit(this.victim.corporationName, {id: this.victim.corporationID, type: \"corporation\"});\n            emit(this.victim.allianceName, {id: this.victim.allianceID, type: \"alliance\"});\n            this.attackers.forEach(function (attacker) {\n                emit(attacker.characterName, {id: attacker.characterID, type: \"character\"});\n                emit(attacker.factionName, {id: attacker.factionID, type: \"faction\"});\n                emit(attacker.corporationName, {id: attacker.corporationID, type: \"corporation\"});\n                emit(attacker.allianceName, {id: attacker.allianceID, type: \"alliance\"});\n            });\n        }";
     $reduce = "function (k, vals) {\n            return vals[0]; // we only need the contents of the first hit for this key\n        }";
     $tr = \Kingboard\Model\TaskRun::findByTaskType(__CLASS__);
     if (is_null($tr)) {
         $tr = new \Kingboard\Model\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);
     return \King23\Mongo\Mongo::mapReduce("Kingboard_Kill", $out, $map, $reduce, $filter);
 }