function mysql_query_cache($sql, $linkIdentifier = false, $timeout = MEMCACHE_STATICDATA_TIMEOUT, $goSilent = true) { global $memCache; if (is_null($memCache)) { mc_open(); } if (($cache = getCache(md5("mysql_query" . $sql))) === false) { if (!$goSilent) { dprintf("mysql_query_cache(): using MySQL data.", $sql); } $cache = false; $r = $linkIdentifier !== false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql); if (is_resource($r) && ($rows = mysql_num_rows($r)) !== 0) { while ($row = mysql_fetch_assoc($r)) { $results[] = $row; } $cache = serialize($results); if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) { # If we get here, there isn't a memcache daemon running or responding if (!$goSilent) { dprintf("mysql_query_cache(): failed to update memcached"); } } mysql_free_result($r); } } else { if (!$goSilent) { dprintf("mysql_query_cache(): using memcached data."); } } return unserialize($cache); }
} else { printf(". "); } } } } } else { // No top corp, so not enough data to do anything! printf("<p>No kills recorded in this system in the past %d months. No intel analysis is possible.</p>", EVEKILL_ANALYSIS_MAX_MONTH_HISTORY); } } } else { // Killboard was invalid, probably a problem querying evekill printf('<p class="fatalerror">Unable to query Eve-Kill data at this time - please try again later.</p>'); } dprintf("intel_evekill_analysis - Finished."); printf("</div>"); } // ======================================================================== } elseif ($action == "intel_pilotinfo") { // ======================================================================== $n_PilotID = trim(mysql_real_escape_string($_REQUEST["id"])); $n_PilotName = urldecode(trim($_REQUEST["name"])); // Note: The double-DIV is required because the AJAX re-AJAXer won't get the "rel" otherwise printf('<div class="gBox">'); printf('<div class="gImg" rel="%s"><img src="/images/gimg_placeholder.jpg" width="%d" height="%d" border="0"/></div>', sprintf(EVE_API_PILOT_IMAGE_LOOKUP_URL, $n_PilotID, EVE_API_IMAGE_XY), EVE_API_IMAGE_XY, EVE_API_IMAGE_XY); printf('<div class="gData">'); printf('<div class="gName">%s</div>', $n_PilotName); printf('<p class="igLinks">Contact List:<br/><a href="javascript:void(0)" onClick="CCPEVE.showInfo(1377, %d)">Show Info</a> – <a href="javascript:void(0)" onClick="javascript:CCPEVE.addContact(%d)">Add</a> – <a href="javascript:void(0)" onClick="javascript:CCPEVE.addCorpContact(%d)">Add Corp</a></p>', $n_PilotID, $n_PilotID, $n_PilotID); printf('<p><a href="%s" target="_blank" alt="Eve-Kill details for %s">Eve-Kill</a></p>', sprintf(EVEKILL_PILOT_URL, $n_PilotID), $n_PilotName); printf('<p><a href="%s" target="_blank" alt="zKillboard details for %s">zKillboard</a></p>', sprintf(ZKB_PILOT_URL, $n_PilotName), $n_PilotName);
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'); } }