<?php

function fn_notduring_tl($aql)
{
	$data = $aql->Consume(2);
	$points = $data[1];
	$times = $data[0];
	
	if (!is_array($points->value))
		$pointset = array($points->value);
	else
		$pointset = $points->value;
	
	$timeseries = $times->value;	
	
	//print_r($timeseries);
	
	$indx = -1;
	foreach($pointset as $p)
	{		
		//echo 'Processing '.$p->assetid.' with '.count($p->history).' history records...';
		for($x=count($p->history)-1;$x>=0;$x--)
		{
			$v = $p->history[$x][0];
			//echo $v;
			$matched = false;
			foreach($timeseries as $t)
			{				
				//echo 'Comparing '.$v.' with '.$t['from'].' - '.$t['to'].'<br/>';
				if (($v >= $t['from']) and ($v < $t['to']))
				{
					$matched = true;
					//echo 'Accepted!';
					break;
				}				
			}
			if ($matched == true)
			{				
				unset($p->history[$x]);							
			}
		}
		$p->history = array_values($p->history);		
	}
	
		
	array_push($aql->stack,$points);
}
?>