<commit_before><?php
abstract class Vps_Util_Rrd_File
{
    private $_fields = array();
    private $_fileName;
    private $_interval = 60;
    private $_timeZone = null;

    public function __construct($fileName)
    {
        $this->_fileName = $fileName;
    }

    public function getTitle()
    {
        return $this->getFileName();
    }

    public function getFileName()
    {
        return $this->_fileName;
    }

    public function addField($f)
    {
        if (!($f instanceof Vps_Util_Rrd_Field)) {
            $f = new Vps_Util_Rrd_Field($f);
        }
        $this->_fields[] = $f;
    }

    public function getField($name)
    {
        foreach ($this->_fields as $f) {
            if ($f->nameEquals($name)) return $f;
        }
        return null;
    }

    public function getFields()
    {
        return $this->_fields;
    }

    public function setInterval($i)
    {
        $this->_interval = $i;
    }

    //im moment nur für graph
    public function setTimeZone($i)
    {
        $this->_timeZone = $i;
    }

    public function getTimeZone()
    {
        return $this->_timeZone;
    }

    protected function getRRAs()
    {
        return array(
            array(
                //1 woche (bei interval von 60)
                'steps' => 1,
                'rows' => 2016
            ),
            array(
                //1 monat (bei interval von 60)
                'steps' => 7,
                'rows' => 1500
            ),
            array(
                //1 jahr (bei interval von 60)
                'steps' => 50,
                'rows' => 2500
            ),
        );
    }

    public function createFile($start)
    {
        if (file_exists($this->_fileName)) {
            throw new Vps_Exception("$this->_fileName already exists");
        }
        $cmd = "rrdtool create $this->_fileName ";
        $cmd .= "--start ".$start." ";
        $cmd .= "--step ".($this->_interval)." ";
        foreach ($this->_fields as $field) {
            if (!is_null($field->getHeartbeat())) {
                $heartbeat = $field->getHeartbeat();
            } else {
                $heartbeat = ($this->_interval*2);
            }
            $cmd .= "DS:".$field->getName().":".$field->getType().":".$heartbeat.":".$field->getMin().":".($field->getMax())." ";
        }
        foreach ($this->getRRAs() as $rra) {
            if (!isset($rra['method'])) $rra['method'] = 'AVERAGE';
            if (!isset($rra['xff'])) $rra['xff'] = '0.6';
            $cmd .= "RRA:$rra[method]:$rra[xff]:$rra[steps]:$rra[rows] ";
        }
        system($cmd, $ret);
        if ($ret != 0) throw new Vps_Exception("Command failed");
    }

    protected function _getMemcache()
    {
        if (!isset($this->_memcache)) {
            $this->_memcache = new Memcache;
            $memcacheSettings = Vps_Registry::get('config')->server->memcache;
            $this->_memcache->addServer($memcacheSettings->host, $memcacheSettings->port);
        }
        return $this->_memcache;
    }

    protected function _getMemcacheValue($field)
    {
        $prefix = Zend_Registry::get('config')->application->id.'-'.
                            Vps_Setup::getConfigSection().'-bench-';
        $value = $this->_getMemcache()->get($prefix.$field);
        if ($value===false) $value = '0';
        return $value;
    }

    abstract public function getRecordValues();

    public function record()
    {
        $values = $this->getRecordValues();

        if (!file_exists($this->_fileName)) {
            $this->createFile(time()-1);
        }
<commit_msg>wenn false dann U nicht 0, sonst hauts uns die statistiken zaum<commit_after><?php
abstract class Vps_Util_Rrd_File
{
    private $_fields = array();
    private $_fileName;
    private $_interval = 60;
    private $_timeZone = null;

    public function __construct($fileName)
    {
        $this->_fileName = $fileName;
    }

    public function getTitle()
    {
        return $this->getFileName();
    }

    public function getFileName()
    {
        return $this->_fileName;
    }

    public function addField($f)
    {
        if (!($f instanceof Vps_Util_Rrd_Field)) {
            $f = new Vps_Util_Rrd_Field($f);
        }
        $this->_fields[] = $f;
    }

    public function getField($name)
    {
        foreach ($this->_fields as $f) {
            if ($f->nameEquals($name)) return $f;
        }
        return null;
    }

    public function getFields()
    {
        return $this->_fields;
    }

    public function setInterval($i)
    {
        $this->_interval = $i;
    }

    //im moment nur für graph
    public function setTimeZone($i)
    {
        $this->_timeZone = $i;
    }

    public function getTimeZone()
    {
        return $this->_timeZone;
    }

    protected function getRRAs()
    {
        return array(
            array(
                //1 woche (bei interval von 60)
                'steps' => 1,
                'rows' => 2016
            ),
            array(
                //1 monat (bei interval von 60)
                'steps' => 7,
                'rows' => 1500
            ),
            array(
                //1 jahr (bei interval von 60)
                'steps' => 50,
                'rows' => 2500
            ),
        );
    }

    public function createFile($start)
    {
        if (file_exists($this->_fileName)) {
            throw new Vps_Exception("$this->_fileName already exists");
        }
        $cmd = "rrdtool create $this->_fileName ";
        $cmd .= "--start ".$start." ";
        $cmd .= "--step ".($this->_interval)." ";
        foreach ($this->_fields as $field) {
            if (!is_null($field->getHeartbeat())) {
                $heartbeat = $field->getHeartbeat();
            } else {
                $heartbeat = ($this->_interval*2);
            }
            $cmd .= "DS:".$field->getName().":".$field->getType().":".$heartbeat.":".$field->getMin().":".($field->getMax())." ";
        }
        foreach ($this->getRRAs() as $rra) {
            if (!isset($rra['method'])) $rra['method'] = 'AVERAGE';
            if (!isset($rra['xff'])) $rra['xff'] = '0.6';
            $cmd .= "RRA:$rra[method]:$rra[xff]:$rra[steps]:$rra[rows] ";
        }
        system($cmd, $ret);
        if ($ret != 0) throw new Vps_Exception("Command failed");
    }

    protected function _getMemcache()
    {
        if (!isset($this->_memcache)) {
            $this->_memcache = new Memcache;
            $memcacheSettings = Vps_Registry::get('config')->server->memcache;
            $this->_memcache->addServer($memcacheSettings->host, $memcacheSettings->port);
        }
        return $this->_memcache;
    }

    protected function _getMemcacheValue($field)
    {
        $prefix = Zend_Registry::get('config')->application->id.'-'.
                            Vps_Setup::getConfigSection().'-bench-';
        $value = $this->_getMemcache()->get($prefix.$field);
        if ($value===false) $value = 'U';
        return $value;
    }

    abstract public function getRecordValues();

    public function record()
    {
        $values = $this->getRecordValues();

        if (!file_exists($this->_fileName)) {
            $this->createFile(time()-1);
        }

{'fraction_non_alphanumeric': 0.15989496959646213, 'fraction_numerical': 0.00912106135986733, 'mean_word_length': 1.743366186504928, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 93, 'https://': 0, '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': '770493', 'n_tokens_mistral': 2215, 'n_tokens_neox': 2125, 'n_words': 439}