<commit_before><?

include_once "fhq_class_security.php";

function echo_statistics()
{
	$security = new fhq_security();
	$db = new fhq_database();

	if(!$security->isAdmin() && !$security->isTester())
	{
		echo '<font color="#ff0000">Not found page</font>';
		exit;
	}

	$query = 'SELECT
  userquest.idquest, 
  quest.name,
  count(*) as cnt
FROM `userquest` 
  INNER JOIN quest ON userquest.idquest = quest.idquest 
WHERE 
	stopdate <> \'00:00:00 00-00-0000\' 
	and 
	quest.for_person = 0
GROUP BY 
	userquest.idquest
ORDER BY 
	cnt DESC
    
';
	
	
	$result = $db->query( $query );

	echo '<table id="customers">
	<tr class="alt">
		<th>Quest (id, Name)</th>
		<th>Users which passed this quest</th>
		<th>Successful Attempts</th>
		<th>No Successful Attempts</th>
	</tr>';

	$class = true;
	while ($row = mysql_fetch_row($result, MYSQL_ASSOC)) // Data
	{   
		$class = !$class;
		$idquest = $row['idquest'];
		$name = base64_decode($row['name']);
		$count = $row['cnt'];
		
		$plus = 0;
		$minus = 0;
		
		{
			$rs = $db->query( 'select count(*) as cnt from tryanswer where idquest = '.$idquest.' and passed = \'Yes\';' );
			$plus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
			$rs = $db->query( 'select count(*) as cnt from tryanswer_backup where idquest = '.$idquest.' and passed = \'Yes\';' );
			$plus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
		}
		
		{
			$rs = $db->query( 'select count(*) as cnt from tryanswer where idquest = '.$idquest.' and passed = \'No\';' );
			$minus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
			$rs = $db->query( 'select count(*) as cnt from tryanswer_backup where idquest = '.$idquest.' and passed = \'No\';' );			
			$minus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
		}

		echo ' 
			<tr '.($class ? 'class="alt"' : '').' >
				<td><a href=main.php?content_page=view_quest&id='.$idquest.'>'.$idquest.', '.$name.'</a></td>
				<td>'.$count.'</td>
				<td>'.$plus.'</td>
				<td>'.$minus.'</td>
			</tr>';
		echo '</pre>';
	}
	mysql_free_result($result);<commit_msg>fixed statistics<commit_after><?

include_once "fhq_class_security.php";

function echo_statistics()
{
	$security = new fhq_security();
	$db = new fhq_database();

	if(!$security->isAdmin() && !$security->isTester())
	{
		echo '<font color="#ff0000">Not found page</font>';
		exit;
	}

/*
	$query = 'SELECT
  userquest.idquest, 
  quest.name,
  count(*) as cnt
FROM `userquest` 
  INNER JOIN quest ON userquest.idquest = quest.idquest 
WHERE 
	stopdate <> \'00:00:00 00-00-0000\' 
	and 
	quest.for_person = 0
GROUP BY 
	userquest.idquest
ORDER BY 
	cnt DESC
    
';
*/

	$query = '
SELECT
	idquest, 
	name,
	min_score,
	score
FROM 
	quest
WHERE
	for_person = 0
ORDER BY
	min_score, score
';
	
	$result = $db->query( $query );

	echo '<table id="customers">
	<tr class="alt">
		<th>Quest (id, Name)</th>
		<th>Score(Min Score)</th>
		<th>Attempts(Yes)</th>
		<th>Attempts(No)</th>
	</tr>';

	function getSpec_SQL($table, $idquest, $passed)
	{
		return '
			select 
				count(*) as cnt 
			from 
				'.$table.' t0
			inner join user t1 on t0.iduser = t1.iduser
			where 
				t0.idquest = '.$idquest.' 
				and t0.passed = \''.$passed.'\'
				and t1.role = \'user\'
				;';
	}


	$class = true;
	while ($row = mysql_fetch_row($result, MYSQL_ASSOC)) // Data
	{   
		$class = !$class;
		$idquest = $row['idquest'];
		$name = base64_decode($row['name']);
		$min_score = $row['min_score'];
		$score = $row['score'];
		// $count = $row['cnt'];
		
		$plus = 0;
		$minus = 0;
		
		{
			$rs = $db->query( getSpec_SQL('tryanswer', $idquest, 'Yes') );
			$plus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
			$rs = $db->query( getSpec_SQL('tryanswer_backup', $idquest, 'Yes') );
			$plus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
		}
		
		{
			$rs = $db->query( getSpec_SQL('tryanswer', $idquest, 'No') );
			$minus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
			$rs = $db->query( getSpec_SQL('tryanswer_backup', $idquest, 'No') );
			$minus += mysql_result($rs, 0, 'cnt');
			mysql_free_result($rs);
		}

		echo ' 
			<tr '.($class ? 'class="alt"' : '').' >
				<td><a href=main.php?content_page=view_quest&id='.$idquest.'>'.$idquest.', '.$name.'</a></td>
				<td>+'.$score.' ( >='.$min_score.') </td>
				<td>'.$plus.'</td>
				<td>'.$minus.'</td>
			</tr>';
		echo '</pre>';
	}
	mysql_free_result($result);
{'fraction_non_alphanumeric': 0.21532184950135994, 'fraction_numerical': 0.014052583862194016, 'mean_word_length': 3.430722891566265, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 72, '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': '6186784', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1737, 'n_words': 365}