添加wsndata数据处理支持

This commit is contained in:
wlx 2013-09-25 14:07:28 +00:00
parent 013b2cdb32
commit c653459536
3 changed files with 176 additions and 1 deletions

View File

@ -22,7 +22,7 @@
die("Error in parameter.");
}
$sql="select dataorder.userid,dataset.path from dataorder left join dataset on dataorder.uuid=dataset.uuid
where dataorder.status in (0,5) and dataset.host='ftp1.westgis.ac.cn' and dataset.path<>''";
where dataorder.status in (0,5) and dataset.host='ftp2.westgis.ac.cn' and dataset.path<>'' and dataorder.selection is null";
if ($onlineappid>0)
$sql.=" and dataorder.onlineappid=".$onlineappid;
else if ($offlineappid>0)
@ -39,6 +39,23 @@
$content.='mkdir -p "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n";
$content.='mount --bind "'.$row['path'].'" "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n";
}
$sql="select distinct dataorder.userid,dataset.path,dataservice.uuid from dataorder left join dataset on dataorder.uuid=dataset.uuid left join dataservice on dataorder.uuid=dataservice.uuid
where dataorder.status in (0,5) and dataset.host='ftp2.westgis.ac.cn' and dataset.path<>'' and dataorder.selection is not null and dataservice.service_type in (1,2)";
if ($onlineappid>0)
$sql.=" and dataorder.onlineappid=".$onlineappid;
else if ($offlineappid>0)
$sql.=" and dataorder.offlineappid=".$offlineappid;
$result = pg_query($link, $sql);
$numrows = pg_num_rows($result);
$basepath='/disk1/WestDC/wsndata/';
for($ri = 0; $ri < $numrows; $ri++)
{
$row = pg_fetch_array($result, $ri);
$content.='# path: '.$row['path']."\n";
$content.='mkdir -p "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($basepath.'wsn_'.$row['userid'],'/')).'"'."\n";
$content.='mount --bind "'.$row['path'].'" "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($basepath.'wsn_'.$row['userid'],'/')).'"'."\n";
}
$filename='./proftp-user.sh';
if (!empty($content))
if (!file_put_contents($filename, $content, LOCK_EX))

View File

@ -30,6 +30,7 @@
umask($old);
if ($filelist)
{
set_time_limit(0);
//是否应当移除FTP信息即用户提交后不再有权限更新
//todo...

157
tools/wsndata.php Normal file
View File

@ -0,0 +1,157 @@
<?php
set_time_limit(0);
//安全检查只接受来自westdc.westgis.ac.cn的访问
if(@$_SERVER['HTTP_CLIENT_IP']){
$onlineip=$_SERVER['HTTP_CLIENT_IP'];
}elseif(@$_SERVER['HTTP_X_FORWARDED_FOR']){
$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$onlineip=$_SERVER['REMOTE_ADDR'];
}
if ($onlineip!='210.77.68.241' && $onlineip!='210.77.68.215' && $onlineip!='2001:cc0:f006::9')
die("error! You are not permitted to visit this page.".$onlineip);
$db = new PDO('pgsql:host=210.77.68.40;dbname=observation', "gis", "gispassword");
$station = 0;
$site = 0;
$logger = 0;
$variable = 0;
$start;
$end;
$uid=0;
$sitename="";
$mailname = "";
$createtime = date("Ymd",time());
$endtime="";
$html="";
$time="";
$value="";
$var="";
$file=array();
$basepath='/disk1/WestDC/wsndata/';
//接收用户uid只生成这个用户的数据
$uid = (int)@$_GET['uid'];
if (!($uid>0))
{
die("Error in parameter.");
}
if(!empty($uid))
{
$sql_user = "SELECT * from users_pm_down where starttime is not null and result=-1 and type='down' and uid=$uid";
$sth_user = $db->query($sql_user);
$rows_user = $sth_user->fetchAll();
//有需要生成的数据
if(!empty($rows_user))
{
foreach($rows_user as $k=>$v )
{
//逐个生成
$site = $v['site'];
$variable = $v['variable'];
$start = $v['starttime'];
$end = $v['endtime'];
$uid = $v['uid'];
//计算有多少天
$days=round((strtotime($end)-strtotime($start))/3600/24)+1;
//获取观测点的名称
$sql_site= "SELECT fld_name from tbl_site_info where fld_site_id=$site";
$sth_site = $db->query($sql_site);
$rows_site = $sth_site->fetch();
$sitename= $rows_site['fld_name'];
//获取用户的邮箱
$sql_mail= "SELECT email from users where id=$uid";
$sth_mail = $db->query($sql_mail);
$rows_mail = $sth_mail->fetch();
if(empty($rows_mail))
{$rows_mail['email']=="wuadan@lzb.ac.cn";}
//先为该用户创建一个文件夹
$aimDir_user=$basepath.'wsn_'.$uid;
if (!file_exists($aimDir_user))
{
$result = mkdir($aimDir_user);
}
//在该用户文件夹下面再建立一个观测点文件夹
$aimDir_site=$aimDir_user.DIRECTORY_SEPARATOR.$site;
if (!file_exists($aimDir_site))
{
$result = mkdir($aimDir_site);
}
//选择全部变量
if($variable==-1)
{
//获取数据
for ($i = 1; $i <= $days; $i++)
{
$endtime=date("Y-m-d 00:00:00",strtotime($start)+24*3600);
$sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<'$endtime' ORDER BY time ";
$sth2 = $db->query($sql2);
$rows2 = $sth2->fetchAll();
$datamount=count( $rows2);
//组装数据
$html="";
foreach($rows2 as $k=>$v)
{
$time[$k] = $v['time'];
$value[$k] = $v['value'];
$var[$k] = $v['variablename'];
$html .=$time[$k].",".$var[$k].",".$value[$k]."\n";
}
$head = "Time,Variable,Value, \n";
//将数据写入文件
$resulttime=date("Ymd",strtotime($start));
$fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_all_".$resulttime.".CSV","a"); //打开csv文件如果不存在则创建
fwrite($fp,$head.$html); //写入数据
fclose($fp); //关闭文件句柄
$start = $endtime;
}
$sql_up= "update users_pm_down set result=0 WHERE site=$site and variable=-1 and uid=$uid and result=-1 and type='down'";
$sth_up = $db->query($sql_up);
} else {
//获取观测变量的名称
$sql3= "SELECT fld_name from tbl_variable_info where fld_variable_id=$variable";
$sth3 = $db->query($sql3);
$rows3 = $sth3->fetch();
$varname=$rows3['fld_name'];
//获取数据
$endtime="";
for ($i = 1; $i <= $days; $i++)
{
$endtime=date("Y-m-d H:m:s",strtotime($start)+24*3600);
$sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_variable_id =$variable and v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<='$endtime' ORDER BY time ";
$sth2 = $db->query($sql2);
$rows2 = $sth2->fetchAll();
$datamount=count( $rows2);
//组装数据
$html="";
foreach($rows2 as $k=>$v)
{
$time[$k] = $v['time'];
$value[$k] = $v['value'];
$var[$k] = $v['variablename'];
$html .=$time[$k].",".$var[$k].",".$value[$k]."\n";
}
$head = "Time,Variable,Value, \n";
//写入文件
$resulttime=date("Ymd",strtotime($start));
$fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_".$varname."_".$resulttime.".CSV","a+");
fwrite($fp,$head.$html); //写入数据
fclose($fp); //关闭文件句柄
$start = $endtime;
}
//给处理的数据做个标记result=0
$sql_up= "update users_pm_down set result=0 WHERE site=$site and variable=$variable and uid=$uid and result=-1 and type='down'";
$sth_up = $db->query($sql_up);
}
}
}
}