<?php
function fn_stddev_t($aql)
{
	$list = $aql->Consume(1);
	
	LiveValuesForPoints($list[0]->value);

	$result = 0;
	$samples = 0;
	$total = 0;
	$lst = array();
	foreach($list[0]->value as $p)
	{		
		$lst[] = $p->rawvalue;
		$samples++;
		$total += $p->rawvalue;
	}
	
	if ($samples > 0)
	{
		$avg = $total / $samples;
		$var = 0;
		foreach($list[0]->value as $p)
		{			
			$var += pow($p->rawvalue - $avg,2);
		}
		$result = sqrt($var) / $samples;
		print("Total Variance: ".$var.' / Samples: '.$samples);
	}
	
	$indx = 0;
	
	$a = new AQLStackElement();
	$a->typename = "const";
	$a->islist = false;
	$a->value = $result;
	array_push($aql->stack,$a);	

}
?>