* Format code.

This commit is contained in:
qixinzhi
2023-07-05 03:06:00 +00:00
parent 2c3ea87e8f
commit e4948091c1
5 changed files with 15 additions and 203 deletions
+5 -2
View File
@@ -35,12 +35,13 @@ class metric extends control
list($otherInstances, $classifiedInstances) = $this->metric->classifyMetric($metricInstances);
/* 计算根据数据源归类后的度量项。*/
foreach($classifiedInstances as $dataSource => $metricInstances)
{
$fieldList = $this->uniteFieldList($metricInstances);
$data = $dataset->$dataSource($fieldList)->fetchAll();
$rows = $dataset->$dataSource($fieldList)->fetchAll();
foreach($data as $row)
foreach($rows as $row)
{
foreach($metricInstances as $instance)
{
@@ -49,8 +50,10 @@ class metric extends control
}
}
/* 处理无法归类的度量项,直接赋值dao。*/
foreach($otherInstances as $instance) $instance->dao = $this->dao;
/* 获取度量项的计算结果并保存。*/
foreach($metricInstances as $instance)
{
$resultSet = $instance->getResult();
+1 -199
View File
@@ -27,41 +27,6 @@ class func
* @access public
*/
public $fieldList;
/**
* 收集方式。可选项:实时更新|定时任务|动作触发
* Collection methods of measurement.Options: realtime|cron|action
*
* @var string
* @access public
*/
public $collectType;
/**
* 范围。可选项:全局|项目集|项目|执行|产品|个人|团队
* Range of measurement.Options: global|project|execution|product|user|dept
*
* @var string
* @access public
*/
public $scope;
/**
* 目的。可选项:规模估算|质量控制|工时统计|成本计算|效率提升|工期控制
* Purpose of measurement.Options: scale|qc|hour|cost|rate|time
*
* @var string
* @access public
*/
public $purpose;
/**
* 收集频率。
* Frequence of collection.
*
* @var string
* @access public
*/
public $collectCFG;
/**
* 数据主表。
@@ -79,7 +44,7 @@ class func
* @var array
* @access public
*/
public $leftJoins;
public $subTables;
/**
* 过滤条件。
@@ -90,24 +55,6 @@ class func
*/
public $filters;
/**
* 分组方式。
* Groups of data.
*
* @var array
* @access public
*/
public $groups;
/**
* 指标。
* Indicators of measurement.
*
* @var array
* @access public
*/
public $indicators;
/**
* 指标结果。
* Result of indicators.
@@ -117,26 +64,6 @@ class func
*/
public $result;
/**
* 根据主表和连接表,抽取数据库表和字段。
*
* @access public
* @return void
*/
public function getTables()
{
}
/**
* 根据主表和连接表,生成sql。
*
* @access public
* @return void
*/
public function getSql($fields)
{
}
/**
* 计算度量项。
* Calculate metric.
@@ -163,131 +90,6 @@ class func
{
}
/**
* 解析过滤条件,返回当前数据满足过滤条件的bool值。
*
* @param array $data
* @access public
* @return bool
*/
public function parseCondition($data)
{
$operator = $this->filter['operator'];
$conditions = $this->filter['conditions'];
return $this->traverseCondition($data, $operator, $conditions);
}
/**
* 根据指标属性获取对应指标的数据值。
*
* @param array $data
* @param array $indicator
* @access public
* @return string
*/
public function getIndicatorValue($data, $indicator)
{
$table = $indicator['table'];
$field = $indicator['field'];
return $this->getValue($data, $table, $field);
}
/**
* 递归遍历过滤条件,返回过滤条件的bool值。
*
* @param array $data
* @param string $operator
* @param int $conditions
* @access private
* @return void
*/
private function traverseCondition($data, $operator, $conditions)
{
$judgeBool = array();
foreach($conditions as $condition)
{
if(isset($condition['conditions']))
{
$subOperator = $condition['operator'];
$subConditions = $condition['conditions'];
$judgeBool[] = $this->traverseCondition($data, $subOperator, $subConditions);
continue;
}
$table = $condition['table'];
$field = $condition['field'];
$value = $condition['value'];
$dataValue = $this->getValue($data, $table, $field);
$judgeBool[] = self::getBoolByCondition($condition['operator'], $dataValue, $value);
// $judgeBool[] = eval("return {$dataValue} $condition['operator'] $value;");
}
$result = $operator == 'and' ? true : false;
foreach($judgeBool as $flag)
{
$result = $operator == 'and' ? ($result && $flag) : ($result || $flag);
}
return $result;
}
/**
* 根据字段和表,获取字段的数据值。
* Get value of field.
*
* @param array $data
* @param string $table
* @param string $field
* @access private
* @return void
*/
private function getValue($data, $table, $field)
{
return is_array($data) ? $data[$field] : ((array)$data)[$field];
}
/**
* 根据参数计算bool值。
* Compute boolean value by condition.
*
* @param string $operator
* @param string|number $left
* @param string|number $right
* @static
* @access public
* @return void
*/
public static function getBoolByCondition($operator, $left, $right)
{
$flag = false;
switch($operator)
{
case '=':
$flag = $left == $right;
break;
case '>':
$flag = $left > $right;
break;
case '>=':
$flag = $left >= $right;
break;
case '<':
$flag = $left < $right;
break;
case '<=':
$flag = $left <= $right;
break;
case '!=':
$flag = $left != $right;
break;
}
return $flag;
}
/**
* 根据字段分组。
* Group by field.
@@ -18,6 +18,8 @@ class count_of_marker_release extends func
public $fieldList = array('t1.id', 't1.marker');
public $result = 0;
public function calculate($data)
{
if(!empty($data->marker) and $data->marker == 1) $this->result ++;
@@ -18,6 +18,8 @@ class count_of_release_in_year extends func
public $fieldList = array('t1.id', 't1.createdDate');
public $result = array();
public function calculate($data)
{
$value = $data->createdDate;
+5 -2
View File
@@ -45,7 +45,9 @@ class metricModel extends model
$currentDay = date('d');
$now = date('H:i');
$metricList = $this->select('code,collectConf')->from(TABLE_BASICMEAS)->where('collectType')->eq('crontab')->fetchAll();
$metricList = $this->select('code,collectConf')->from(TABLE_BASICMEAS)
->where('collectType')->eq('crontab')
->fetchAll();
$excutableMetric = array();
foreach($metricList as $metric)
@@ -76,7 +78,8 @@ class metricModel extends model
foreach($this->config->metric->purposeList as $purpose)
{
$pattern = $funcRoot . $scope . DS . $purpose . DS . '*.php';
$fileList = array_merge($fileList, glob($pattern));
$matchedFiles = glob($pattern);
if($matchedFiles !== false) $fileList = array_merge($fileList, $matchFiles);
}
}