diff --git a/module/metric/calc/global/hour/hour_of_daily_effort.php b/module/metric/calc/global/hour/hour_of_daily_effort.php new file mode 100644 index 0000000000..665398e1be --- /dev/null +++ b/module/metric/calc/global/hour/hour_of_daily_effort.php @@ -0,0 +1,54 @@ + + * @package + * @uses func + * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) + * @Link https://www.zentao.net + */ +class hour_of_daily_effort extends baseCalc +{ + public $result = array(); + + public function getStatement() + { + return $this->dao->select("year(date) as year, month(date) as month, day(date) as day, sum(consumed) as consumed") + ->from(TABLE_EFFORT) + ->where('deleted')->eq('0') + ->andWhere('year(date)')->ne('0000') + ->groupBy('`year`, `month`, `day`') + ->query(); + } + + public function calculate($row) + { + $year = $row->year; + $month = $row->month; + $day = $row->day; + $consumed = $row->consumed; + + $this->result[$year] = array(); + $this->result[$year][$month] = array(); + $this->result[$year][$month][$day] = $consumed; + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('year', 'month', 'day', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/test/calc/global/hour/hour_of_daily_effort.php b/module/metric/test/calc/global/hour/hour_of_daily_effort.php new file mode 100644 index 0000000000..826912dae8 --- /dev/null +++ b/module/metric/test/calc/global/hour/hour_of_daily_effort.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +config('effort', $useCommon = true, $levels = 4)->gen(1000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=hour_of_daily_effort +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('11'); // 测试分组数。 + +r($calc->getResult(array('year' => '2014'))) && p('0:value') && e('7.5'); // 测试2014年。 +r($calc->getResult(array('year' => '2016'))) && p('0:value') && e('2.5'); // 测试2016年。