feat(dashboard): 添加特码热力图功能
在控制台增加特码热力图可视化功能: - 新增 getSpecialHeatmap() 方法生成热力图数据 - 热力图展示近N期特码号码分布(X轴期号,Y轴号码1-49) - 使用号码波色作为单元格颜色,直观展示开奖规律
This commit is contained in:
@@ -463,7 +463,70 @@ class History extends Model
|
||||
'oddeven' => $this->getOddEvenAnalysis($periods, 'special'),
|
||||
'bigsmall' => $this->getBigSmallAnalysis($periods, 'special'),
|
||||
'special' => $this->getSpecialTrend($periods),
|
||||
'tailnumbers' => $this->getTailNumbers($periods, 'special')
|
||||
'tailnumbers' => $this->getTailNumbers($periods, 'special'),
|
||||
'heatmap' => $this->getSpecialHeatmap($periods)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 特码热力图数据
|
||||
* @param int $periods 查询最近多少期
|
||||
* @return array {expects: [], heatmap: [[x, y, value]], colors: [号码对应颜色]}
|
||||
*/
|
||||
public function getSpecialHeatmap($periods = 30)
|
||||
{
|
||||
$num_model = new Num();
|
||||
$colorMap = $num_model->column('color', 'num');
|
||||
|
||||
// 查询最近 N 期特码数据
|
||||
$history = $this
|
||||
->field('expect,num7,openTime')
|
||||
->order('openTime', 'desc')
|
||||
->limit($periods)
|
||||
->select();
|
||||
|
||||
if (empty($history)) {
|
||||
return ['expects' => [], 'heatmap' => [], 'colors' => []];
|
||||
}
|
||||
|
||||
// 反转数组,使数据从左到右为从远到近
|
||||
$history = array_reverse($history);
|
||||
$expects = [];
|
||||
$heatmap = [];
|
||||
|
||||
// 构建热力图数据:[x_index, y_index, value]
|
||||
// x_index = 期号索引(0到periods-1)
|
||||
// y_index = 号码-1(0到48,号码1-49)
|
||||
// value = 1(出现)或 0(未出现)
|
||||
foreach ($history as $idx => $row) {
|
||||
$expects[] = (string)$row['expect'];
|
||||
$specialNum = (int)$row['num7'];
|
||||
// 标记该期特码号码出现
|
||||
if ($specialNum >= 1 && $specialNum <= 49) {
|
||||
$heatmap[] = [$idx, $specialNum - 1, 1];
|
||||
}
|
||||
}
|
||||
|
||||
// 补充号码颜色映射(索引0对应号码1)
|
||||
$colors = [];
|
||||
for ($num = 1; $num <= 49; $num++) {
|
||||
$color = $colorMap[$num] ?? '';
|
||||
if (strpos($color, '红') !== false) {
|
||||
$colors[] = '#e74c3c';
|
||||
} elseif (strpos($color, '蓝') !== false) {
|
||||
$colors[] = '#3498db';
|
||||
} elseif (strpos($color, '绿') !== false) {
|
||||
$colors[] = '#2ecc71';
|
||||
} else {
|
||||
$colors[] = '#95a5a6';
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'expects' => $expects,
|
||||
'heatmap' => $heatmap,
|
||||
'colors' => $colors,
|
||||
'nums' => range(1, 49) // 号码列表
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user