include("setup.php"); include("median.php"); header("Content-Type: text/html; charset=UTF-8"); $title=date("Y"); $xtitle=$ytitle=$title; $atitle=$mtitle=$dtitle=""; if ($_GET["data"]=="today") { $_GET["data"]=date("Ymd"); } if (preg_match('/^([0-9]{4})([0-9]{2})?([0-9]{2})?$/',$_GET["data"],$matches)) { $title=$_GET["data"]; $xtitle=$ytitle=$matches[1]; if ($matches[2]!="") { $xtitle.="-".$matches[2]; $mtitle=$matches[2]; } if ($matches[3]!="") { $xtitle.="-".$matches[3]; $dtitle=$matches[3]; } } $uri=isset($_GET["mode"]) ? $_GET["mode"]."-" : ""; define("NORMAL",0); define("PLUSNET",1); define("AAISP",2); define("MODE",($uri=="" ? NORMAL : ($uri=="plusnet-" ? PLUSNET : ($uri=="aaisp-" ? AAISP : NORMAL)) )); define("DAY",$dtitle!=""); define("RX",0); define("TX",1); $monlen=Array(0, 31,(date("L", mktime(0,0,0,1,1,substr($title,0,4))) ? 29 : 28),31, 30,31,30, 31,31,30, 31,30,31); $receive="Receive"; $transmit="Transmit"; $start_day=1; if (MODE==PLUSNET) { if (!DAY) { $receive="Peak"; $transmit="Off-peak"; } $start_day=$plusnet_billing_day; $peak=array_fill(16,23-16,TRUE); if ($mtitle!="" && $dtitle=="") { $atitle.=" to "; if ($mtitle!=12) { $atitle.=$ytitle."-".str_pad($mtitle+1,2,"0",STR_PAD_LEFT); } else { $atitle.=($ytitle+1)."-01"; } } } else if (MODE==AAISP) { if (!DAY) { $receive="Usage"; $transmit="Other"; } $start_day=1; $peak=array_fill(8,17-8,TRUE); } if (strlen($title) == 4) { // year $name="Month"; $start=mktime(0,0,0,1,$start_day,$ytitle); $finish=mktime(0,0,0,1,$start_day,$ytitle+1); $output=Array( Array('id'=>'01','url'=>$ytitle.'01',name=>'January',sname=>'Jan',start=>mktime(0,0,0,1,$start_day,$ytitle),stop=>mktime(0,0,0,2,$start_day,$ytitle)), Array('id'=>'02','url'=>$ytitle.'02',name=>'February',sname=>'Feb',start=>mktime(0,0,0,2,$start_day,$ytitle),stop=>mktime(0,0,0,3,$start_day,$ytitle)), Array('id'=>'03','url'=>$ytitle.'03',name=>'March',sname=>'Mar',start=>mktime(0,0,0,3,$start_day,$ytitle),stop=>mktime(0,0,0,4,$start_day,$ytitle)), Array('id'=>'04','url'=>$ytitle.'04',name=>'April',sname=>'Apr',start=>mktime(0,0,0,4,$start_day,$ytitle),stop=>mktime(0,0,0,5,$start_day,$ytitle)), Array('id'=>'05','url'=>$ytitle.'05',name=>'May',sname=>'May',start=>mktime(0,0,0,5,$start_day,$ytitle),stop=>mktime(0,0,0,6,$start_day,$ytitle)), Array('id'=>'06','url'=>$ytitle.'06',name=>'June',sname=>'Jun',start=>mktime(0,0,0,6,$start_day,$ytitle),stop=>mktime(0,0,0,7,$start_day,$ytitle)), Array('id'=>'07','url'=>$ytitle.'07',name=>'July',sname=>'Jul',start=>mktime(0,0,0,7,$start_day,$ytitle),stop=>mktime(0,0,0,8,$start_day,$ytitle)), Array('id'=>'08','url'=>$ytitle.'08',name=>'August',sname=>'Aug',start=>mktime(0,0,0,8,$start_day,$ytitle),stop=>mktime(0,0,0,9,$start_day,$ytitle)), Array('id'=>'09','url'=>$ytitle.'09',name=>'September',sname=>'Sep',start=>mktime(0,0,0,9,$start_day,$ytitle),stop=>mktime(0,0,0,10,$start_day,$ytitle)), Array('id'=>'10','url'=>$ytitle.'10',name=>'October',sname=>'Oct',start=>mktime(0,0,0,10,$start_day,$ytitle),stop=>mktime(0,0,0,11,$start_day,$ytitle)), Array('id'=>'11','url'=>$ytitle.'11',name=>'November',sname=>'Nov',start=>mktime(0,0,0,11,$start_day,$ytitle),stop=>mktime(0,0,0,12,$start_day,$ytitle)), Array('id'=>'12','url'=>$ytitle.'12',name=>'December',sname=>'Dec',start=>mktime(0,0,0,12,$start_day,$ytitle),stop=>mktime(0,0,0,1,$start_day,$ytitle+1))); } else if (strlen($title) == 6) { // month $name="Day"; $next_month=($mtitle!=12 ? $mtitle+1 : 1); $next_year=($mtitle!=12 ? $ytitle : $ytitle + 1); $start=mktime(0,0,0,$mtitle,$start_day,$ytitle); $finish=mktime(0,0,0,$next_month,$start_day,$next_year); $days_max=$monlen[intval(substr($title,4,2))]; for ($i=1;$i<=$days_max;$i++) { $days[]=$i; } $days=array_merge( array_slice($days,$start_day-1,($days_max-$start_day)+1), array_slice($days,0,$start_day-1)); $month=$mtitle; $year=$ytitle; foreach ($days as $i) { $day=str_pad($i,2,"0",STR_PAD_LEFT); $output[$i]['id']=$day; $output[$i]['start']=mktime(0,0,0,$month,$i,$year); $output[$i]['stop']=mktime(0,0,0,($i!=$days_max ? $month : $next_month), ($i!=$days_max ? $i+1 : 1), ($i!=$days_max ? $year : $next_year)); $output[$i]['url']=date("Ymd",$output[$i]['start']); if ($i==$days_max) { $month=$next_month; $year=$next_year; } } } else if (strlen($title) == 8) { // day $name="Hour"; $days_max=$monlen[intval(substr($title,4,2))]; $next_month=($dtitle!=$days_max ? $mtitle : ($mtitle!=12 ? $mtitle+1 : 1)); $next_year=($dtitle!=$days_max ? $ytitle : ($mtitle!=12 ? $ytitle : $ytitle + 1)); $start=mktime(0,0,0,$mtitle,$dtitle,$ytitle); $finish=mktime(0,0,0,($dtitle!=$days_max ? $mtitle : $next_month), ($dtitle!=$days_max ? $dtitle+1 : 1), ($dtitle!=$days_max ? $ytitle : $next_year)); for ($i=$start;$i<$finish;$i+=3600) { $hour=date("H",$i); $hour=str_pad($hour,2,"0",STR_PAD_LEFT); $output[]=Array('id'=>$hour,'name'=>$hour.":00–".$hour.":59",'sname'=>$hour,'start'=>$i,'stop'=>$i+3600); } } $debug="start: ".microtime()."\n"; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { if ($file+86400 <= $start || $file >= $finish) { continue; } $fd=file_get_contents($dir.$file); $z=explode(" ",str_replace("\n","",$fd)); foreach ($output as $key => $period) { if ($period['start'] >= $file+86400 || $period['stop'] <= $file) { continue; } if (MODE==PLUSNET || MODE==AAISP) { list ($y,$m,$d) = explode(" ",gmdate("Y m d",$file)); } if ($period['start'] <= $file && $period['stop'] >= $file+86400) { $all=TRUE; } if ((MODE==NORMAL || DAY) && $all) { // load the whole file $debug.="load: $file (all) to ".$period['id']."\n"; $data[$key][RX]+=array_sum(array_slice($z,0,24)); $data[$key][TX]+=array_sum(array_slice($z,24,24)); } else { // load part of the file if ($all) { $debug.="load: $file (all) to ".$period['id']."\n"; $offset=0; $length=24; } else { if ($period['start'] <= $file) { $offset=0; } else { $offset=($period['start'] - $file)/3600; } if ($period['stop'] >= $file+86400) { $length=24 - $offset; } else { $length=($period['stop'] - $file)/3600 - $offset; } $debug.="load: $file ($offset+$length) to ".$period['id']."\n"; } if (MODE==NORMAL || DAY) { $data[$key][RX]+=array_sum(array_slice($z,$offset,$length)); $data[$key][TX]+=array_sum(array_slice($z,24+$offset,$length)); } else if (MODE==PLUSNET) { for ($i=$file+$offset*3600,$j=$offset; $j<$offset+$length; $i+=3600,$j++) { $h=date("G",$i); if (isset($peak[$h])) { $data[$key][RX]+=$z[$j]; $data[$key][RX]+=$z[24+$j]; } else { $data[$key][TX]+=$z[$j]; $data[$key][TX]+=$z[24+$j]; } } } else if (MODE==AAISP) { for ($i=$file+$offset*3600,$j=$offset; $j<$offset+$length; $i+=3600,$j++) { $h=date("G",$i); $w=date("w",$i); if (isset($peak[$h]) && $w!=0 && $w!=6) { $data[$key][RX]+=$z[$j]; $data[$key][TX]+=$z[24+$j]; } else { $data[$key][TX]+=$z[$j]; $data[$key][TX]+=$z[24+$j]; } } } } } } } } $debug.="end: ".microtime()."\n"; if (!isset($data)) { header("HTTP/1.1 404 No Data"); header("Content-Type: text/plain"); echo "No data for $title\n"; die(); } ?>
'.$name.' | '; echo ''.$receive.' ('.$use[1].') | '; echo ''.$transmit.' ('.$use[1].') | '; echo 'Total ('.$use[1].') | '; echo 'Ratio | '; echo '
---|---|---|---|---|
'; if (($data[$key][RX] == 0 && $data[$key][TX] == 0) || !isset($period['url'])) { echo $sname; } else { echo ''.$sname.''; } echo ' | '; echo ''.sprintf("%01.2f",round($data[$key][RX]/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round($data[$key][TX]/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round(($data[$key][RX]+$data[$key][TX])/$use[0],2)).' | '; echo ''; if ($data[$key][RX] == 0 || $data[$key][TX] == 0) { echo ' | '; } else if ($data[$key][RX] > $data[$key][TX]) { echo sprintf("%01.2f",round($data[$key][RX]/$data[$key][TX],2)).' : 1'; } else if ($data[$key][RX] < $data[$key][TX]) { echo sprintf("%01.2f",round($data[$key][RX]/$data[$key][TX],2)).' : 1'; } else if ($data[$key][RX] == $data[$key][TX]) { echo '1 : 1'; } echo '
Average | '; echo ''.sprintf("%01.2f",round($arx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round($atx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round(($arx+$atx)/$use[0],2)).' | '; echo ''; echo ' |
Median | '; echo ''.sprintf("%01.2f",round($mrx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round($mtx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round($mcx/$use[0],2)).' | '; echo ''; if ($mrx == 0 || $mtx == 0) { echo ' '; } else if ($mrx > $mtx) { echo sprintf("%01.2f",round($mrx/$mtx,2)).' : 1'; } else if ($mrx < $mtx) { echo sprintf("%01.2f",round($mrx/$mtx,2)).' : 1'; } else if ($mrx == $mtx) { echo '1 : 1'; } echo ' | '; echo '
Total | '; echo ''.sprintf("%01.2f",round($rx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round($tx/$use[0],2)).' | '; echo ''.sprintf("%01.2f",round(($rx+$tx)/$use[0],2)).' | '; echo ''; if ($rx == 0 || $tx == 0) { echo ' '; } else if ($rx > $tx) { echo sprintf("%01.2f",round($rx/$tx,2)).' : 1'; } else if ($rx < $tx) { echo sprintf("%01.2f",round($rx/$tx,2)).' : 1'; } else if ($rx == $tx) { echo '1 : 1'; } echo ' | '; echo '