"4.84",1,0)) as dutyon, sum(if(data="4.84",1,0)) as dutyoff,sum(if(data<>"4.84",1,0))/((sum(if(data<>"4.84",1,0))+sum(if(data="4.84",1,0))))*100 as `Duty_Cycle` from logs where `time` > '.$mintime.' group by `hour` order by `time`';} if ($_GET['dutycycle']) { $query='select concat(left(date_format(`time`,"%m/%d/%Y %H:%i"),14),"00") as hour,sum(if(data<>"4.84",1,0))/((sum(if(data<>"4.84",1,0))+sum(if(data="4.84",1,0))))*100 as `Duty_Cycle` from logs where `time` > '.$mintime.' group by `hour` order by `time`';} if ($_GET['temp']) { $query='select date_format(datetime,"%m/%d/%Y %H:%i:%s") as hour,unix_timestamp(datetime) as `unixtime`,temp_in,temp_out from weather order by datetime asc limit 150'; $db='open2300';$pw='mysql2300'; $query='select date_format(datetime,"%m/%d/%Y %H:%i:%s") as hour,unix_timestamp(datetime) as `unixtime`,temp_in,temp_out from weather where datetime> '.$mintime.' order by datetime asc'; $db='open2300';$pw='mysql2300'; } if ($_GET['externaltemp']) { $query='select date_format(datetime,"%m/%d/%Y %H:%i:%s") as hour,temp_out from weather where datetime> '.$mintime.' order by datetime asc'; $db='open2300';$pw='mysql2300'; } if ($_GET['externaltempsummary']) { $query='select date_format(datetime,"%m/%d/%Y %H:00") as hour,temp_out from weather where datetime> '.$mintime.' group by hour order by datetime asc'; $db='open2300';$pw='mysql2300'; } if ($_GET['onoff']) { $query='select time,binary(data<>4.84) as status from logs where time > '.$mintime.' order by time'; db_connect(); $x=0; $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { $first=0; while($data=mysql_fetch_assoc($result)) { if (!$first) { $first=1; print '"'.implode('","',array_keys($data))."\"\n"; } if ($data['status']<>$x) { $x=$data['status']; if ($prior) { print '"'.implode('","',$prior)."\"\n"; } print '"'.implode('","',$data)."\"\n"; } $prior=$data; } } } // print $query."\n"; else if ($_GET['csv']) { db_connect(); $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { $first=0; while($data=mysql_fetch_assoc($result)) { if (!$first) { $first=1; print '"'.implode('","',array_keys($data))."\"\n"; } print '"'.implode('","',$data)."\"\n"; } } } else if ($_GET['csv2']) { db_connect(); $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { $first=0; while($data=mysql_fetch_assoc($result)) { if (!$first) { $first=1; print '"'.implode('","',array_keys($data))."\"\r\n"; } print '"'.implode('","',$data)."\"\r\n"; } } } else if ($_GET['csv3']) { db_connect(); $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { $first=0; while($data=mysql_fetch_assoc($result)) { print "'".implode("','",$data)."'\\n"; } } } else if ($_GET['csv4']) { db_connect(); $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { $first=0; while($data=mysql_fetch_assoc($result)) { print implode(",",$data)."\\n"; } } } elseif ($_GET['json']) { db_connect(); $result=mysql_db_query($db,$query,$connection); if (mysql_num_rows($result)) { while($data=mysql_fetch_assoc($result)) { /* if (!$first) { $first=1; print '"'.implode('","',array_keys($data))."\"\n"; } */ $out[]=$data; } print json_encode($out); } } else { include 'iam_xls.php'; $xls=new IAM_XLS; $xls->xlsName='furnacelog-'.date("YmdHis"); $xls->WriteSQLDump($query,$db,$db,$pw); } function db_connect() { global $connection,$db,$pw; $user = $db; $pass = $pw; #$server = "localhost"; # $server=":/tmp/mysql.sock"; $connection = mysql_pconnect($server, $user, $pass); } ?>