예제 #1
0
 private function calcResidency()
 {
     $oldestKill = $this->res_metrics["oldestKill"];
     $latestKill = $this->res_metrics["newestKill"];
     $rsAry = array();
     if ($oldestKill && $latestKill && sizeof($this->corp) > 0) {
         $sysKillTimeSpan = strtotime($latestKill->timestamp) - strtotime($oldestKill->timestamp);
         // Create new wormhole object, for checking capital use in lower class
         $aTempWH = new Wormhole($this->uniqID);
         foreach ($this->corp as $aCorp) {
             // NPC corporations can't be resident (obviously Sleepers are :) )
             if ($aCorp->isNPCCorporation()) {
                 continue;
             }
             // Create/update alliance object
             if (!($aCorp->allianceID == 0 || $aCorp->allianceID == NO_ALLIANCE_ALLIANCE_ID)) {
                 if (is_null($aAlliance =& $this->getAllianceRM($aCorp->allianceName))) {
                     $this->res_metrics["alliance"][] = array("alliance_name" => &$aCorp->allianceName, "corp_count" => 1);
                 } else {
                     $aAlliance["corp_count"]++;
                 }
             }
             // Weigh each battle according to how long ago it occured
             $battleCount = 0;
             foreach ($aCorp->battle as $aBattle) {
                 //dprintf("[%s] battle time: %s, <i>it</i>: %d, <i>k</i>: %f, <i>t</i>: %d, <i>N<sub>0</sub></i>: %d, expo. decay: %f", $aCorp->corporationName, $aBattle->timestamp, $sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, (strtotime($latestKill->timestamp) - strtotime($aBattle->timestamp)), SCORE_MAX_SCORE_FOR_BATTLE, $this->ed($sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, (strtotime($latestKill->timestamp) - strtotime($aBattle->timestamp)), SCORE_MAX_SCORE_FOR_BATTLE));
                 $aCorp->residency["score"] += $this->ed($sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, strtotime($latestKill->timestamp) - strtotime($aBattle->timestamp), SCORE_MAX_SCORE_FOR_BATTLE + ++$battleCount * SCORE_MULTIPLE_BATTLE_INCREMENT);
             }
             // Add weight to residency score for kills where corp's POS was either a killer or a victim
             $posKills = $this->getPOSCombatActivity($aCorp);
             if (sizeof($posKills) > 0) {
                 foreach ($posKills as $aPOSKill) {
                     dprintf('[%s] POS was involved in a %s on %s - <a href="%s" target="_blank">here</a>', $aCorp->corporationName, $aPOSKill["isVictim"] == 1 ? "LOSS" : "KILL", $aPOSKill["kill"]->timestamp, $aPOSKill["kill"]->url);
                     $aCorp->residency["score"] += $this->ed($sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, strtotime($latestKill->timestamp) - strtotime($aPOSKill["kill"]->timestamp), SCORE_SKEW_POS_COMBAT_ACTIVITY);
                     $aCorp->residency["posactvy"][] = $aPOSKill;
                 }
             }
             // If wormhole is class 4 or lower, and this corp has used a capital, it's a good
             // assumption that they are or have been resident at some point.
             if ($aTempWH->isValidLocus() && $aTempWH->isWHLocus()) {
                 if ($aTempWH->getSysClass() <= 4) {
                     $capUsageDB = $this->getActivityInvolvingCaps($aCorp->corporationName, true);
                     if (sizeof($capUsageDB) > 0) {
                         dprintf("[%s] Corp has used a cap %d times in a <= C4 wormhole", $aCorp->corporationName, sizeof($capUsageDB));
                         foreach ($capUsageDB as $aKillWithCap) {
                             $aCorp->residency["score"] += $this->ed($sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, strtotime($latestKill->timestamp) - strtotime($aKillWithCap["kill"]->timestamp), SCORE_SKEW_CAPITAL_USE_IN_LOWCLASS_WH);
                             $aCorp->residency["caplcuse"][] = $aKillWithCap["kill"];
                         }
                     }
                 }
                 // Skew for InterBus Customs Office activity
                 $IBCOKillDB = $this->getInterBusCOKills($aCorp);
                 if (sizeof($IBCOKillDB) > 0) {
                     dprintf("[%s] Corp has killed %d InterBus C.Os in this system", $aCorp->corporationName, sizeof($IBCOKillDB));
                     foreach ($IBCOKillDB as $aIBCOKill) {
                         $aCorp->residency["score"] += $this->ed($sysKillTimeSpan, SCORE_EXPONENTIAL_DECAY_RATE, strtotime($latestKill->timestamp) - strtotime($aIBCOKill->timestamp), SCORE_SKEW_INTERBUS_CO_KILL);
                         $aCorp->residency["ibcokills"][] = $aIBCOKill;
                     }
                 }
             }
             // Check eviction status for each corp
             if (!is_null($aCorp->residency["evicted"] = $this->calcEviction($aCorp, EVEKILL_ANALYSIS_MAX_MONTH_HISTORY))) {
                 if ($aCorp->residency["evicted"]["ppl_score"] >= SCORE_RES_STILL_RES_THRESHOLD_SCORE) {
                     dprintf("[%s] Corp lost tower(s), but appeared to rally and remain resident? (still res weight: %f)", $aCorp->corporationName, $aCorp->residency["evicted"]["ppl_score"]);
                     // Include this corps score in array for stddev calc
                     $rsAry[] = $aCorp->residency["score"];
                 } else {
                     // If evicted zero score to eliminate them from standard deviation checks to allow us to find the current resident
                     dprintf("[%s] Corp is evicted. (%f)", $aCorp->corporationName, $aCorp->residency["evicted"]["ppl_score"]);
                     //$aCorp->residency["score"] = 0;
                 }
             } else {
                 // Include this corps score in array for stddev calc
                 $rsAry[] = $aCorp->residency["score"];
             }
         }
         // Populate total residency score metric in killboard
         $this->res_metrics["totalScore"] = $this->getTotalResidencyScore();
         // Calculate stddev, z-score and percentile
         $resStdDev = sd($rsAry);
         foreach ($this->corp as $aCorp) {
             $aCorp->residency["stddev"] = $resStdDev;
             $aCorp->residency["z-score"] = ($aCorp->residency["score"] - $this->res_metrics["totalScore"] / sizeof($this->corp)) / $aCorp->residency["stddev"];
             $aCorp->residency["z-perc"] = cdf($aCorp->residency["z-score"]) * 100;
         }
         // Sort the corp table by residency score descending order
         usort($this->corp, 'rcmp');
     }
 }