Files
OMS/app/eccommon/lib/analysis/base.php
2025-12-28 23:13:25 +08:00

58 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
class eccommon_analysis_base
{
/**
* fetch_graph_data
* @param mixed $params 参数
* @return mixed 返回值
*/
public function fetch_graph_data($params)
{
$analysis_info = app::get('eccommon')->model('analysis')->select()->columns('*')->where('service = ?', $params['service'])->instance()->fetch_row();
if(empty($analysis_info)) return array('categories'=>array(), 'data'=>array());
$obj = app::get('eccommon')->model('analysis_logs')->select()->columns('target, flag, value, time')->where('analysis_id = ?', $analysis_info['id']);
$obj->where('target = ?', $params['target']);
$obj->where('time >= ?', strtotime(sprintf('%s 00:00:00', $params['time_from'])));
$obj->where('time <= ?', strtotime(sprintf('%s 23:59:59', $params['time_to'])));
if(isset($this->_params['type'])) $obj->where('type = ?', $params['type']);
$rows = $obj->instance()->fetch_all();
$time_range = [];
for($i=strtotime($params['time_from']); $i<=strtotime($params['time_to']); $i+=($analysis_info['interval'] == 'day')?86400:3600){
$time_range[] = ($analysis_info['interval'] == 'day') ? date("Y-m-d", $i) : date("Y-m-d H", $i);
}
$logs_options = kernel::single($params['service'])->logs_options;
$target = $logs_options[$params['target']];
if(is_array($target['flag']) && count($target['flag'])){
foreach($target['flag'] AS $k=>$v){
foreach($time_range AS $date){
$data[$v][$date] = 0;
}
}
}else{
foreach($time_range AS $date){
$data['全部'][$date] = 0;
}
}
foreach($rows AS $row){
$date = ($analysis_info['interval'] == 'day') ? date("Y-m-d", $row['time']) : date("Y-m-d H", $row['time']);
$flag_name = $target['flag'][$row['flag']];
if($flag_name){
$data[$flag_name][$date] = $row['value'];
}else{
$data['全部'][$date] = $row['value'];
}
}
return array('categories'=>$time_range, 'data'=>$data);
}//End Function
}//End Class