From 8c8dec620e24cfd10a5c73d492f1f5d824a90d10 Mon Sep 17 00:00:00 2001 From: leon <916117771@qq.com> Date: Sat, 25 Apr 2026 23:31:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(dashboard):=20=E6=96=B0=E5=A2=9E=E6=B3=A2?= =?UTF-8?q?=E8=89=B2=E8=BD=AC=E7=A7=BB=E6=A6=82=E7=8E=87=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=EF=BC=8C=E4=B8=8E=E5=8C=BA=E5=9F=9F=E8=BD=AC=E7=A7=BB=E6=A6=82?= =?UTF-8?q?=E7=8E=87=E5=B9=B6=E6=8E=92=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/History.php | 17 +++++- application/admin/model/History.php | 68 +++++++++++++++++++++++- public/assets/js/backend/dashboard.js | 32 +++++++++-- 3 files changed, 112 insertions(+), 5 deletions(-) diff --git a/application/admin/controller/History.php b/application/admin/controller/History.php index 286cf77..91c8341 100644 --- a/application/admin/controller/History.php +++ b/application/admin/controller/History.php @@ -22,7 +22,7 @@ class History extends Backend * 无需额外权限检查的方法(但仍在 admin 模块内,需要 admin 登录) * @var array */ - protected $noNeedRight = ['missingNum', 'trendData', 'hotColdNumbers', 'colorWaveAnalysis', 'zodiacAnalysis', 'oddEvenAnalysis', 'bigSmallAnalysis', 'specialTrend', 'consecutiveNumbers', 'tailNumbers', 'dashboard', 'specialHeatmap', 'specialHotColdAction', 'zoneTransition']; + protected $noNeedRight = ['missingNum', 'trendData', 'hotColdNumbers', 'colorWaveAnalysis', 'zodiacAnalysis', 'oddEvenAnalysis', 'bigSmallAnalysis', 'specialTrend', 'consecutiveNumbers', 'tailNumbers', 'dashboard', 'specialHeatmap', 'specialHotColdAction', 'zoneTransition', 'colorWaveTransition']; public function _initialize() { @@ -328,5 +328,20 @@ class History extends Backend } } + /** + * 波色转移概率统计 + */ + public function colorWaveTransition() + { + if ($this->request->isAjax()) { + $periods = $this->request->get('periods', 100, 'intval'); + if ($periods < 10 || $periods > 500) { + $this->error('期数范围必须在 10-500 之间'); + } + $result = $this->model->getColorWaveTransition($periods); + $this->success('查询成功', null, $result); + } + } + } diff --git a/application/admin/model/History.php b/application/admin/model/History.php index 9cf6a47..4761cdf 100644 --- a/application/admin/model/History.php +++ b/application/admin/model/History.php @@ -465,7 +465,8 @@ class History extends Model 'special' => $this->getSpecialTrend($periods), 'tailnumbers' => $this->getTailNumbers($periods, 'special'), 'heatmap' => $this->getSpecialHeatmap($periods), - 'zonetransition' => $this->getZoneTransition($periods) + 'zonetransition' => $this->getZoneTransition($periods), + 'colorwavetransition' => $this->getColorWaveTransition($periods) ]; } @@ -729,6 +730,71 @@ class History extends Model ]; } + /** + * 波色转移概率统计 + * 统计特码从一种波色转移到另一种波色的概率(红/蓝/绿) + * @param int $periods 查询最近多少期 + * @return array {colors: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int} + */ + public function getColorWaveTransition($periods = 100) + { + $history = $this + ->field('expect,num7,openTime') + ->order('openTime', 'desc') + ->limit($periods) + ->select(); + + if (empty($history) || count($history) < 2) { + return ['colors' => ['红波','蓝波','绿波'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0]; + } + + $history = array_reverse($history); + $num_model = new Num(); + $colorMap = $num_model->column('color', 'num'); + + $colorLabels = ['红波', '蓝波', '绿波']; + $matrix = array_fill(0, 3, array_fill(0, 3, 0)); + $rowTotals = array_fill(0, 3, 0); + + $getColorIdx = function ($num) use ($colorMap) { + $color = $colorMap[$num] ?? ''; + if (strpos($color, '红') !== false) return 0; + if (strpos($color, '蓝') !== false) return 1; + if (strpos($color, '绿') !== false) return 2; + return -1; + }; + + $totalTransitions = 0; + for ($i = 0; $i < count($history) - 1; $i++) { + $currentNum = (int)$history[$i]['num7']; + $nextNum = (int)$history[$i + 1]['num7']; + $from = $getColorIdx($currentNum); + $to = $getColorIdx($nextNum); + if ($from < 0 || $to < 0) continue; + + $matrix[$from][$to]++; + $rowTotals[$from]++; + $totalTransitions++; + } + + $probabilities = array_fill(0, 3, array_fill(0, 3, 0)); + for ($i = 0; $i < 3; $i++) { + if ($rowTotals[$i] > 0) { + for ($j = 0; $j < 3; $j++) { + $probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1); + } + } + } + + return [ + 'colors' => $colorLabels, + 'matrix' => $matrix, + 'probabilities' => $probabilities, + 'row_totals' => $rowTotals, + 'total_transitions' => $totalTransitions + ]; + } + /** * 特码热力图数据 * @param int $periods 查询最近多少期 diff --git a/public/assets/js/backend/dashboard.js b/public/assets/js/backend/dashboard.js index 64607a5..04ebabf 100644 --- a/public/assets/js/backend/dashboard.js +++ b/public/assets/js/backend/dashboard.js @@ -85,10 +85,13 @@ define(['jquery'], function ($) { html += '
区域特码 | ';
+ var cwt = data.colorwavetransition;
+ html += '
|---|
区域特码 | ';
for (var z = 0; z < zt.zones.length; z++) {
html += '' + zt.zones[z] + ' | '; } @@ -105,6 +108,29 @@ define(['jquery'], function ($) { html += '
|---|
区域特码 | ';
+ for (var z = 0; z < cwt.colors.length; z++) {
+ html += '' + cwt.colors[z] + ' | '; + } + html += '
|---|---|
| ' + cwt.colors[r] + ' | '; + for (var c = 0; c < 3; c++) { + var pct = cwt.probabilities[r][c]; + var cnt = cwt.matrix[r][c]; + var bg = pct > 40 ? cwColors[r] : pct > 20 ? cwColors[c] : pct > 0 ? '#95a5a6' : '#f5f5f5'; + var txt = pct > 20 ? '#fff' : '#333'; + html += '' + cnt + '次 ' + pct + '% | ';
+ }
+ html += '