function execQuery() { if ($this->executed_) { return; } $this->executed_ = True; $this->klist_->addSystem($this->system_); $this->llist_->addSystem($this->system_); $this->klist_->setStartDate($this->ctr_started_); $this->klist_->setEndDate($this->ctr_ended_); $this->llist_->setStartDate($this->ctr_started_); $this->llist_->setEndDate($this->ctr_ended_); // if manual side assignment is enabled if (config::get("fleet_battles_mod_sideassign")) { // get possible side assignments $sideAssignments = getSideAssignments($this->system_->getID(), $this->ctr_started_, $this->ctr_ended_); // apply foreach ($sideAssignments as $sideAssignment) { // entity is an alliance if ($sideAssignment["entity_type"] == "alliance") { // alliance is an enemy if ($sideAssignment["side"] == "e") { $this->klist_->addVictimAlliance($sideAssignment["entity_id"]); $this->llist_->addInvolvedAlliance($sideAssignment["entity_id"]); } else { $this->klist_->addInvolvedAlliance($sideAssignment["entity_id"]); $this->llist_->addVictimAlliance($sideAssignment["entity_id"]); } } else { // alliance is an enemy if ($sideAssignment["side"] == "e") { $this->klist_->addVictimCorp($sideAssignment["entity_id"]); $this->llist_->addInvolvedCorp($sideAssignment["entity_id"]); } else { $this->klist_->addInvolvedCorp($sideAssignment["entity_id"]); $this->llist_->addVictimCorp($sideAssignment["entity_id"]); } } } } $this->pilots_ = array('a' => array(), 'e' => array()); $destroyed = array(); $sides = array(); while ($kill = $this->klist_->getKill()) { handle_involved($kill, 'a', $this->pilots_, FALSE); handle_destroyed($kill, 'e', $destroyed, $this->pilots_, FALSE); } while ($kill = $this->llist_->getKill()) { handle_involved($kill, 'e', $this->pilots_, FALSE); handle_destroyed($kill, 'a', $destroyed, $this->pilots_, FALSE); } $this->llist_->rewind(); $this->klist_->rewind(); $this->involved_ = count($this->pilots_['a']) + count($this->pilots_['e']); }
public function buildStats() { // this is a fast query to get the system and timestamp $rqry = DBFactory::getDBQuery(); if ($this->adjacent) { $rsql = 'SELECT kll_timestamp, sjp_to as sys_id from kb3_kills join kb3_systems a ON (a.sys_id = kll_system_id) join kb3_system_jumps on (sjp_from = a.sys_id) where kll_id = ' . $this->kll_id . ' UNION SELECT kll_timestamp, kll_system_id as sys_id from kb3_kills where kll_id = ' . $this->kll_id; } else { $rsql = 'SELECT kll_timestamp, kll_system_id as sys_id from kb3_kills where kll_id = ' . $this->kll_id; } $rqry->execute($rsql); while ($rrow = $rqry->getRow()) { $this->systems[] = $rrow['sys_id']; $basetime = $rrow['kll_timestamp']; } // now we get all kills in that system for +-4 hours $query = 'SELECT kll.kll_timestamp AS ts FROM kb3_kills kll WHERE kll.kll_system_id IN (' . implode(',', $this->systems) . ') AND kll.kll_timestamp <= "' . date('Y-m-d H:i:s', strtotime($basetime) + config::get('fleet_battles_mod_maxtime') * 60 * 60) . '"' . ' AND kll.kll_timestamp >= "' . date('Y-m-d H:i:s', strtotime($basetime) - config::get('fleet_battles_mod_maxtime') * 60 * 60) . '"' . ' ORDER BY kll.kll_timestamp ASC'; $qry = DBFactory::getDBQuery(); $qry->execute($query); $ts = array(); $timestampsRaw = array(); while ($row = $qry->getRow()) { $time = strtotime($row['ts']); $ts[intval(date('H', $time))][] = $row['ts']; $timestampsRaw[] = $row["ts"]; } // only for non-battles if (!$this->displayingBattle) { // this tricky thing looks for gaps of more than 1 hour and creates an intersection $baseh = date('H', strtotime($basetime)); $maxc = count($ts); $times = array(); for ($i = 0; $i < $maxc; $i++) { $h = ($baseh + $i) % 24; if (!isset($ts[$h])) { break; } foreach ($ts[$h] as $timestamp) { $times[] = $timestamp; } } for ($i = 0; $i < $maxc; $i++) { $h = ($baseh - $i) % 24; if ($h < 0) { $h += 24; } if (!isset($ts[$h])) { break; } foreach ($ts[$h] as $timestamp) { $times[] = $timestamp; } } unset($ts); asort($times); // we got 2 resulting timestamps $this->firstts = array_shift($times); $this->lastts = array_pop($times); } else { // take the first and last timestamp from our original query $this->firstts = array_shift($timestampsRaw); $this->lastts = array_pop($timestampsRaw); } // get parameters for overriding start and end times // dirty hook for the enlightened circle ;) $overrideStartTime = str_replace('%20', ' ', edkURI::getArg('starttime')); $overrideEndTime = str_replace('%20', ' ', edkURI::getArg('endtime')); if ($overrideStartTime && strtotime($overrideStartTime)) { $this->firstts = $overrideStartTime; } if ($overrideEndTime && strtotime($overrideEndTime)) { $this->lastts = $overrideEndTime; } // unfiltered kill list (no ship class filter applied) $this->kslist = new KillList(); $this->kslist->setOrdered(true); foreach ($this->systems as $system) { $this->kslist->addSystem($system); } $this->kslist->setStartDate($this->firstts); $this->kslist->setEndDate($this->lastts); involved::load($this->kslist, 'kill'); // unfiltered loss list (no ship class filter applied) $this->lslist = new KillList(); $this->lslist->setOrdered(true); foreach ($this->systems as $system) { $this->lslist->addSystem($system); } $this->lslist->setStartDate($this->firstts); $this->lslist->setEndDate($this->lastts); involved::load($this->lslist, 'loss'); // filtered kill list (shipclass filter applied) $this->klist = new KillList(); $this->klist->setOrdered(true); $this->klist->setCountComments(true); $this->klist->setCountInvolved(true); foreach ($this->systems as $system) { $this->klist->addSystem($system); } $this->klist->setStartDate($this->firstts); $this->klist->setEndDate($this->lastts); involved::load($this->klist, 'kill'); // filtered loss list (ship class filter applied) $this->llist = new KillList(); $this->llist->setOrdered(true); $this->llist->setCountComments(true); $this->llist->setCountInvolved(true); foreach ($this->systems as $system) { $this->llist->addSystem($system); } $this->llist->setStartDate($this->firstts); $this->llist->setEndDate($this->lastts); involved::load($this->llist, 'loss'); // apply ship class filters if ($this->scl_id) { $this->klist->addVictimShipClass($this->scl_id); $this->llist->addVictimShipClass($this->scl_id); } // if manual side assignment is enabled if (config::get("fleet_battles_mod_sideassign")) { // get possible side assignments $sideAssignments = getSideAssignments($this->systems[0], $this->firstts, $this->lastts); $sideAssignmentMap = array(); // apply foreach ($sideAssignments as $sideAssignment) { $this->isFixed = TRUE; $sideAssignmentMap[$sideAssignment["entity_type"]][$sideAssignment["entity_id"]] = $sideAssignment["side"]; // entity is an alliance if ($sideAssignment["entity_type"] == "alliance") { // alliance is an enemy if ($sideAssignment["side"] == "e") { $this->kslist->addVictimAlliance($sideAssignment["entity_id"]); $this->lslist->addInvolvedAlliance($sideAssignment["entity_id"]); $this->klist->addVictimAlliance($sideAssignment["entity_id"]); $this->llist->addInvolvedAlliance($sideAssignment["entity_id"]); } else { $this->kslist->addInvolvedAlliance($sideAssignment["entity_id"]); $this->lslist->addVictimAlliance($sideAssignment["entity_id"]); // also add as involved alliance for blue-on-blue kills $this->lslist->addInvolvedAlliance($sideAssignment["entity_id"]); $this->klist->addInvolvedAlliance($sideAssignment["entity_id"]); $this->llist->addVictimAlliance($sideAssignment["entity_id"]); // also add as involved alliance for blue-on-blue kills $this->llist->addInvolvedAlliance($sideAssignment["entity_id"]); } } else { // alliance is an enemy if ($sideAssignment["side"] == "e") { $this->kslist->addVictimCorp($sideAssignment["entity_id"]); $this->lslist->addInvolvedCorp($sideAssignment["entity_id"]); $this->klist->addVictimCorp($sideAssignment["entity_id"]); $this->llist->addInvolvedCorp($sideAssignment["entity_id"]); } else { $this->kslist->addInvolvedCorp($sideAssignment["entity_id"]); $this->lslist->addVictimCorp($sideAssignment["entity_id"]); // also add as involved alliance for blue-on-blue kills $this->lslist->addInvolvedCorp($sideAssignment["entity_id"]); $this->klist->addInvolvedCorp($sideAssignment["entity_id"]); $this->llist->addVictimCorp($sideAssignment["entity_id"]); // also add as involved alliance for blue-on-blue kills $this->llist->addInvolvedCorp($sideAssignment["entity_id"]); } } } } // we need a summary table first $this->summaryTable = new KillSummaryTable($this->kslist, $this->lslist); $this->summaryTable->generate(); $this->destroyed = array(); $this->lossValues = array(); $this->killValues = array(); $this->pilots = array('a' => array(), 'e' => array()); $this->klist->rewind(); $this->damageOverview = array('a' => array(), 'e' => array()); $totalKillIsk = $this->summaryTable->getTotalKillISK(); while ($kill = $this->klist->getKill()) { handle_involved($kill, 'a', $this->pilots, $sideAssignmentMap, TRUE); handle_destroyed($kill, 'e', $this->destroyed, $this->pilots, $sideAssignmentMap, TRUE); // gather data for battle timeline and loss value lists // for better performance we use this loop so we won't have to loop over the same data again // --------------------------------------------------------------------------------------- // gathering kill values // --------------------------------------------------------------------------------------- // we dont want our own people on the enemy's side! if (in_array($kill->getVictimAllianceID(), config::get('cfg_allianceid')) || in_array($kill->getVictimCorpID(), config::get('cfg_corpid')) || in_array($kill->getVictimID(), config::get('cfg_pilotid'))) { continue; } $lossValueRaw = $kill->getISKLoss(); $lossValue = self::formatIskValue($lossValueRaw); if ($totalKillIsk != 0) { $percentualLossValue = number_format($lossValueRaw / $totalKillIsk * 100, 2); } else { $percentualLossValue = 0.0; } if ($lossValueRaw > 0) { $this->killValues[] = array("victimName" => $kill->getVictimName(), "victimID" => $kill->getVictimID(), "victimUrl" => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), "victimShipName" => $kill->getVictimShipName(), "victimShipImage" => imageUrl::getURL("Ship", $kill->getVictimShipID(), 32), "victimShipClass" => $kill->getVictimShipClassName(), "victimCorpName" => $kill->getVictimCorpName(), "victimCorpID" => $kill->getVictimCorpID(), "victimCorpUrl" => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), "victimAllianceName" => $kill->getVictimAllianceName(), "victimAllianceID" => $kill->getVictimAllianceID(), "victimAllianceUrl" => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), "killId" => $kill->getID(), "killUrl" => edkURI::page("kill_detail", $kill->getID(), "kll_id"), "lossValueRaw" => $lossValueRaw, "lossValue" => $lossValue, "lossValuePercentage" => $percentualLossValue); } // --------------------------------------------------------------------------------------- // gathering timeline data // --------------------------------------------------------------------------------------- $killTimestamp = strtotime($kill->getTimeStamp()); // increase killtimestamp for pods so they appear AFTER the ship kill in the timeline $shipClassId = $kill->getVictimShip()->getClass()->getID(); if ($shipClassId == 18 || $shipClassId == 2) { $killTimestamp += 1; } $this->timeLine[] = array("timestamp" => $killTimestamp, "loss" => NULL, "kill" => array("victimName" => $kill->getVictimName(), "victimID" => $kill->getVictimID(), "victimUrl" => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), "victimShipName" => $kill->getVictimShipName(), "victimShipImage" => imageUrl::getURL("Ship", $kill->getVictimShipID(), 32), "victimShipClass" => $kill->getVictimShipClassName(), "victimCorpName" => $kill->getVictimCorpName(), "victimCorpID" => $kill->getVictimCorpID(), "victimCorpUrl" => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), "victimAllianceName" => $kill->getVictimAllianceName(), "victimAllianceID" => $kill->getVictimAllianceID(), "victimAllianceUrl" => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), "killId" => $kill->getID(), "killUrl" => edkURI::page("kill_detail", $kill->getID(), "kll_id"))); // --------------------------------------------------------------------------------------- // gathering damage overview data // --------------------------------------------------------------------------------------- $this->damageOverview["a"][] = array("victimName" => $kill->getVictimName(), "victimID" => $kill->getVictimID(), "victimUrl" => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), "victimShipName" => $kill->getVictimShipName(), "victimShipImage" => imageUrl::getURL("Ship", $kill->getVictimShipID(), 32), "victimShipClass" => $kill->getVictimShipClassName(), "victimCorpName" => $kill->getVictimCorpName(), "victimCorpID" => $kill->getVictimCorpID(), "victimCorpUrl" => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), "victimAllianceName" => $kill->getVictimAllianceName(), "victimAllianceID" => $kill->getVictimAllianceID(), "victimAllianceUrl" => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), "killId" => $kill->getID(), "killUrl" => edkURI::page("kill_detail", $kill->getID(), "kll_id"), "lossValueRaw" => $lossValueRaw, "lossValue" => $lossValue, "lossValuePercentage" => $percentualLossValue); } $this->llist->rewind(); $totalLossIsk = $this->summaryTable->getTotalLossISK(); while ($kill = $this->llist->getKill()) { handle_involved($kill, 'e', $this->pilots, $sideAssignmentMap, TRUE); handle_destroyed($kill, 'a', $this->destroyed, $this->pilots, $sideAssignmentMap, TRUE); // gather data for battle timeline and loss value lists // for better performance we use this loop so we won't have to loop over the same data again // --------------------------------------------------------------------------------------- // gathering loss values // --------------------------------------------------------------------------------------- $lossValueRaw = $kill->getISKLoss(); $lossValue = self::formatIskValue($lossValueRaw); if ($totalLossIsk != 0) { $percentualLossValue = number_format($lossValueRaw / $totalLossIsk * 100, 2); } else { $percentualLossValue = 0.0; } if ($lossValueRaw > 0) { $this->lossValues[] = array("victimName" => $kill->getVictimName(), "victimID" => $kill->getVictimID(), "victimUrl" => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), "victimShipName" => $kill->getVictimShipName(), "victimShipImage" => imageUrl::getURL("Ship", $kill->getVictimShipID(), 32), "victimShipClass" => $kill->getVictimShipClassName(), "victimCorpName" => $kill->getVictimCorpName(), "victimCorpID" => $kill->getVictimCorpID(), "victimCorpUrl" => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), "victimAllianceName" => $kill->getVictimAllianceName(), "victimAllianceID" => $kill->getVictimAllianceID(), "victimAllianceUrl" => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), "killId" => $kill->getID(), "killUrl" => edkURI::page("kill_detail", $kill->getID(), "kll_id"), "lossValueRaw" => $lossValueRaw, "lossValue" => $lossValue, "lossValuePercentage" => $percentualLossValue); } // --------------------------------------------------------------------------------------- // gathering timeline data // --------------------------------------------------------------------------------------- $killTimestamp = strtotime($kill->getTimeStamp()); $shipClassId = $kill->getVictimShip()->getClass()->getID(); $this->timeLine[] = array("timestamp" => strtotime($kill->getTimeStamp()), "loss" => array("victimName" => $kill->getVictimName(), "victimID" => $kill->getVictimID(), "victimUrl" => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), "victimShipName" => $kill->getVictimShipName(), "victimShipImage" => imageUrl::getURL("Ship", $kill->getVictimShipID(), 32), "victimShipClass" => $kill->getVictimShipClassName(), "victimCorpName" => $kill->getVictimCorpName(), "victimCorpID" => $kill->getVictimCorpID(), "victimCorpUrl" => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), "victimAllianceName" => $kill->getVictimAllianceName(), "victimAllianceID" => $kill->getVictimAllianceID(), "victimAllianceUrl" => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), "killId" => $kill->getID(), "killUrl" => edkURI::page("kill_detail", $kill->getID(), "kll_id")), "kill" => NULL); } //echo "<pre>"; var_dump($this->pilots); echo "</pre>"; // sort pilot ships, order pods after ships foreach ($this->pilots as $side => $pilot) { foreach ($pilot as $id => $kll) { usort($this->pilots[$side][$id], array($this, 'cmp_ts_func')); } } // sort arrays, ships with high points first uasort($this->pilots['a'], array($this, 'cmp_func')); uasort($this->pilots['e'], array($this, 'cmp_func')); // now get the pods out and mark the ships the've flown as podded foreach ($this->pilots as $side => $pilot) { foreach ($pilot as $id => $kll) { $max = count($kll); for ($i = 0; $i < $max; $i++) { // add up total damage for each side if ($side == "a") { if (isset($kll[$i]["damage"])) { $this->damageTotalFriendly += $kll[$i]["damage"]; } } else { if (isset($kll[$i]["damage"])) { $this->damageTotalHostile += $kll[$i]["damage"]; } } // this kill has a pod as ship if ($kll[$i]['shipClass'] == 'Capsule') { // this pilot made previous kills in another ship if (isset($kll[$i - 1]['sid'])) { // this kill is a pod loss if (isset($kll[$i]['destroyed'])) { $this->pilots[$side][$id][$i - 1]['podded'] = true; $this->pilots[$side][$id][$i - 1]['podid'] = $kll[$i]['kll_id']; $this->pilots[$side][$id][$i - 1]['pod_url'] = edkURI::page("kill_detail", $kll[$i]['kll_id'], "kll_id"); unset($this->pilots[$side][$id][$i]); } else { // update stats for previously used ship $this->pilots[$side][$id][$i - 1]['times'] += $this->pilots[$side][$id][$i]['times']; $this->pilots[$side][$id][$i - 1]['damage'] += $this->pilots[$side][$id][$i]['damage']; unset($this->pilots[$side][$id][$i]); } } } } } } // update battles with current stats $this->updateBattles(); }