<commit_before><?php
namespace ProjectRena\Task\Resque;

use ProjectRena\RenaApp;
use ZMQ;
use ZMQContext;


/**
 * Upgrades the killjson in killmails to contain a load of extra information, meaning less querying happening on the frontend
 */
class upgradeKillmail
{

    /**
     * The Slim Application
     */

    /** @var RenaApp $app */
    private $app;

    /**
     * Performs the task, can access all $this->crap setup in setUp)
     */

    public function perform()
    {
        $killID = $this->args["killID"];

        if (!$killID)
            exit;

        $killData = $this->app->Db->queryRow("SELECT * FROM killmails WHERE killID = :killID", array(":killID" => $killID));
        $killHash = $killData["hash"];
        $killData = json_decode($killData["kill_json"], true);

        // Make sure it hasn't already been upgraded, if it has, exit.. this could happen if it's behind and the cron has already thrown more into the queue..
        $upgraded = $this->app->Db->queryField("SELECT upgraded FROM killmails WHERE killID = :killID", "upgraded", array(":killID" => $killID), 0);
        if ($upgraded == 1)
            exit;

        // If there is no XYZ refetch the data from CREST
        if (!isset($killData["victim"]["z"])) {
            $killMail = json_decode($this->app->cURL->getData("https://public-crest.eveonline.com/killmails/{$killID}/{$killHash}/"), true);
            $killData = $this->app->CrestFunctions->generateFromCREST(array("killID" => $killID, "killmail" => $killMail));
        }

        // Image server url
        $imageServer = $this->app->baseConfig->getConfig("imageServer", "ccp", "https://image.eveonline.com/");

        // The new killdata array that we will be building
        $nk = array();

        $nk["killID"] = (int)$killData["killID"];
        $nk["solarSystemID"] = (int)$killData["solarSystemID"];
        $nk["solarSystemName"] = $this->app->mapSolarSystems->getNameByID($killData["solarSystemID"]);
        $nk["regionID"] = (int)$this->app->mapSolarSystems->getRegionIDByID($killData["solarSystemID"]);
        $nk["regionName"] = $this->app->mapRegions->getRegionNameByRegionID($nk["regionID"]);
        $nk["near"] = $this->getNear($killData["victim"]["x"], $killData["victim"]["y"], $killData["victim"]["z"], $killData["solarSystemID"]);
        $nk["x"] = (float)$killData["victim"]["x"];
        $nk["y"] = (float)$killData["victim"]["y"];
        $nk["z"] = (float)$killData["victim"]["z"];
        $nk["moonID"] = (int)$killData["moonID"];
        $killValues = $this->app->Prices->calculateKillValue($killData);
        $nk["shipValue"] = (float)$killValues["shipValue"];
        $nk["fittingValue"] = (float)$killValues["itemValue"];
        $nk["totalValue"] = (float)$killValues["totalValue"];
        $nk["dna"] = $this->getDNA($killData["items"], $killData["victim"]["shipTypeID"]);

        // Victim Data
        $nk["victim"]["x"] = (float)$killData["victim"]["x"];
        $nk["victim"]["y"] = (float)$killData["victim"]["y"];
        $nk["victim"]["z"] = (float)$killData["victim"]["z"];<commit_msg>Move a few things around, and make it less error prone, plus refetch the data from CREST regardless of if we already have it.. don't trust anyone............<commit_after><?php
namespace ProjectRena\Task\Resque;

use ProjectRena\RenaApp;
use ZMQ;
use ZMQContext;


/**
 * Upgrades the killjson in killmails to contain a load of extra information, meaning less querying happening on the frontend
 */
class upgradeKillmail
{

    /**
     * The Slim Application
     */

    /** @var RenaApp $app */
    private $app;

    /**
     * Performs the task, can access all $this->crap setup in setUp)
     */

    public function perform()
    {
        $killID = $this->args["killID"];

        if (!$killID)
            exit;

        // Make sure it hasn't already been upgraded, if it has, exit.. this could happen if it's behind and the cron has already thrown more into the queue..
        $upgraded = $this->app->Db->queryField("SELECT upgraded FROM killmails WHERE killID = :killID", "upgraded", array(":killID" => $killID), 0);
        if ($upgraded == 1)
            exit;

        // Fetch the killmail data and lets get going with upgrading it!
        $killData = $this->app->Db->queryRow("SELECT * FROM killmails WHERE killID = :killID", array(":killID" => $killID), 0);
        $killHash = $killData["hash"];
        $killData = json_decode($killData["kill_json"], true);

        // refetch it from CREST unless CREST bugs out
        $killMail = json_decode($this->app->cURL->getData("https://public-crest.eveonline.com/killmails/{$killID}/{$killHash}/"), true);

        // Generate the killmail data if CREST returned valid data..
        if(!empty($killMail))
            $killData = $this->app->CrestFunctions->generateFromCREST(array("killID" => $killID, "killmail" => $killMail));

        // Image server url
        $imageServer = $this->app->baseConfig->getConfig("imageServer", "ccp", "https://image.eveonline.com/");

        // The new killdata array that we will be building
        $nk = array();

        $nk["killID"] = (int)$killData["killID"];
        $nk["solarSystemID"] = (int)$killData["solarSystemID"];
        $nk["solarSystemName"] = $this->app->mapSolarSystems->getNameByID($killData["solarSystemID"]);
        $nk["regionID"] = (int)$this->app->mapSolarSystems->getRegionIDByID($killData["solarSystemID"]);
        $nk["regionName"] = $this->app->mapRegions->getRegionNameByRegionID($nk["regionID"]);
        $nk["near"] = $this->getNear($killData["victim"]["x"], $killData["victim"]["y"], $killData["victim"]["z"], $killData["solarSystemID"]);
        $nk["x"] = (float)$killData["victim"]["x"];
        $nk["y"] = (float)$killData["victim"]["y"];
        $nk["z"] = (float)$killData["victim"]["z"];
        $nk["moonID"] = (int)$killData["moonID"];
        $killValues = $this->app->Prices->calculateKillValue($killData);
        $nk["shipValue"] = (float)$killValues["shipValue"];
        $nk["fittingValue"] = (float)$killValues["itemValue"];
        $nk["totalValue"] = (float)$killValues["totalValue"];
        $nk["dna"] = $this->getDNA($killData["items"], $killData["victim"]["shipTypeID"]);

        // Victim Data
        $nk["victim"]["x"] = (float)$killData["victim"]["x"];
        $nk["victim"]["y"] = (float)$killData["victim"]["y"];
        $nk["victim"]["z"] = (float)$killData["victim"]["z"];
{'fraction_non_alphanumeric': 0.19589871057946248, 'fraction_numerical': 0.0007767593599502874, 'mean_word_length': 3.3915416098226467, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4993634', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2050, 'n_words': 429}