<commit_before><?php
/**
 * Bar image generation
 *
 * PHP Version 5.2
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @category  phpMyFAQ
 * @package   PMF_Bar
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009-2010 phpMyFAQ Team
 * @license   http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
 * @link      http://www.phpmyfaq.de
 * @since     2009-03-30
 */

if (!defined('IS_VALID_PHPMYFAQ')) {
    exit();
}

/**
 * PMF_Bar
 *
 * @category  phpMyFAQ
 * @package   PMF_Bar
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009-2010 phpMyFAQ Team
 * @license   http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
 * @link      http://www.phpmyfaq.de
 * @since     2009-03-30
 */
class PMF_Bar
{
    /**
     * Image resource
     * 
     * @var resource
     */
    private $image = null;
    
    /**
     * Number
     * 
     * @var float
     */
    private $number = 0;
    
    /**
     * Colored image
     * 
     * @var boolean
     */
    private $colored = false;
    
    /**
     * Text color
     * 
     * @var integer
     */
    private $textcolor = 0;
    
    /**
     * Background color
     * 
     * @var integer
     */
    private $backgroundcolor = 0;
    
    /**
     * Quartiles
     * 
     * @var array
     */
    private $quartiles = array(25, 50, 75);
    
    /**
     * Constructor
     *
     * @param  float   $number  Number for the bar
     * @param  boolean $colored Image colored? default: false
     * @return void
     */
    public function __construct($number = null, $colored = false)
    {
        $this->number  = $number;
        $this->colored = $colored;
        
        /**
         * Initalize default quartiles
         */
        $this->quartiles = array('lower_quartile' => array('percentile' => 25,
                                                           'text_color' => array(255, 255, 255),
                                                           'bar_color'  => array(255, 0, 0)),
                                 /**
                                  * Median is currently not used
                                  */
                                 'median' => array(),
                                 'upper_quartile' => array('percentile' => 75,
                                                           'text_color' => array(255, 255, 255),
                                                           'bar_color'  => array(0, 128, 0)),
                                 /**
                                  * This is the difference between the upper and lower quartiles
                                  */
                                 'interquartile_range' => array('text_color' => array(255, 255, 255),
                                                           	    'bar_color'  => array(150, 150, 150))
        
        );
    }

    /**
     * Returns the colors
     * 
     * @return boolean
     */
    public function getColored()
    {
        return $this->colored;
    }
    
    /**
     * Returns the number
     * 
     * @return float
     */
    public function getNumber()
    {
        return $this->number;
    }
    
    /**
     * Sets the color
     * 
     * @param boolean $colored Colored?
     */
    public function setColored($colored)
    {
        $this->colored = $colored;
    }
    
    /**
     * Sets the number
     * 
     * @param float $number Number
     */
    public function setNumber($number)
    {
        $this->number = $number;
    }
    
    /**
     * Sets the quartiles
     * 
     * @param  array $quartiles Quartiles
     * @return void 
     */
    public function setQuartiles(Array $quartiles)
    {
        $this->quartiles = $quartiles;
    }
    
    /**
     * Returns the quartiles
     * 
     * @return array
     */
    public function getQuartiles()
    {
        return $this->quartiles;
    }
    
    /**
     * Rendering of the image
     * 
     * @return boolean
     */
    public function renderImage()
    {
        header ('Content-type: image/png');

        $this->prepareImage() || $this->resetImage();
        
        return imagepng($this->image);
    }
    
    /**
     * Prepares the image for rendering
     *
     * @return boolean
     */
    private function prepareImage()
    {
        $retval = false;
        
        $this->resetImage();
        
        if (null !== $this->number) {
            if ($this->colored) {
                if ($this->number < $this->quartiles['lower_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['lower_quartile']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['lower_quartile']['bar_color'];
                } elseif ($this->number > $this->quartiles['upper_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['upper_quartile']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['upper_quartile']['bar_color'];
                } elseif ($this->number <= $this->quartiles['upper_quartile']['percentile'] &&
                          $this->number >= $this->quartiles['lower_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['interquartile_range']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['interquartile_range']['bar_color'];
                }
            } else {
                list($r1, $g1, $b1) = array(0, 0, 0);
                list($r2, $g2, $b2) = array(211, 211, 211);
            }
            
            $this->textcolor = imagecolorallocate ($this->image, $r1, $g1, $b1);
            $barColor        = imagecolorallocate ($this->image, $r2, $g2, $b2);
            
            $retval = imagefilledrectangle ($this->image, 0, 0, round(($this->number/100)*50), 15, $barColor);
            $retval = $retval && imagestring($this->image, 2, 1, 1, floor($this->number) . '%', $this->textcolor);
        } else {
            $retval = imagestring($this->image, 1, 5, 5, 'n/a', $this->textcolor);
        }
        
        return $retval;
    }
    
    /**
     * Resets the image
     *
     * @return void
     */
    private function resetImage()
    {
        $this->image           = imagecreate(50, 15);
        $this->backgroundcolor = imagecolorallocate ($this->image, 255, 255, 255);
        $this->textcolor       = imagecolorallocate ($this->image, 0, 0, 0);
    }
}<commit_msg>Fixed color of statistics<commit_after><?php
/**
 * Bar image generation
 *
 * PHP Version 5.2
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @category  phpMyFAQ
 * @package   PMF_Bar
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009-2011 phpMyFAQ Team
 * @license   http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
 * @link      http://www.phpmyfaq.de
 * @since     2009-03-30
 */

if (!defined('IS_VALID_PHPMYFAQ')) {
    exit();
}

/**
 * PMF_Bar
 *
 * @category  phpMyFAQ
 * @package   PMF_Bar
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009-2011 phpMyFAQ Team
 * @license   http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
 * @link      http://www.phpmyfaq.de
 * @since     2009-03-30
 */
class PMF_Bar
{
    /**
     * Image resource
     * 
     * @var resource
     */
    private $image = null;
    
    /**
     * Number
     * 
     * @var float
     */
    private $number = 0;
    
    /**
     * Colored image
     * 
     * @var boolean
     */
    private $colored = false;
    
    /**
     * Text color
     * 
     * @var integer
     */
    private $textcolor = 0;
    
    /**
     * Background color
     * 
     * @var integer
     */
    private $backgroundcolor = 0;
    
    /**
     * Quartiles
     * 
     * @var array
     */
    private $quartiles = array(25, 50, 75);
    
    /**
     * Constructor
     *
     * @param  float   $number  Number for the bar
     * @param  boolean $colored Image colored? default: false
     * @return void
     */
    public function __construct($number = null, $colored = false)
    {
        $this->number  = $number;
        $this->colored = $colored;
        
        /**
         * Initalize default quartiles
         */
        $this->quartiles = array('lower_quartile' => array('percentile' => 25,
                                                           'text_color' => array(0, 0, 0),
                                                           'bar_color'  => array(255, 0, 0)),
                                 /**
                                  * Median is currently not used
                                  */
                                 'median' => array(),
                                 'upper_quartile' => array('percentile' => 75,
                                                           'text_color' => array(0, 0, 0),
                                                           'bar_color'  => array(0, 128, 0)),
                                 /**
                                  * This is the difference between the upper and lower quartiles
                                  */
                                 'interquartile_range' => array('text_color' => array(0, 0, 0),
                                                           	    'bar_color'  => array(150, 150, 150))
        
        );
    }

    /**
     * Returns the colors
     * 
     * @return boolean
     */
    public function getColored()
    {
        return $this->colored;
    }
    
    /**
     * Returns the number
     * 
     * @return float
     */
    public function getNumber()
    {
        return $this->number;
    }
    
    /**
     * Sets the color
     * 
     * @param boolean $colored Colored?
     */
    public function setColored($colored)
    {
        $this->colored = $colored;
    }
    
    /**
     * Sets the number
     * 
     * @param float $number Number
     */
    public function setNumber($number)
    {
        $this->number = $number;
    }
    
    /**
     * Sets the quartiles
     * 
     * @param  array $quartiles Quartiles
     * @return void 
     */
    public function setQuartiles(Array $quartiles)
    {
        $this->quartiles = $quartiles;
    }
    
    /**
     * Returns the quartiles
     * 
     * @return array
     */
    public function getQuartiles()
    {
        return $this->quartiles;
    }
    
    /**
     * Rendering of the image
     * 
     * @return boolean
     */
    public function renderImage()
    {
        header ('Content-type: image/png');

        $this->prepareImage() || $this->resetImage();
        
        return imagepng($this->image);
    }
    
    /**
     * Prepares the image for rendering
     *
     * @return boolean
     */
    private function prepareImage()
    {
        $retval = false;
        
        $this->resetImage();
        
        if (null !== $this->number) {
            if ($this->colored) {
                if ($this->number < $this->quartiles['lower_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['lower_quartile']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['lower_quartile']['bar_color'];
                } elseif ($this->number > $this->quartiles['upper_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['upper_quartile']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['upper_quartile']['bar_color'];
                } elseif ($this->number <= $this->quartiles['upper_quartile']['percentile'] &&
                          $this->number >= $this->quartiles['lower_quartile']['percentile']) {
                    list($r1, $g1, $b1) = $this->quartiles['interquartile_range']['text_color'];
                    list($r2, $g2, $b2) = $this->quartiles['interquartile_range']['bar_color'];
                }
            } else {
                list($r1, $g1, $b1) = array(0, 0, 0);
                list($r2, $g2, $b2) = array(211, 211, 211);
            }
            
            $this->textcolor = imagecolorallocate ($this->image, $r1, $g1, $b1);
            $barColor        = imagecolorallocate ($this->image, $r2, $g2, $b2);
            
            $retval = imagefilledrectangle ($this->image, 0, 0, round(($this->number/100)*50), 15, $barColor);
            $retval = $retval && imagestring($this->image, 2, 1, 1, floor($this->number) . '%', $this->textcolor);
        } else {
            $retval = imagestring($this->image, 1, 5, 5, 'n/a', $this->textcolor);
        }
        
        return $retval;
    }
    
    /**
     * Resets the image
     *
     * @return void
     */
    private function resetImage()
    {
        $this->image           = imagecreate(50, 15);
        $this->backgroundcolor = imagecolorallocate ($this->image, 255, 255, 255);
        $this->textcolor       = imagecolorallocate ($this->image, 0, 0, 0);
    }
}
{'fraction_non_alphanumeric': 0.1367794395237404, 'fraction_numerical': 0.024248584289240597, 'mean_word_length': 1.4828767123287672, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669160', 'n_tokens_mistral': 4312, 'n_tokens_neox': 3906, 'n_words': 929}