<commit_before><?php
/**
 * @copyright Copyright (C) 2015 <NAME>
 * @license https://github.com/fetus-hina/stat.ink/blob/master/LICENSE MIT
 * @author <NAME> <<EMAIL>>
 */

namespace app\models;

use Yii;

/**
 * This is the model class for table "agent".
 *
 * @property integer $id
 * @property string $name
 * @property string $version
 *
 * @property Battle[] $battles
 */
class Agent extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'agent';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'version'], 'required'],
            [['name'], 'string', 'max' => 64],
            [['version'], 'string', 'max' => 255],
            [['name', 'version'], 'unique',
                'targetAttribute' => ['name', 'version'],
                'message' => 'The combination of Name and Version has already been taken.']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'version' => 'Version',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBattles()
    {
        return $this->hasMany(Battle::class, ['agent_id' => 'id']);
    }

    public function getIsAutomatedByDefault()
    {
        $attr = AgentAttribute::findOne(['name' => (string)$this->name]);
        if ($attr && $attr->is_automated) {
            return true;
        }
        return false;
    }

    public function getIsIkalog()
    {
        return $this->name === 'IkaLog' || $this->name === 'TakoLog';
    }

    public function getIsOldIkalogAsAtTheTime($t = null)
    {
        if ($t === null) {
            $t = $_SERVER['REQUEST_TIME'] ?? time();
        } elseif (is_string($t)) {
            $t = strtotime($t);
        } else {
            $t = (int)$t;
        }
        if (!$this->getIsIkalog()) {
            return false;
        }
        if (preg_match('/^unknown\b/', $this->version)) {
            return false;
        }
        return preg_match('/_Win(?:Ika|Tako)Log$/', $this->version)
            ? $this->getIsOldWinIkalogAsAtTheTime($t)
            : $this->getIsOldCliIkalogAsAtTheTime($t);
    }

    static private $latestWinIkaLog;
    private function getIsOldWinIkalogAsAtTheTime($t)
    {
        if (!preg_match('/^([0-9a-f]{7,})_/', $this->version, $match)) {
            // なんかおかしい
            return false;
        }
<commit_msg>refs #74, IkaLogバージョン警告を一旦停止<commit_after><?php
/**
 * @copyright Copyright (C) 2015 <NAME>
 * @license https://github.com/fetus-hina/stat.ink/blob/master/LICENSE MIT
 * @author <NAME> <<EMAIL>>
 */

namespace app\models;

use Yii;

/**
 * This is the model class for table "agent".
 *
 * @property integer $id
 * @property string $name
 * @property string $version
 *
 * @property Battle[] $battles
 */
class Agent extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'agent';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'version'], 'required'],
            [['name'], 'string', 'max' => 64],
            [['version'], 'string', 'max' => 255],
            [['name', 'version'], 'unique',
                'targetAttribute' => ['name', 'version'],
                'message' => 'The combination of Name and Version has already been taken.']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'version' => 'Version',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBattles()
    {
        return $this->hasMany(Battle::class, ['agent_id' => 'id']);
    }

    public function getIsAutomatedByDefault()
    {
        $attr = AgentAttribute::findOne(['name' => (string)$this->name]);
        if ($attr && $attr->is_automated) {
            return true;
        }
        return false;
    }

    public function getIsIkalog()
    {
        return $this->name === 'IkaLog' || $this->name === 'TakoLog';
    }

    public function getIsOldIkalogAsAtTheTime($t = null)
    {
        return false;

        if ($t === null) {
            $t = $_SERVER['REQUEST_TIME'] ?? time();
        } elseif (is_string($t)) {
            $t = strtotime($t);
        } else {
            $t = (int)$t;
        }
        if (!$this->getIsIkalog()) {
            return false;
        }
        if (preg_match('/^unknown\b/', $this->version)) {
            return false;
        }
        return preg_match('/_Win(?:Ika|Tako)Log$/', $this->version)
            ? $this->getIsOldWinIkalogAsAtTheTime($t)
            : $this->getIsOldCliIkalogAsAtTheTime($t);
    }

    static private $latestWinIkaLog;
    private function getIsOldWinIkalogAsAtTheTime($t)
    {
        if (!preg_match('/^([0-9a-f]{7,})_/', $this->version, $match)) {
            // なんかおかしい
            return false;
        }

{'fraction_non_alphanumeric': 0.17062256809338522, 'fraction_numerical': 0.005058365758754864, 'mean_word_length': 1.8752796420581654, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, 'https://': 2, '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': '459143', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1636, 'n_words': 334}