* Add recalculate single metric.
This commit is contained in:
@@ -34,6 +34,11 @@ $config->metric->actionList['delete']['url'] = helper::createLink('metr
|
||||
$config->metric->actionList['delete']['class'] = 'ajax-submit';
|
||||
$config->metric->actionList['delete']['data-confirm'] = $lang->metric->confirmDelete;
|
||||
|
||||
$config->metric->actionList['recalculate']['icon'] = 'refresh';
|
||||
$config->metric->actionList['recalculate']['text'] = $lang->metric->recalculate;
|
||||
$config->metric->actionList['recalculate']['hint'] = $lang->metric->recalculate;
|
||||
$config->metric->actionList['recalculate']['url'] = 'javascript:confirmRecalculate("{code}")';
|
||||
|
||||
$config->metric->necessaryMethodList = array('getStatement', 'calculate', 'getResult');
|
||||
|
||||
$config->metric->oldScopeMap = array();
|
||||
|
||||
@@ -70,4 +70,4 @@ $config->metric->dtable->definition->fieldList['actions']['type'] = 'actions
|
||||
$config->metric->dtable->definition->fieldList['actions']['sortType'] = false;
|
||||
$config->metric->dtable->definition->fieldList['actions']['list'] = $config->metric->actionList;
|
||||
$config->metric->dtable->definition->fieldList['actions']['fixed'] = 'right';
|
||||
$config->metric->dtable->definition->fieldList['actions']['menu'] = array('edit', 'implement', 'delist', 'delete');
|
||||
$config->metric->dtable->definition->fieldList['actions']['menu'] = array('edit', 'implement', 'delist', 'delete', 'recalculate');
|
||||
|
||||
@@ -158,6 +158,27 @@ class metric extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算一个度量项的历史数据。
|
||||
* Update history metric lib of single metric.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $date
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateSingleMetricLib($code, $date)
|
||||
{
|
||||
$date = str_replace('_', '-', $date);
|
||||
|
||||
$calc = $this->metric->calculateMetricByCode($code);
|
||||
$record = $this->metricZen->getRecordByCodeAndDate($code, $calc, $date);
|
||||
|
||||
$records = array();
|
||||
$records[$code] = $record;
|
||||
$this->metric->insertMetricLib($records, 'inference');
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算历史数据。
|
||||
* Update metric lib of history.
|
||||
@@ -443,11 +464,13 @@ class metric extends control
|
||||
* 重算度量项历史数据。
|
||||
* Recalculate metric history data.
|
||||
*
|
||||
* @param string $code
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function recalculate()
|
||||
public function recalculate($code = 'all')
|
||||
{
|
||||
$this->view->code = $code;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -456,14 +479,17 @@ class metric extends control
|
||||
* Show recalculate progress.
|
||||
*
|
||||
* @param string $calcType all|inference
|
||||
* @param string $code
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function recalculateProgress($calcType)
|
||||
public function recalculateProgress($calcType, $code = 'all')
|
||||
{
|
||||
$startDate = $this->metric->getInstallDate();
|
||||
if($calcType == 'all') $endDate = helper::now();
|
||||
|
||||
$this->view->code = $code;
|
||||
$this->view->dateType = $dateType;
|
||||
$this->view->startDate = substr($startDate, 0, 10);
|
||||
$this->view->endDate = substr($endDate, 0, 10);
|
||||
$this->display();
|
||||
|
||||
@@ -72,10 +72,10 @@ window.loadImplement = function(link)
|
||||
modal.render({url: link});
|
||||
}
|
||||
|
||||
window.confirmRecalculate = function()
|
||||
window.confirmRecalculate = function(code = 'all')
|
||||
{
|
||||
zui.Modal.confirm(confirmRecalculate).then((res)=>
|
||||
{
|
||||
if(res) zui.Modal.open({url: $.createLink('metric', 'recalculate')});
|
||||
if(res) zui.Modal.open({url: $.createLink('metric', 'recalculate', 'code=' + code)});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
window.showRecalculateProgress = function()
|
||||
window.showRecalculateProgress = function(code = 'all')
|
||||
{
|
||||
var calcType = $('.isCalcAll').prop('checked') ? 'all' : 'inference';
|
||||
var link = $.createLink('metric', 'recalculateProgress', 'calcType=' + calcType);
|
||||
var link = $.createLink('metric', 'recalculateProgress', 'calcType=' + calcType + '&code=' + code);
|
||||
loadPage(link);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
recalculate(startDate, endDate);
|
||||
if(code == 'all')
|
||||
{
|
||||
recalculateAll(startDate, endDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
recalculateSingle(code, startDate, endDate);
|
||||
}
|
||||
});
|
||||
|
||||
function recalculate(startDate, endDate)
|
||||
function recalculateAll(startDate, endDate)
|
||||
{
|
||||
var dateRange = getDateRange(startDate, endDate);
|
||||
|
||||
var calcLink = $.createLink('metric', 'saveClassifiedCalcGroup');
|
||||
$.get(calcLink, function(result){
|
||||
updateHistory(dateRange);
|
||||
updateAllHistory(dateRange);
|
||||
});
|
||||
|
||||
function updateHistory(dateRange, index = 0)
|
||||
function updateAllHistory(dateRange, index = 0)
|
||||
{
|
||||
if(index >= dateRange.length)
|
||||
{
|
||||
@@ -21,19 +28,37 @@ function recalculate(startDate, endDate)
|
||||
return;
|
||||
}
|
||||
|
||||
var date = dateRange[index];
|
||||
|
||||
var year = date.getFullYear();
|
||||
var month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
var day = date.getDate().toString().padStart(2, '0');
|
||||
|
||||
var date = year + '_' + month + '_' + day;
|
||||
var date = dateToString(dateRange[index]);
|
||||
var $html = recalculateLog(date);
|
||||
|
||||
var link = $.createLink('metric', 'updateHistoryMetricLib', 'date=' + date);
|
||||
$.get(link, function(result){
|
||||
$('.verify-content').append($html);
|
||||
updateHistory(dateRange, index + 1);
|
||||
updateAllHistory(dateRange, index + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function recalculateSingle(code, startDate, endDate)
|
||||
{
|
||||
var dateRange = getDateRange(startDate, endDate, dateType);
|
||||
updateSingleHistory(dateRange);
|
||||
function updateSingleHistory(dateRange, index = 0)
|
||||
{
|
||||
if(index >= dateRange.length)
|
||||
{
|
||||
var deduplication = $.createLink('metric', 'deduplicateRecord');
|
||||
$.get(deduplication, function(result){});
|
||||
return;
|
||||
}
|
||||
|
||||
var date = dateToString(dateRange[index]);
|
||||
var $html = recalculateLog(date);
|
||||
|
||||
var link = $.createLink('metric', 'updateSingleMetricLib', 'code=' + code + '&date=' + date);
|
||||
$.get(link, function(result){
|
||||
$('.verify-content').append($html);
|
||||
updateSingleHistory(dateRange, index + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -48,17 +73,30 @@ function recalculateLog(date)
|
||||
return html;
|
||||
}
|
||||
|
||||
function getDateRange(startDate, endDate)
|
||||
function getDateRange(startDate, endDate, dateType = 'day')
|
||||
{
|
||||
var startDate = new Date(startDate);
|
||||
var endDate = new Date(endDate);
|
||||
|
||||
var dateRange = [];
|
||||
while(startDate <= endDate)
|
||||
|
||||
if(dateType == 'day')
|
||||
{
|
||||
dateRange.push(new Date(startDate));
|
||||
startDate.setDate(startDate.getDate() + 1);
|
||||
while(startDate <= endDate)
|
||||
{
|
||||
dateRange.push(new Date(startDate));
|
||||
startDate.setDate(startDate.getDate() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return dateRange;
|
||||
}
|
||||
|
||||
function dateToString(date)
|
||||
{
|
||||
var year = date.getFullYear();
|
||||
var month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
var day = date.getDate().toString().padStart(2, '0');
|
||||
|
||||
return year + '_' + month + '_' + day;
|
||||
}
|
||||
|
||||
@@ -642,6 +642,34 @@ class metricModel extends model
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代号计算度量项。
|
||||
* Calculate metric by code.
|
||||
*
|
||||
* @param string $code
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function calculateMetricByCode($code)
|
||||
{
|
||||
$metric = $this->metricTao->fetchMetricByCode($code);
|
||||
if(!$metric) return false;
|
||||
|
||||
$calcPath = $this->getCalcRoot() . $metric->scope . DS . $metric->purpose . DS . $metric->code . '.php';
|
||||
if(!is_file($calcPath)) return false;
|
||||
|
||||
include_once $this->getBaseCalcPath();
|
||||
include_once $calcPath;
|
||||
$calculator = new $metric->code;
|
||||
|
||||
$statement = $this->getDataStatement($calculator, 'statement', 'rnd');
|
||||
$rows = $statement->fetchAll();
|
||||
|
||||
foreach($rows as $row) $calculator->calculate($row);
|
||||
|
||||
return $calculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代号获取计算实时度量项的结果。
|
||||
* Get result of calculate metric by code.
|
||||
|
||||
@@ -26,7 +26,7 @@ form
|
||||
btn
|
||||
(
|
||||
setClass('btn primary-outline'),
|
||||
bind::click('window.showRecalculateProgress()'),
|
||||
bind::click("window.showRecalculateProgress('$code')"),
|
||||
$lang->metric->recalculate
|
||||
)
|
||||
);
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace zin;
|
||||
jsVar('startDate', $startDate);
|
||||
jsVar('endDate', $endDate);
|
||||
jsVar('recalculateLogText', $lang->metric->recalculateLog);
|
||||
jsVar('code', $code);
|
||||
jsVar('dateType', $dateType);
|
||||
|
||||
detailHeader
|
||||
(
|
||||
|
||||
@@ -54,10 +54,7 @@ class metricZen extends metric
|
||||
*/
|
||||
protected function responseAfterCreate($metricID, $afterCreate, $from, $location)
|
||||
{
|
||||
if($afterCreate == 'back' && $location)
|
||||
{
|
||||
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => $location);
|
||||
}
|
||||
if($afterCreate == 'back' && $location) return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => $location);
|
||||
|
||||
$location = $this->createLink('metric', 'implement', "metricID=$metricID&from=$from");
|
||||
$callback = array('name' => 'loadImplement', 'params' => $location);
|
||||
|
||||
Reference in New Issue
Block a user