feat(dashboard): 添加区域转移概率统计功能
将1-49数字分为5个区域(1-10/11-20/21-30/31-40/41-49), 统计特码从一个区域转移到另一个区域的概率矩阵, 在控制台页面以彩色表格展示
This commit is contained in:
@@ -464,7 +464,8 @@ class History extends Model
|
||||
'bigsmall' => $this->getBigSmallAnalysis($periods, 'special'),
|
||||
'special' => $this->getSpecialTrend($periods),
|
||||
'tailnumbers' => $this->getTailNumbers($periods, 'special'),
|
||||
'heatmap' => $this->getSpecialHeatmap($periods)
|
||||
'heatmap' => $this->getSpecialHeatmap($periods),
|
||||
'zonetransition' => $this->getZoneTransition($periods)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -662,6 +663,69 @@ class History extends Model
|
||||
return ['hot' => $hot, 'cold' => $cold, 'warm' => $warm];
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域转移概率统计
|
||||
* 将1-49分为5个区域,统计特码从一个区域转移到另一个区域的概率
|
||||
* 区域1: 1-10, 区域2: 11-20, 区域3: 21-30, 区域4: 31-40, 区域5: 41-49
|
||||
* @param int $periods 查询最近多少期
|
||||
* @return array {zones: [], matrix: [], probabilities: [], total_transitions: int}
|
||||
*/
|
||||
public function getZoneTransition($periods = 100)
|
||||
{
|
||||
$history = $this
|
||||
->field('expect,num7,openTime')
|
||||
->order('openTime', 'asc')
|
||||
->limit($periods)
|
||||
->select();
|
||||
|
||||
if (empty($history) || count($history) < 2) {
|
||||
return ['zones' => ['1-10','11-20','21-30','31-40','41-49'], 'matrix' => [], 'probabilities' => [], 'total_transitions' => 0];
|
||||
}
|
||||
|
||||
$zoneLabels = ['1-10', '11-20', '21-30', '31-40', '41-49'];
|
||||
$matrix = array_fill(0, 5, array_fill(0, 5, 0));
|
||||
$rowTotals = array_fill(0, 5, 0);
|
||||
|
||||
$getZone = function ($num) {
|
||||
if ($num <= 10) return 0;
|
||||
if ($num <= 20) return 1;
|
||||
if ($num <= 30) return 2;
|
||||
if ($num <= 40) return 3;
|
||||
return 4;
|
||||
};
|
||||
|
||||
$totalTransitions = 0;
|
||||
for ($i = 0; $i < count($history) - 1; $i++) {
|
||||
$currentNum = (int)$history[$i]['num7'];
|
||||
$nextNum = (int)$history[$i + 1]['num7'];
|
||||
if ($currentNum < 1 || $currentNum > 49 || $nextNum < 1 || $nextNum > 49) continue;
|
||||
|
||||
$from = $getZone($currentNum);
|
||||
$to = $getZone($nextNum);
|
||||
$matrix[$from][$to]++;
|
||||
$rowTotals[$from]++;
|
||||
$totalTransitions++;
|
||||
}
|
||||
|
||||
// 计算概率矩阵
|
||||
$probabilities = array_fill(0, 5, array_fill(0, 5, 0));
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
if ($rowTotals[$i] > 0) {
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'zones' => $zoneLabels,
|
||||
'matrix' => $matrix,
|
||||
'probabilities' => $probabilities,
|
||||
'row_totals' => $rowTotals,
|
||||
'total_transitions' => $totalTransitions
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 特码热力图数据
|
||||
* @param int $periods 查询最近多少期
|
||||
|
||||
Reference in New Issue
Block a user