feat(history): 新增历史开奖数据分析功能
- 添加History控制器和模型实现开奖数据统计分析 - 实现遗漏号码、走势图、冷热号码等基础分析功能 - 添加波色分析、生肖分析、奇偶分析等专项统计 - 集成尾号转移矩阵和首号转移矩阵概率分析 - 在后台仪表板展示综合统计数据表格
This commit is contained in:
@@ -468,7 +468,9 @@ class History extends Model
|
||||
'zonetransition' => $this->getZoneTransition($periods),
|
||||
'colorwavetransition' => $this->getColorWaveTransition($periods),
|
||||
'zonetocolortransition' => $this->getZoneToZoneColor($periods),
|
||||
'zodiactransition' => $this->getZodiacTransition($periods)
|
||||
'zodiactransition' => $this->getZodiacTransition($periods),
|
||||
'tailnumbertransition' => $this->getTailNumberTransition($periods),
|
||||
'headnumbertransition' => $this->getHeadNumberTransition($periods)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -861,6 +863,127 @@ class History extends Model
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 尾号转移概率统计
|
||||
* 统计特码从一个尾号转移到另一个尾号的概率(尾号0-9)
|
||||
* @param int $periods 查询最近多少期
|
||||
* @return array {tails: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int}
|
||||
*/
|
||||
public function getTailNumberTransition($periods = 100)
|
||||
{
|
||||
$history = $this
|
||||
->field('expect,num7,openTime')
|
||||
->order('openTime', 'desc')
|
||||
->limit($periods)
|
||||
->select();
|
||||
|
||||
if (empty($history) || count($history) < 2) {
|
||||
return ['tails' => ['尾0','尾1','尾2','尾3','尾4','尾5','尾6','尾7','尾8','尾9'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0];
|
||||
}
|
||||
|
||||
$history = array_reverse($history);
|
||||
|
||||
$tailLabels = ['尾0', '尾1', '尾2', '尾3', '尾4', '尾5', '尾6', '尾7', '尾8', '尾9'];
|
||||
$numTails = 10;
|
||||
$matrix = array_fill(0, $numTails, array_fill(0, $numTails, 0));
|
||||
$rowTotals = array_fill(0, $numTails, 0);
|
||||
|
||||
$getTail = function ($num) {
|
||||
return $num % 10;
|
||||
};
|
||||
|
||||
$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 = $getTail($currentNum);
|
||||
$to = $getTail($nextNum);
|
||||
$matrix[$from][$to]++;
|
||||
$rowTotals[$from]++;
|
||||
$totalTransitions++;
|
||||
}
|
||||
|
||||
$probabilities = array_fill(0, $numTails, array_fill(0, $numTails, 0));
|
||||
for ($i = 0; $i < $numTails; $i++) {
|
||||
if ($rowTotals[$i] > 0) {
|
||||
for ($j = 0; $j < $numTails; $j++) {
|
||||
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'tails' => $tailLabels,
|
||||
'matrix' => $matrix,
|
||||
'probabilities' => $probabilities,
|
||||
'row_totals' => $rowTotals,
|
||||
'total_transitions' => $totalTransitions
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 首号转移概率统计
|
||||
* 统计特码从一个首号转移到另一个首号的概率(首号0-4)
|
||||
* 首号定义:1-9首号=0,10-19首号=1,20-29首号=2,30-39首号=3,40-49首号=4
|
||||
* @param int $periods 查询最近多少期
|
||||
* @return array {heads: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int}
|
||||
*/
|
||||
public function getHeadNumberTransition($periods = 100)
|
||||
{
|
||||
$history = $this
|
||||
->field('expect,num7,openTime')
|
||||
->order('openTime', 'desc')
|
||||
->limit($periods)
|
||||
->select();
|
||||
|
||||
if (empty($history) || count($history) < 2) {
|
||||
return ['heads' => ['首号0','首号1','首号2','首号3','首号4'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0];
|
||||
}
|
||||
|
||||
$history = array_reverse($history);
|
||||
|
||||
$headLabels = ['首号0', '首号1', '首号2', '首号3', '首号4'];
|
||||
$numHeads = 5;
|
||||
$matrix = array_fill(0, $numHeads, array_fill(0, $numHeads, 0));
|
||||
$rowTotals = array_fill(0, $numHeads, 0);
|
||||
|
||||
$getHead = function ($num) {
|
||||
return intval(floor($num / 10));
|
||||
};
|
||||
|
||||
$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 = $getHead($currentNum);
|
||||
$to = $getHead($nextNum);
|
||||
$matrix[$from][$to]++;
|
||||
$rowTotals[$from]++;
|
||||
$totalTransitions++;
|
||||
}
|
||||
|
||||
$probabilities = array_fill(0, $numHeads, array_fill(0, $numHeads, 0));
|
||||
for ($i = 0; $i < $numHeads; $i++) {
|
||||
if ($rowTotals[$i] > 0) {
|
||||
for ($j = 0; $j < $numHeads; $j++) {
|
||||
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'heads' => $headLabels,
|
||||
'matrix' => $matrix,
|
||||
'probabilities' => $probabilities,
|
||||
'row_totals' => $rowTotals,
|
||||
'total_transitions' => $totalTransitions
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域→区域转移矩阵,单元格内显示波色概率
|
||||
* 统计上一期特码所在区域后,下一期特码在各区域的分布,以及每个区域内的波色占比
|
||||
|
||||
Reference in New Issue
Block a user