前台可视化依据新表结构的修改

This commit is contained in:
wlx 2015-01-21 07:22:29 +00:00
parent 0d251e4206
commit 1d4629d22a
3 changed files with 47 additions and 159 deletions

View File

@ -50,7 +50,6 @@ class VisualController extends Zend_Controller_Action
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$uuid = $this->_getParam("uuid"); $uuid = $this->_getParam("uuid");
//$record_type = $this->_getParam("dataset");
$record_subset = $this->_getParam("subdataset"); $record_subset = $this->_getParam("subdataset");
$record = new Visual\Record($uuid,$record_subset); $record = new Visual\Record($uuid,$record_subset);

View File

@ -30,11 +30,11 @@ $this->nav[] = array('link'=>"/data/visual",'title'=>'可视化数据列表');
</div> </div>
<hr /> <hr />
<?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?> <?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['variable']);?>
<?php foreach($vars as $k=>$v) { ?> <?php foreach($vars as $k=>$v) { ?>
<a class="btn btn-default control-btn" href="javascript:void(0);" data-dataset="" data-subdataset="<?= $v['field'] ?>" data-seriename="<?= $v['name'] ?>"> <a class="btn btn-default control-btn" href="javascript:void(0);" data-subdataset="<?= $v['name'] ?>" data-seriename="<?= $v['title'] ?>">
<?= $v['name'] ?> <?= $v['title'] ?>
</a> </a>
<?php } ?> <?php } ?>
@ -67,7 +67,6 @@ $(function() {
Highcharts.setOptions({ Highcharts.setOptions({
lang: { lang: {
months : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], months : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
//months : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
weekdays: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'] weekdays: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
}, },
global: { global: {
@ -87,17 +86,7 @@ $(function() {
}, },
xAxis: { xAxis: {
type: 'datetime', type: 'datetime'
dateTimeLabelFormats: {
second: '%Y-%m-%d<br/>%H:%M:%S',
minute: '%Y-%m-%d<br/>%H:%M',
hour: '%Y-%m-%d<br/>%H:%M',
day: '%Y<br/>%m-%d',
week: '%Y<br/>%m-%d',
month: '%Y-%m',
year: '%Y'
}
}, },
tooltip : { tooltip : {
@ -138,7 +127,7 @@ $(function() {
$.ajax({ $.ajax({
'url': '/visual/data', 'url': '/visual/data',
'data': 'uuid=' + uuid + '&dataset=' + dataset + '&subdataset=' + subdataset, 'data': 'uuid=' + uuid + '&subdataset=' + subdataset,
'method': 'GET', 'method': 'GET',
'dataType': 'json', 'dataType': 'json',
'success': function(data){ 'success': function(data){

View File

@ -4,25 +4,16 @@ namespace Westdc\Visual;
class Record extends Database class Record extends Database
{ {
public $subdataset,$valueFilter,$vars; public $subdataset,$valueFilter,$vars,$uuid,$xaxis;
public $timeFiled = "utctime";
private $sql; private $sql;
function __construct($uuid = NULL,$identifier = "") function __construct($uuid,$identifier )
{ {
parent::__construct(); parent::__construct();
if(!empty($identifier)) $this->uuid=$uuid;
{
$this->subdataset = $identifier; $this->subdataset = $identifier;
} $this->init();
if(!empty($uuid) && !empty($identifier))
{
$this->initVisual($uuid);
}
} }
public function __invoke() public function __invoke()
@ -30,72 +21,24 @@ class Record extends Database
return $this->getData(); return $this->getData();
} }
public function initVisual($uuid) public function init()
{ {
$visual = new Visual; $visual = new Visual;
$var_data = $visual->getVisualVars($uuid); $var_data = $visual->getVisualVars($this->uuid);
$this->vars = $var_data['vars']; $this->vars = $var_data['variable'];
$this->xaxis=$var_data['xaxis'];
if(!empty($var_data['visual_valuefilter'])) $json=json_decode($this->vars,true);
$this->valueFilter = (float)$var_data['visual_valuefilter']; $subvar=array_filter($json,function($sub) { return $sub['name']==$this->subdataset; });
if (isset($subvar['sql']) && !empty($subvar['sql']))
if($var_data['visual_timefield_model'] == 'single') { $this->sql=$this->makeSql($subvar['sql']);
$this->timeFiled = '"' . $var_data['visual_timefield'] . '"'; elseif(isset($var_data['data']) && !empty($var_data['data']))
}//single
elseif($var_data['visual_timefield_model'] == 'multiple'){
$timefield_temp = "(";
if(!empty($var_data['visual_timefield_year']))
{ {
$timefield_temp .= $var_data['visual_timefield_year'] . "::character varying||"; $condition=null;
if (isset($subvar['condition']) && !empty($subvar['condition']))
$condition=$subvar['condition'];
$this->sql = $this->makeSql($var_data['data'],$condition);
} }
$timefield_temp .= "'-'";
if(!empty($var_data['visual_timefield_month']))
{
$timefield_temp .= "||".$var_data['visual_timefield_month']."::character varying||";
}else{
$timefield_temp .= '1';
}
$timefield_temp .= "'-";
if(!empty($var_data['visual_timefield_day']))
{
$timefield_temp .= "'||".$var_data['visual_timefield_day'] . '::character varying';
}else{
$timefield_temp .= "1'";
}
$timefield_temp .= ")";
$timefield_temp .= "::timestamp without time zone";
$this->timeFiled = $timefield_temp;
}//multiple
elseif($var_data['visual_timefield_model'] == 'custom'){
$this->timeFiled = $var_data['visual_timefield_custom'];
}//custom
//时间字段为空的bug
if(empty($var_data['visual_timefield_model'])){
$this->timeFiled = "utctime";
}else{
if($var_data['visual_timefield_model'] == 'single' && empty($var_data['visual_timefield'])){
$this->timeFiled = "utctime";
}elseif($var_data['visual_timefield_model'] == 'multiple' && empty($var_data['visual_timefield_year'])){
$this->timeFiled = "utctime";
}elseif($var_data['visual_timefield_model'] == 'custom' && empty($var_data['visual_timefield_custom'])) {
$this->timeFiled = "utctime";
}
}
if(isset($var_data['data']) && !empty($var_data['data']))
$this->sql = $this->makeSql($var_data['data']);
else
$this->sql = $this->makeSql($var_data['visual_datatable']);
//echo $this->sql;exit(); //echo $this->sql;exit();
} }
@ -114,57 +57,36 @@ class Record extends Database
$row['utctime'] = $this->utcMsTime(strtotime($row['utctime'])); $row['utctime'] = $this->utcMsTime(strtotime($row['utctime']));
//var_dump($row); //var_dump($row);
$data[] = array( $t=[];
$row['utctime'], foreach($row as $k=>$v)
$row['value'] $t[]=$v;
); $data[] = $t;
} }
return $data; return $data;
} }
public function makeSql($table) public function makeSql($table,$condition=NULL)
{ {
$wheresql = ""; $wheresql = "";
if ($condition)
if(!empty($this->valueFilter))
{ {
$wheresql = " WHERE \"$this->subdataset\"<>".$this->valueFilter .' '; $filter=explode(';',$condition);
}
$filter = $this->getFilter($this->subdataset);
if(!empty($filter)) if(!empty($filter))
{ {
if(is_string($filter)) if(is_string($filter))
$wheresql = ' WHERE "'.$this->subdataset.'"'. $filter .' '; $wheresql = " WHERE $filter ";
elseif(is_array($filter)) elseif(is_array($filter))
{ {
$wheresql = []; $wheresql = ' WHERE '.join(" AND ",$filter);
foreach($filter as $v)
{
if(preg_match("/^[<|>|=|!](.*)/",$v))
$wheresql[] = '"'.$this->subdataset.'"'.$v;
else
$wheresql[] = $v;
} }
$wheresql = ' WHERE '.join(" AND ",$wheresql);
} }
} }
$sql = "SELECT $sql = "SELECT {$this->xaxis},{$this->subdataset}
{$this->timeFiled} as utctime , \"{$this->subdataset}\" as value FROM ($table) as tbl
FROM $table as tbl
$wheresql $wheresql
ORDER BY ORDER BY {$this->xaxis}";
extract(YEAR from {$this->timeFiled}) ASC,
extract(MONTH from {$this->timeFiled}) ASC,
extract(DAY from {$this->timeFiled}) ASC,
extract(HOUR from {$this->timeFiled}) ASC,
extract(MINUTE from {$this->timeFiled}) ASC,
extract(SECOND from {$this->timeFiled}) ASC
";
return $sql; return $sql;
} }
@ -174,26 +96,4 @@ class Record extends Database
else else
return ($time)*1000; return ($time)*1000;
} }
public function getFilter($subdataset)
{
$vars = json_decode($this->vars,TRUE);
if(!is_array($vars) || count($vars)<1)
return null;
foreach($vars as $v)
{
if($v['field'] == $subdataset)
{
if(isset($v['filter']) && !empty($v['filter']))
{
return $v['filter'];
}else{
return null;
}
}
}
return null;
}
} }