feat(admin): 尾首概率弹窗增加相同明细数据

后端新增 tailSameDetail 和 headSameDetail 字段,统计相邻两期
特码尾数/首位相同的具体值及出现次数
前端弹窗新增两个明细表格展示
This commit is contained in:
2026-05-02 15:41:28 +08:00
parent 31cd375ff1
commit 6c1754417c
2 changed files with 60 additions and 4 deletions
+36 -4
View File
@@ -988,7 +988,7 @@ class History extends Model
* 尾首概率:下一期尾数/首位与前一期相同的概率
* 统计相邻两期特码的尾数(num%10)和首位(floor(num/10))变化
* @param int $periods 查询最近多少期
* @return array {tailProb: float, headProb: float, totalTransitions: int, periodCount: int}
* @return array {tailProb: float, headProb: float, tailSameDetail: array, headSameDetail: array, totalTransitions: int, periodCount: int}
*/
public function getTailHeadProbability($periods = 100)
{
@@ -999,7 +999,7 @@ class History extends Model
->select();
if (empty($history) || count($history) < 2) {
return ['tailProb' => 0, 'headProb' => 0, 'totalTransitions' => 0, 'periodCount' => 0];
return ['tailProb' => 0, 'headProb' => 0, 'tailSameDetail' => [], 'headSameDetail' => [], 'totalTransitions' => 0, 'periodCount' => 0];
}
// 按时间升序排列(旧→新)
@@ -1008,6 +1008,8 @@ class History extends Model
$tailSame = 0;
$headSame = 0;
$totalTransitions = 0;
$tailSameDetail = []; // 尾数相同明细: key为尾数, value为次数
$headSameDetail = []; // 首位相同明细: key为首数, value为次数
for ($i = 0; $i < count($history) - 1; $i++) {
$currentNum = (int)$history[$i]['num7'];
@@ -1018,21 +1020,51 @@ class History extends Model
}
$totalTransitions++;
$currentTail = $currentNum % 10;
$nextTail = $nextNum % 10;
$currentHead = intval(floor($currentNum / 10));
$nextHead = intval(floor($nextNum / 10));
// 尾数相同(个位相同)
if (($currentNum % 10) === ($nextNum % 10)) {
if ($currentTail === $nextTail) {
$tailSame++;
$key = $currentTail;
if (!isset($tailSameDetail[$key])) {
$tailSameDetail[$key] = 0;
}
$tailSameDetail[$key]++;
}
// 首位相同(十位相同)
if (intval(floor($currentNum / 10)) === intval(floor($nextNum / 10))) {
if ($currentHead === $nextHead) {
$headSame++;
$key = $currentHead;
if (!isset($headSameDetail[$key])) {
$headSameDetail[$key] = 0;
}
$headSameDetail[$key]++;
}
}
// 排序:尾数按0-9排序,首位按0-4排序
$tailResult = [];
for ($t = 0; $t <= 9; $t++) {
if (isset($tailSameDetail[$t])) {
$tailResult[] = ['tail' => $t, 'count' => $tailSameDetail[$t]];
}
}
$headResult = [];
for ($h = 0; $h <= 4; $h++) {
if (isset($headSameDetail[$h])) {
$headResult[] = ['head' => $h, 'count' => $headSameDetail[$h]];
}
}
return [
'tailProb' => $totalTransitions > 0 ? round($tailSame / $totalTransitions * 100, 2) : 0,
'headProb' => $totalTransitions > 0 ? round($headSame / $totalTransitions * 100, 2) : 0,
'tailSameDetail' => $tailResult,
'headSameDetail' => $headResult,
'totalTransitions' => $totalTransitions,
'periodCount' => count($history)
];