<commit_before><?php
class apache_log_parser {

	/**
	* @var String
	* @access private
	*/
	private $file = "";

	/**
	* @var String
	* @access private
	*/
	private $inhalt = "";

	/**
	* @var Array
	* @access private
	*/
	private $data = array();

	/**
	* @var Array
	* @access public
	*/
	private $stats = array();

	/**
	* @param String $file
	* @return FruitParseError
	* @access public
	*/
	public function __construct($file){
		$this->file = $file;
		$this->inhalt = file_get_contents($this->file);
		if(!$this->inhalt){
			echo "Can not open file: '".$this->file."' <br>Check the file name!";
			return;
		}
		$this->paralyse_log();
	}

	/**
	* Parse raw data and keep only errors
	* @access private
	*/
	private function parse_data(){
		$input = explode("\n",$this->inhalt);
		$this->stats['rows'] = 0;
		$array_size = sizeof($input);
		for($i = 0; $i < $array_size; $i++){
			$this->stats['rows']++;
			$back = explode(" ",$input[$i]);
			if(!isset($back['8'])){ //new line in file / empty line
				continue;
			}
			if(
				//these are not errors
				$back['8'] == '200' || // OK
				$back['8'] == '206' || //Partial Content
				$back['8'] == '301' || // Moved Permanently (redirect permanently)
				$back['8'] == '302' || // Found (in cache / or redirect after POST or so)
				$back['8'] == '304' // Not Modified (in cache)
			){
				continue;
			}
			$output = array('type' => $back['8'],'date' => $back['3'],'info' => $back['0'],'detail' => $back['6']);
			$this->data[] = $output;
		}
	}

	/**
	* parse the log file
	* @access private
	*/
	private function paralyse_log(){
		$this->parse_data();
		$type = array();
		$detail = array();

		$size_of_data = sizeof($this->data);
		for($a = 0; $a < $size_of_data; $a++){
			if(isset($type[$this->data[$a]['type']])){
				$type[$this->data[$a]['type']]++;
			} else {
				$type[$this->data[$a]['type']] = 1;
			}

			if(isset($detail[$this->data[$a]['detail']])){
				$detail[$this->data[$a]['detail']]++;
			} else {
				$detail[$this->data[$a]['detail']] = 1;
				$this->stats['content_type'][$this->data[$a]['detail']] = $this->data[$a]['type'];
			}
		}
		// statistics + types
		$this->stats['analyzed_rows'] = sizeof($this->data);
		$key = array_keys($type);
		$this->stats['rowtypeCount'] = sizeof($key);
		for($x = 0; $x < sizeof($key); $x++) {
			$temp = array('name' => $key[$x],'value' => $type[$key[$x]], 'pro' => round(($type[$key[$x]]*100/$this->stats['analyzed_rows']),4).' %');
			$this->stats['rowtype'][] = $temp;
		}

		$this->stats['errCount'] = sizeof($detail);
		array_multisort($detail, SORT_DESC, SORT_NUMERIC);
		$this->stats['err'] = $detail;
	}

	/**
	* @access public
	* @return String $out
	*/
	public function table(){
		$out = '<br /><br />Parsed '. $this->stats['rows'] .' lines. Found <b>'.$this->stats['analyzed_rows'].'</b> errors with <b>'.$this->stats['rowtypeCount'].'</b> type(s)<br /><br />';
		$out .= '<table>';<commit_msg>don't count over and over again<commit_after><?php
class apache_log_parser {

	/**
	* @var String
	* @access private
	*/
	private $file = "";

	/**
	* @var String
	* @access private
	*/
	private $inhalt = "";

	/**
	* @var Array
	* @access private
	*/
	private $data = array();

	/**
	* @var Array
	* @access public
	*/
	private $stats = array();

	/**
	* @param String $file
	* @return FruitParseError
	* @access public
	*/
	public function __construct($file){
		$this->file = $file;
		$this->inhalt = file_get_contents($this->file);
		if(!$this->inhalt){
			echo "Can not open file: '".$this->file."' <br>Check the file name!";
			return;
		}
		$this->paralyse_log();
	}

	/**
	* Parse raw data and keep only errors
	* @access private
	*/
	private function parse_data(){
		$input = explode("\n",$this->inhalt);
		$this->stats['rows'] = 0;
		$array_size = sizeof($input);
		for($i = 0; $i < $array_size; $i++){
			$this->stats['rows']++;
			$back = explode(" ",$input[$i]);
			if(!isset($back['8'])){ //new line in file / empty line
				continue;
			}
			if(
				//these are not errors
				$back['8'] == '200' || // OK
				$back['8'] == '206' || //Partial Content
				$back['8'] == '301' || // Moved Permanently (redirect permanently)
				$back['8'] == '302' || // Found (in cache / or redirect after POST or so)
				$back['8'] == '304' // Not Modified (in cache)
			){
				continue;
			}
			$output = array('type' => $back['8'],'date' => $back['3'],'info' => $back['0'],'detail' => $back['6']);
			$this->data[] = $output;
		}
	}

	/**
	* parse the log file
	* @access private
	*/
	private function paralyse_log(){
		$this->parse_data();
		$type = array();
		$detail = array();

		$size_of_data = sizeof($this->data);
		for($a = 0; $a < $size_of_data; $a++){
			if(isset($type[$this->data[$a]['type']])){
				$type[$this->data[$a]['type']]++;
			} else {
				$type[$this->data[$a]['type']] = 1;
			}

			if(isset($detail[$this->data[$a]['detail']])){
				$detail[$this->data[$a]['detail']]++;
			} else {
				$detail[$this->data[$a]['detail']] = 1;
				$this->stats['content_type'][$this->data[$a]['detail']] = $this->data[$a]['type'];
			}
		}
		// statistics + types
		$this->stats['analyzed_rows'] = sizeof($this->data);
		$key = array_keys($type);
		$this->stats['rowtypeCount'] = sizeof($key);
		for($x = 0; $x < $this->stats['rowtypeCount']; $x++) {
			$temp = array('name' => $key[$x],'value' => $type[$key[$x]], 'pro' => round(($type[$key[$x]]*100/$this->stats['analyzed_rows']),4).' %');
			$this->stats['rowtype'][] = $temp;
		}

		$this->stats['errCount'] = sizeof($detail);
		array_multisort($detail, SORT_DESC, SORT_NUMERIC);
		$this->stats['err'] = $detail;
	}

	/**
	* @access public
	* @return String $out
	*/
	public function table(){
		$out = '<br /><br />Parsed '. $this->stats['rows'] .' lines. Found <b>'.$this->stats['analyzed_rows'].'</b> errors with <b>'.$this->stats['rowtypeCount'].'</b> type(s)<br /><br />';
		$out .= '<table>';
{'fraction_non_alphanumeric': 0.2596055763345801, 'fraction_numerical': 0.011900714042842571, 'mean_word_length': 3.6141176470588237, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 100, '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': '2237589', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2199, 'n_words': 442}