<?php

	require_once 'processes/dbh.inc.php';
// 	include("conection.php");
	include("funciones.php");
	
	
	// FUNCTION THAT CALCULATES THE STANDARD DEVIATION OF ARRAY ELEMENTS
	function stddev($arr) {
	
		$num_of_elements = count(array_filter($arr, function($x) { return is_numeric($x); })); 
		//return $num_of_elements;
		$variance = 0.0; 
	
		// calculating mean using array_sum() method 
		$average = average($arr); 
	
		foreach($arr as $i) { 
			// sum of squares of differences between 
			// all numbers and means. 
			$variance += pow(($i - $average), 2); 
		} 
	
		return (float)sqrt($variance / $num_of_elements); 
	} 
	
	
	// FUNCTION THAT CALCULATES THE AVERAGE OF ARRAY ELEMENTS
	function average($valores) {
		//return array_sum(array_filter($valores) / count(array_filter($valores));
		//return array_sum(array_filter($valores)) / count(array_filter($valores,function($x) { return is_numeric($x); }));
		return array_sum(array_filter($valores, function($x) { return is_numeric($x); })) / count(array_filter($valores, function($x) { return is_numeric($x); }));
	}


	// FUNCTION THAT CALCULATES THE PERCENT CHANGE BETWEEN TWO VALUES
	function porcientoCambio($primero, $segundo) {
		if(is_numeric($primero) and is_numeric($segundo)) {	
			return 100.0 * ($segundo - $primero) / $primero;
		}
		//else return NaN;
	}


	// FUNCTION THAT ROUNDS DECIMAL NUMBER TO TWO DECIMAL PLACES
	function siDecimal2($numero) {
		if(is_numeric($numero)) {
			$numero = sprintf("%.2f", $numero);
			$numero = rtrim($numero, "0");
			$numero = rtrim($numero, ".");
			return $numero;
		}
	}


	//SELECT a.id_question, q.premise, a.id_subquestionnair , q.id_category,q.id_subcategory  FROM `answer` a, question q WHERE a.`id_student` = 1860  and a.id_question=q.id ORDER BY `a`.`id_question` ASC
	$id_experiencia = mysqli_real_escape_string($connection, trim($_POST['id_exp']));
	$id_student = mysqli_real_escape_string($connection, trim($_POST['id_student']));
	$res_type = mysqli_real_escape_string($connection, trim($_POST['res_type']));

	
	// RUN CORRESPONDING SCRIPT DEPENDING ON SUMMARY VARIABLE (questions, subcategory, category)
	if($res_type == 0) {
		include "siPreguntas.php";
	}
	elseif($res_type == 1) {
		include "siSubCategoria.php";
	}
	elseif($res_type == 2) {
		include "siCategoria.php";
	}

// 	print "<script>console.log('".print_r($preguntas)."');</script>";

  	foreach($preguntas as $id => $pregunta) {
    	print "<tr>";
    	foreach($pregunta as $item) {
    		print '<td style="vertical-align: middle; text-align: center;">'.$item.'</td>';
    	}
    	print "</tr>";
	}

?>