<commit_before><?php

require_once '../lib/_require.php';

class TraceView {
	
	use TRequest;
	
	CONST APP_NAME             = 'traceView';
	CONST APP_CLASS            = 'traceView';
	CONST MAIN_TEMPLATE        = 'traceViewTemplate';
	CONST FILTER_SUFFIX        = 'Filter';
	CONST SELECTED_SUFFIX      = 'Selected';
	CONST LIST_SUFFIX          = 'List';
	CONST COUNT_SUFFIX         = 'Count';
	CONST LIST_HTML_GET_SUFFIX = 'ListHtmlGet';
	CONST COUNT_HTML_SUFFIX    = 'CountHtml';
	CONST SELECTED_HTML        = ' selected="selected" selected ';
	CONST OPTION_ALL_HTML      = '<option id="all" name="all" value="all">all</option>';
	CONST OPTION_NONE_HTML     = '<option id="none" name="none" value="none">none</option>';
		
	private $html;
	private $appNameSelected;
	private $mockSelected;
	private $stateSelected;
	private $userIdSelected;
	private $yearSelected;
	private $monthSelected;
	private $daySelected;
	private $hourSelected;
	private $classSelected;
	private $instanceSelected;
	private $lineSelected;
	private $methodSelected;
	private $envSelected;
	private $mockList;
	private $appList;
	private $stateList;
	private $classList;
	private $content;
	private $time;
	private $timeZone;
	private $filterList     = array('env', 'state', 'class', 'appName', 'mock', 'year', 'month', 'day', 'hour', 'userId', 'instance', 'line', 'method');
	private $filterDateList = array();
	private $listList       = array('env', 'mock', 'app', 'state', 'class');
	private $countHtml      = '';
	private $fileCount      = array();
	private $appCount       = array();
	private $userCount      = array();
	private $classCount     = array();
	private $appNameCount   = array();
	private $mockCount      = array();
	private $yearCount      = array();
	private $monthCount     = array();
	private $dayCount       = array();
	private $hourCount      = array();
	private $userIdCount    = array();
	private $instanceCount  = array();
	private $methodCount    = array();
		
	public function __construct() {
		
		date_default_timezone_set(Conf::TIMEZONE_DEFAULT);
	}
	
	public function htmlGet() {
		
		$this->filterDateList['year']  = 'Y';
		$this->filterDateList['month'] = 'm';
		$this->filterDateList['day']   = 'd';
		$this->filterDateList['hour']  = 'H';
				
		foreach($this->filterList as $filter) {
			
			$varName         = $filter.self::SELECTED_SUFFIX;
			$filterName      = $filter.self::FILTER_SUFFIX;
			
			if(isset($this->filterDateList[$filter]) === false) $this->$varName  = self::filterExist($filterName);
			else                                                $this->$varName  = self::filterExist($filterName, date($this->filterDateList[$filter], time()));
		}
		foreach($this->listList as $list){
		
			$varName        = $list.self::LIST_SUFFIX;
			$funcName       = $list.self::LIST_HTML_GET_SUFFIX;
			$this->$varName = $this->$funcName();
		}
		$this->time		= date('d/m/Y H:i:s', time());
		$this->timeZone	= Conf::TIMEZONE_DEFAULT;
		$this->content  = $this->fileContentHtmlGet();

		foreach($this->filterList as $filter) {
						
			if($filter === 'state') continue;
			if($filter === 'line')  continue;
			
			$varName          = $filter.self::COUNT_SUFFIX;
			$this->countHtml .= '<h3>'.$filter.'</h3>';
			
			foreach($this->$varName as $value => $states) {
				
				$this->countHtml .= '<p>'.$value.': ';
				
				foreach($states as $state => $val) {
			
					$this->countHtml .= '<span class="'.$state.'">'.$state.'('.$val.')</span> ';
				}
				$this->countHtml .= '</p>';
			}
		}
		$this->html = $this->templateHtml();
		
		return $this->html;
	}
	
	private function templateHtml() {
		
		$this->html = Template::htmlConfTemplateGet(self::MAIN_TEMPLATE);
		
		foreach($this as $k => $v){
				
			if(is_string($v) !== true) continue;
				
			$this->html = str_replace('{'.$k.'}', $v, $this->html);
		}
		return $this->html;
	}
	
	public static function selectedHtmlGet($var, $selected, $selectedHtml = '') {
		
		if($var === $selected) $selectedHtml = self::SELECTED_HTML;
		
		return $selectedHtml;
	}
	public static function optionHtmlGet($selected, $id, $value, $text) {
		
		return '<option '.$selected.' name="'.$id.'" id="'.$id.'" value="'.$value.'">'.$text.'</option>';
	}

	public static function filterExist($tag, $default = 'all') {
		
		$value = self::requestVal($tag);
		
		if($value === false) $value = $default;
		
		return $value;
	}
	
	public static function isSelected($val, $select){
		
		if($select === '')      return true;
		if($select === '0')     return true;
		if($select === 'all')   return true;
		if($val    === $select) return true;
		
		return false;
	}
	
	public static function listHtmlGet($list, $valueSelected, $all = true, $none = false) {

		$listHtml = '';
		
		if($all  === true) $listHtml .= self::OPTION_ALL_HTML;
		if($none === true) $listHtml .= self::OPTION_NONE_HTML;
		
		foreach($list as $value){
				
			$selected  = self::selectedHtmlGet($value, $valueSelected);
			$listHtml .= self::optionHtmlGet($selected, $value, $value, $value);
		}
		return $listHtml;
	}
	
	private function stateListHtmlGet() {
		
		return self::listHtmlGet(Trace::$stateList, $this->stateSelected, true);
	}
	
	private function envListHtmlGet() {
		
		return self::listHtmlGet(array('dev', 'preproduction', 'production'), $this->envSelected, true);
	}
	
	private function classListHtmlGet() {
		
		return self::listHtmlGet(Fw::$classList, $this->classSelected, true);
	}
	
	private function mockListHtmlGet() {

		$files2 = array();
		$files  = glob(Mock::DIR.'*'.Mock::FILE_EXT);
		
		sort($files);
		
		foreach($files as $file) {
				
			$file     = basename($file);
			$files2[] = str_replace(Mock::FILE_EXT, '', $file);
		}
		return self::listHtmlGet($files2, $this->mockSelected, true, true);
	}
	
	private function appListHtmlGet(){

		$files2 = array();
		$files  = glob(App::EXPLOIT_DIR.'*'.App::FILE_EXT);
		$files  = array_merge($files, glob(App::PUBLIC_DIR.'*'.App::FILE_EXT));
		
		sort($files);
		
		foreach($files as $file) {
				
			$file     = basename($file);
			$files2[] = str_replace(App::FILE_EXT, '', $file);
		}
		return self::listHtmlGet($files2, $this->appNameSelected, true);
	}
	
	private function fileContentHtmlGet() {
		
		$contentA = array();
		$files    = glob(Trace::DIR.'*'.Trace::FILE_EXT);
		
		sort($files);
		
		foreach($files as $file) {
		
			$size      = filesize($file);
			$size      = $size / 1000000;
			$size      = round($size,3);
			$size      = (string) $size;
			$basenamme = basename($file);
			$content   = file_get_contents($file);
			$content   = trim($content);
			$content   = explode(Trace::SEP, $content);
			rsort($content);
			
			foreach($content as $l) {
				
				$l       = trim($l);
				$l       = str_replace(Trace::SEP_REPLACE, Trace::SEP, $l);
				$l       = json_decode($l);
				
				forach($l as $k => $v){
					
					if($v === Trace::VOID) unset($l[$k]);
				}
				$env     = $l->env_name;
				$state   = $l->errorInfoLevel;
				$userId  = $l->u_idCryptedT;
				$appName = $l->app_name;
				$year    = $l->tY_Y;
				$month   = $l->tmon_m;
				$day     = $l->tdm_d;
				$hour    = $l->tH_H;
				$mock    = 'none';
				
				if($l->mock_state !== false) $mock = $l->mock_name;
				
				$time     = $l->t_time;
				$class    = $l->c_name;<commit_msg>some fix (2)<commit_after><?php

require_once '../lib/_require.php';

class TraceView {
	
	use TRequest;
	
	CONST APP_NAME             = 'traceView';
	CONST APP_CLASS            = 'traceView';
	CONST MAIN_TEMPLATE        = 'traceViewTemplate';
	CONST FILTER_SUFFIX        = 'Filter';
	CONST SELECTED_SUFFIX      = 'Selected';
	CONST LIST_SUFFIX          = 'List';
	CONST COUNT_SUFFIX         = 'Count';
	CONST LIST_HTML_GET_SUFFIX = 'ListHtmlGet';
	CONST COUNT_HTML_SUFFIX    = 'CountHtml';
	CONST SELECTED_HTML        = ' selected="selected" selected ';
	CONST OPTION_ALL_HTML      = '<option id="all" name="all" value="all">all</option>';
	CONST OPTION_NONE_HTML     = '<option id="none" name="none" value="none">none</option>';
		
	private $html;
	private $appNameSelected;
	private $mockSelected;
	private $stateSelected;
	private $userIdSelected;
	private $yearSelected;
	private $monthSelected;
	private $daySelected;
	private $hourSelected;
	private $classSelected;
	private $instanceSelected;
	private $lineSelected;
	private $methodSelected;
	private $envSelected;
	private $mockList;
	private $appList;
	private $stateList;
	private $classList;
	private $content;
	private $time;
	private $timeZone;
	private $filterList     = array('env', 'state', 'class', 'appName', 'mock', 'year', 'month', 'day', 'hour', 'userId', 'instance', 'line', 'method');
	private $filterDateList = array();
	private $listList       = array('env', 'mock', 'app', 'state', 'class');
	private $countHtml      = '';
	private $fileCount      = array();
	private $appCount       = array();
	private $userCount      = array();
	private $classCount     = array();
	private $appNameCount   = array();
	private $mockCount      = array();
	private $yearCount      = array();
	private $monthCount     = array();
	private $dayCount       = array();
	private $hourCount      = array();
	private $userIdCount    = array();
	private $instanceCount  = array();
	private $methodCount    = array();
		
	public function __construct() {
		
		date_default_timezone_set(Conf::TIMEZONE_DEFAULT);
	}
	
	public function htmlGet() {
		
		$this->filterDateList['year']  = 'Y';
		$this->filterDateList['month'] = 'm';
		$this->filterDateList['day']   = 'd';
		$this->filterDateList['hour']  = 'H';
				
		foreach($this->filterList as $filter) {
			
			$varName         = $filter.self::SELECTED_SUFFIX;
			$filterName      = $filter.self::FILTER_SUFFIX;
			
			if(isset($this->filterDateList[$filter]) === false) $this->$varName  = self::filterExist($filterName);
			else                                                $this->$varName  = self::filterExist($filterName, date($this->filterDateList[$filter], time()));
		}
		foreach($this->listList as $list){
		
			$varName        = $list.self::LIST_SUFFIX;
			$funcName       = $list.self::LIST_HTML_GET_SUFFIX;
			$this->$varName = $this->$funcName();
		}
		$this->time		= date('d/m/Y H:i:s', time());
		$this->timeZone	= Conf::TIMEZONE_DEFAULT;
		$this->content  = $this->fileContentHtmlGet();

		foreach($this->filterList as $filter) {
						
			if($filter === 'state') continue;
			if($filter === 'line')  continue;
			
			$varName          = $filter.self::COUNT_SUFFIX;
			$this->countHtml .= '<h3>'.$filter.'</h3>';
			
			foreach($this->$varName as $value => $states) {
				
				$this->countHtml .= '<p>'.$value.': ';
				
				foreach($states as $state => $val) {
			
					$this->countHtml .= '<span class="'.$state.'">'.$state.'('.$val.')</span> ';
				}
				$this->countHtml .= '</p>';
			}
		}
		$this->html = $this->templateHtml();
		
		return $this->html;
	}
	
	private function templateHtml() {
		
		$this->html = Template::htmlConfTemplateGet(self::MAIN_TEMPLATE);
		
		foreach($this as $k => $v){
				
			if(is_string($v) !== true) continue;
				
			$this->html = str_replace('{'.$k.'}', $v, $this->html);
		}
		return $this->html;
	}
	
	public static function selectedHtmlGet($var, $selected, $selectedHtml = '') {
		
		if($var === $selected) $selectedHtml = self::SELECTED_HTML;
		
		return $selectedHtml;
	}
	public static function optionHtmlGet($selected, $id, $value, $text) {
		
		return '<option '.$selected.' name="'.$id.'" id="'.$id.'" value="'.$value.'">'.$text.'</option>';
	}

	public static function filterExist($tag, $default = 'all') {
		
		$value = self::requestVal($tag);
		
		if($value === false) $value = $default;
		
		return $value;
	}
	
	public static function isSelected($val, $select){
		
		if($select === '')      return true;
		if($select === '0')     return true;
		if($select === 'all')   return true;
		if($val    === $select) return true;
		
		return false;
	}
	
	public static function listHtmlGet($list, $valueSelected, $all = true, $none = false) {

		$listHtml = '';
		
		if($all  === true) $listHtml .= self::OPTION_ALL_HTML;
		if($none === true) $listHtml .= self::OPTION_NONE_HTML;
		
		foreach($list as $value){
				
			$selected  = self::selectedHtmlGet($value, $valueSelected);
			$listHtml .= self::optionHtmlGet($selected, $value, $value, $value);
		}
		return $listHtml;
	}
	
	private function stateListHtmlGet() {
		
		return self::listHtmlGet(Trace::$stateList, $this->stateSelected, true);
	}
	
	private function envListHtmlGet() {
		
		return self::listHtmlGet(array('dev', 'preproduction', 'production'), $this->envSelected, true);
	}
	
	private function classListHtmlGet() {
		
		return self::listHtmlGet(Fw::$classList, $this->classSelected, true);
	}
	
	private function mockListHtmlGet() {

		$files2 = array();
		$files  = glob(Mock::DIR.'*'.Mock::FILE_EXT);
		
		sort($files);
		
		foreach($files as $file) {
				
			$file     = basename($file);
			$files2[] = str_replace(Mock::FILE_EXT, '', $file);
		}
		return self::listHtmlGet($files2, $this->mockSelected, true, true);
	}
	
	private function appListHtmlGet(){

		$files2 = array();
		$files  = glob(App::EXPLOIT_DIR.'*'.App::FILE_EXT);
		$files  = array_merge($files, glob(App::PUBLIC_DIR.'*'.App::FILE_EXT));
		
		sort($files);
		
		foreach($files as $file) {
				
			$file     = basename($file);
			$files2[] = str_replace(App::FILE_EXT, '', $file);
		}
		return self::listHtmlGet($files2, $this->appNameSelected, true);
	}
	
	private function fileContentHtmlGet() {
		
		$contentA = array();
		$files    = glob(Trace::DIR.'*'.Trace::FILE_EXT);
		
		sort($files);
		
		foreach($files as $file) {
		
			$size      = filesize($file);
			$size      = $size / 1000000;
			$size      = round($size,3);
			$size      = (string) $size;
			$basenamme = basename($file);
			$content   = file_get_contents($file);
			$content   = trim($content);
			$content   = explode(Trace::SEP, $content);
			rsort($content);
			
			foreach($content as $l) {
				
				$l = trim($l);
				$l = str_replace(Trace::SEP_REPLACE, Trace::SEP, $l);
				$l = json_decode($l);
				
				foreach($l as $k => $v){
					
					if($v === Trace::VOID) unset($l[$k]);
				}
				$env     = $l->env_name;
				$state   = $l->errorInfoLevel;
				$userId  = $l->u_idCryptedT;
				$appName = $l->app_name;
				$year    = $l->tY_Y;
				$month   = $l->tmon_m;
				$day     = $l->tdm_d;
				$hour    = $l->tH_H;
				$mock    = 'none';
				
				if($l->mock_state !== false) $mock = $l->mock_name;
				
				$time     = $l->t_time;
				$class    = $l->c_name;
{'fraction_non_alphanumeric': 0.1823448275862069, 'fraction_numerical': 0.002413793103448276, 'mean_word_length': 3.2889677610174504, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2948063', 'n_tokens_mistral': 5635, 'n_tokens_neox': 4884, 'n_words': 981}