westdc-zf1/application/default/controllers/VisualController.php

146 lines
3.3 KiB
PHP
Raw Normal View History

<?php
class VisualController extends Zend_Controller_Action
{
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db');
2012-04-24 16:16:27 +00:00
$this->dbh = new PDO("pgsql:dbname=qinghaihu;host=localhost", "gis", "gispassword" );
}
function indexAction()
{
}
function getTemperatureByStation($sid)
{
$sql = "select id,station_id as sid,date,avg_air_temperature as temp from daily_meteorological_data where station_id=$sid";
$sth = $this->dbh->prepare($sql);
$sth->execute();
$temp = $sth->fetchAll();
$dataSet = array();
foreach ($temp as $k=>$v)
{
$dataSet[] = array(strtotime($v['date'])*1000,$v['temp']);
}
unset($temp);
return $dataSet;
}
function createTemperatureDataSet($sid)
{
$data = array(
"name"=>"站点:$sid",
"data"=>$this->getTemperatureByStation($sid),
"tooltip"=>array(
"valueDecimals"=> 1,
"valueSuffix"=> '°C'
)
);
return $data;
}
function dataAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$sql = "select station_id as sid from daily_meteorological_data group by station_id";
$sth = $this->dbh->prepare($sql);
$sth->execute();
$stations = $sth->fetchAll();
$datas = array();
foreach($stations as $v)
{
$datas[]=$this->createTemperatureDataSet($v['sid']);
}
$data = array(
"label"=>"气温",
"title"=>'气温',
"datas"=>$datas
);
$this->jsonexit($data);
return true;
}
function utcMsTime($time=''){
if(empty($time))
return (time()+8*3600)*1000;
else
return $time*1000;
}
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return application/JSON
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}//jsonexit() 退出并返回json数据
}
/*
数据模型
"data"=>array(
//第一条曲线
"data1"=>array(
"title"=>"5米风速",
"unit"=>"m/s",
"sensor"=>"传感器XXX",
"sensor_type"=>"传感器类型",
"datas"=>array(
array($this->utcMsTime(),26.0),
array($this->utcMsTime()+3600*1000,28.1),
array($this->utcMsTime()+7200*1000,30.9),
array($this->utcMsTime()+10800*1000,32.0),
array($this->utcMsTime()+12800*1000,28.0),
array($this->utcMsTime()+13800*1000,22.0)
)
),
//第二条曲线
"data2"=>array(
"title"=>"10米风速",
"unit"=>"m/s",
"sensor"=>"传感器XXX",
"sensor_type"=>"传感器类型",
"datas"=>array(
array($this->utcMsTime(),26.0),
array($this->utcMsTime()+5600*1000,22.1),
array($this->utcMsTime()+8200*1000,35.9),
array($this->utcMsTime()+11800*1000,32.0),
array($this->utcMsTime()+13900*1000,22.0),
array($this->utcMsTime()+16800*1000,21.0)
)
),
//第三条.......
)
*/