/** * update statistics * @param array $options * @return void */ public function update_stats(array $options) { $log = Registry::getInstance()->getLogger(); $log->info('start updating stats'); $log->info('updating kills by Shiptype'); // stats table of how often all ships have been killed KillsByShip::mapReduce(); $log->info('update of KillsByShip stats completed'); $log->info('updating pilot loss stats'); LossesByShipByPilot::mapReduce(); $log->info('update of pilot loss stats completed'); $log->info('updating pilot kill stats'); KillsByShipByPilot::mapReduce(); $log->info('update of pilot kill stats completed'); $log->info('updating corporation loss stats'); LossesByShipByCorporation::mapReduce(); $log->info('update of corporation loss stats completed'); $log->info('updating corporation kill stats'); KillsByShipByCorporation::mapReduce(); $log->info('update of corporation kill stats completed'); $log->info('updating alliance loss stats'); LossesByShipByAlliance::mapReduce(); $log->info('update of alliance loss stats completed'); $log->info('updating alliance kill stats'); KillsByShipByAlliance::mapReduce(); $log->info('update of alliance kill stats completed'); $log->info('updating faction loss stats'); LossesByShipByFaction::mapReduce(); $log->info('update of faction loss stats completed'); $log->info('updating faction kill stats'); KillsByShipByFaction::mapReduce(); $log->info('update of faction kill stats completed'); $log->info('updating name lists for search'); NameSearch::mapReduce(); $log->info("name list updated"); $log->info('updating daily stats'); KillsByDay::mapReduce(); $log->info("daily stats updated"); $log->info('updating daily stats by entity'); KillsByDayByEntity::mapReduce(); $log->info("daily stats by entity updated"); }
public function index(array $params) { $context = array(); if (!isset($params['date'])) { $context["date"] = date("Y-m-d"); } else { $context["date"] = $params['date']; } // get previous day $dt = new DateTime($context['date']); $context["previousDate"] = date("Y-m-d", $dt->sub(new \DateInterval("P1D"))->getTimestamp()); $dt = new DateTime($context['date']); $ts = $dt->add(new \DateInterval("P1D"))->getTimestamp(); if ($ts < time()) { $context["nextDate"] = date("Y-m-d", $ts); } else { $context["nextDate"] = date("Y-m-d"); } if (!isset($params['page']) || empty($params['page'])) { $page = 1; } else { $page = (int) $params['page']; } // reset date $dt = new DateTime($context['date']); $mdt = new MongoDate($dt->getTimestamp()); if ($this->_context['ownerID']) { $stats = KillsByDayByEntity::findOne($dt->getTimestamp(), $this->_context['ownerID']); } else { $stats = KillsByDay::findOne($mdt); } $context['stats'] = $stats['value']; $paginator = new Paginator($page, $context['stats']['total']); $context['page'] = $paginator->getNavArray(); // reset date $dt = new DateTime($context['date']); if ($this->_context['ownerID']) { switch ($this->_context['ownerType']) { case "alliance": $involvedType = "involvedAlliances"; break; case "faction": $involvedType = "involvedFactions"; break; case "corp": case "corporation": $involvedType = "involvedCorporations"; break; case "char": case "character": case "pilot": $involvedType = "involvedCharacters"; break; default: throw new \Exception("Configuration has set unknown ownerType!"); return; } $kills = KillModel::find(array('$and' => array(array("killTime" => array('$gt' => new MongoDate($dt->getTimestamp()))), array("killTime" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp()))), array($involvedType => $this->_context['ownerID']))))->hint(array("killTime" => 1))->sort(array("killTime" => -1))->skip($paginator->getSkip())->limit(10); } else { $kills = KillModel::find(array('$and' => array(array("killTime" => array('$gt' => new MongoDate($dt->getTimestamp()))), array("killTime" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp()))))))->hint(array("killTime" => 1))->sort(array("killTime" => -1))->skip($paginator->getSkip())->limit(10); } $context['kills'] = $kills; $context['action'] = "/day/" . $context['date']; $dt = new DateTime($context['date']); $criteria = array('$and' => array(array("startdate" => array('$gt' => new MongoDate($dt->getTimestamp() - 1))), array("startdate" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp()))))); if ($this->_context['ownerID']) { $criteria['$or'] = array(array("ownerCharacter" => $this->_context['ownerID']), array("ownerCorporation" => $this->_context['ownerID']), array("ownerAlliance" => $this->_context['ownerID']), array("ownerFaction" => $this->_context['ownerID'])); } $battles = BattleSettings::find($criteria); // resolve collection to avoid count() of doom $context["battles"] = array(); foreach ($battles as $battle) { $context["battles"][] = $battle->toArray(); } $this->render("date/daily.html", $context); }