Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
 }