feat(dashboard): 新增生肖转移概率表格

在控制台页面转移概率区域新增生肖(12生肖)转移概率矩阵,与现有
的区域转移和波色转移保持一致的展示风格。
This commit is contained in:
2026-04-26 16:52:22 +08:00
parent cbca6217d6
commit 7fb2ba4dcf
3 changed files with 105 additions and 2 deletions
+66 -1
View File
@@ -467,7 +467,8 @@ class History extends Model
'heatmap' => $this->getSpecialHeatmap($periods),
'zonetransition' => $this->getZoneTransition($periods),
'colorwavetransition' => $this->getColorWaveTransition($periods),
'zonetocolortransition' => $this->getZoneToZoneColor($periods)
'zonetocolortransition' => $this->getZoneToZoneColor($periods),
'zodiactransition' => $this->getZodiacTransition($periods)
];
}
@@ -796,6 +797,70 @@ class History extends Model
];
}
/**
* 生肖转移概率统计
* 统计特码从一种生肖转移到另一种生肖的概率(12生肖)
* @param int $periods 查询最近多少期
* @return array {animals: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int}
*/
public function getZodiacTransition($periods = 100)
{
$history = $this
->field('expect,num7,openTime')
->order('openTime', 'desc')
->limit($periods)
->select();
if (empty($history) || count($history) < 2) {
return ['animals' => ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0];
}
$history = array_reverse($history);
$num_model = new Num();
$animalMap = $num_model->column('animal', 'num');
$animalLabels = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'];
$numAnimals = 12;
$matrix = array_fill(0, $numAnimals, array_fill(0, $numAnimals, 0));
$rowTotals = array_fill(0, $numAnimals, 0);
$getAnimalIdx = function ($num) use ($animalMap, $animalLabels) {
$animal = $animalMap[$num] ?? '';
$idx = array_search($animal, $animalLabels);
return $idx === false ? -1 : $idx;
};
$totalTransitions = 0;
for ($i = 0; $i < count($history) - 1; $i++) {
$currentNum = (int)$history[$i]['num7'];
$nextNum = (int)$history[$i + 1]['num7'];
$from = $getAnimalIdx($currentNum);
$to = $getAnimalIdx($nextNum);
if ($from < 0 || $to < 0) continue;
$matrix[$from][$to]++;
$rowTotals[$from]++;
$totalTransitions++;
}
$probabilities = array_fill(0, $numAnimals, array_fill(0, $numAnimals, 0));
for ($i = 0; $i < $numAnimals; $i++) {
if ($rowTotals[$i] > 0) {
for ($j = 0; $j < $numAnimals; $j++) {
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
}
}
}
return [
'animals' => $animalLabels,
'matrix' => $matrix,
'probabilities' => $probabilities,
'row_totals' => $rowTotals,
'total_transitions' => $totalTransitions
];
}
/**
* 区域→区域转移矩阵,单元格内显示波色概率
* 统计上一期特码所在区域后,下一期特码在各区域的分布,以及每个区域内的波色占比