Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
home
/
nonga.eemo.co.kr
/
public_html
/
www
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/nonga.eemo.co.kr/public_html/www/test_tot.php
<? session_cache_limiter('no-cache, must-revalidate'); session_start(); header("Pragma: no-cache"); header("Cache-Control: no-cache,must-revalidate"); header("Content-Type: text/html; charset=UTF-8"); ini_set('max_execution_time',86400); include_once("dbconn.php"); include_once("lib.php"); $arr_base_time=array(); $arr_base_date=array(); $result_time_base=mysql_query("select concat(date(jtime),' ',LPAD(hour(jtime),2,'0')) as vdate, no, humi from iot_raw where dong_no='31' group by concat(date(jtime),' ',LPAD(hour(jtime),2,'0')) order by jtime asc ") or die(mysql_error()); while($rs_tt=mysql_fetch_array($result_time_base)) { $arr_base_time[]=$rs_tt[vdate]; } $result_time_base2=mysql_query("select date(jtime) as jdate from iot_raw where dong_no='31' group by date(jtime) order by jtime asc ") or die(mysql_error()); while($rs_tt2=mysql_fetch_array($result_time_base2)) { $arr_base_date[]=$rs_tt2[jdate]; } $result_sens=mysql_query("select * from iot_raw where 1 group by sensor_no ") or die(mysql_error()); while($rs_sens=mysql_fetch_array($result_sens)) { foreach($arr_base_time as $tk => $tv) { $exp_time=explode(" ",$tv); $rs_tot=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sens[sensor_no]}' and date(jtime)='{$exp_time[0]}' and LPAD(hour(jtime),2,'0')='{$exp_time[1]}' "); echo "select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sens[sensor_no]}' and date(jtime)='{$exp_time[0]}' and LPAD(hour(jtime),2,'0')='{$exp_time[1]}' <br>"; $rs_hour=RS("select * from iot_hour where sensor_no='{$rs_sens[sensor_no]}' and jdate='{$exp_time[0]}' and jhour='{$exp_time[1]}' "); if(!$rs_hour[no]) { $query="insert into iot_hour set farm_no='{$rs_sens[farm_no]}', dong_no='{$rs_sens[dong_no]}', sensor_no='{$rs_sens[sensor_no]}', temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', jdate='{$exp_time[0]}', jhour='{$exp_time[1]}', uptime=now() "; mysql_query($query) or die(mysql_error()); } else { $query="update iot_hour set temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', uptime=now() where no='{$rs_hour[no]}' "; mysql_query($query) or die(mysql_error()); } echo $query."<br><br>"; } foreach($arr_base_date as $tk => $tv) { $rs_tot2=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sens[sensor_no]}' and date(jtime)='$tv' "); $rs_date=RS("select * from iot_date where farm_no='{$rs_sens[farm_no]}' and dong_no='{$rs_sens[dong_no]}' and sensor_no='{$rs_sens[sensor_no]}' and jdate='$tv' "); if(!$rs_date[no]) { $query="insert into iot_date set farm_no='{$rs_sens[farm_no]}', dong_no='{$rs_sens[dong_no]}', sensor_no='{$rs_sens[sensor_no]}', temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', jdate='$tv', uptime=now() "; mysql_query($query) or die(mysql_error()); } else { $query="update iot_date set temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', uptime=now() where no='{$rs_date[no]}' "; mysql_query($query) or die(mysql_error()); } echo $query."<br><br><br>"; } //echo $query."<br><br>"; } ?>