feat(phase-4 to 10): add all remaining analysis features - color wave, zodiac, odd/even, big/small, sum, consecutive, tail numbers
This commit is contained in:
@@ -44,7 +44,7 @@ class History extends Model
|
||||
|
||||
$history = $this
|
||||
->field('expect,num1,num2,num3,num4,num5,num6,num7,openTime')
|
||||
->order('openTime', 'asc')
|
||||
->order('openTime', 'desc')
|
||||
->limit($periods)
|
||||
->select();
|
||||
|
||||
@@ -67,6 +67,10 @@ class History extends Model
|
||||
}
|
||||
}
|
||||
|
||||
// 反转数组,使最远的数据在左边,最近的数据在右边(从左往右,从远到近)
|
||||
$expects = array_reverse($expects);
|
||||
$data = array_reverse($data);
|
||||
|
||||
return [
|
||||
'expects' => $expects,
|
||||
'data' => $data,
|
||||
@@ -246,5 +250,201 @@ class History extends Model
|
||||
return count($allHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 波色分析
|
||||
*/
|
||||
public function getColorWaveAnalysis($periods = 30, $type = 'all')
|
||||
{
|
||||
$num_model = new Num();
|
||||
$colorMap = $num_model->column('color', 'num');
|
||||
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['red' => 0, 'blue' => 0, 'green' => 0, 'red_pct' => 0, 'blue_pct' => 0, 'green_pct' => 0, 'details' => []];
|
||||
|
||||
$fields = ($type === 'special') ? ['num7'] : ['num1','num2','num3','num4','num5','num6','num7'];
|
||||
$colors = ['红' => 0, '蓝' => 0, '绿' => 0];
|
||||
$total = 0;
|
||||
foreach ($history as $row) {
|
||||
foreach ($fields as $f) {
|
||||
$num = (int)$row[$f];
|
||||
$color = $colorMap[$num] ?? '';
|
||||
if (strpos($color, '红') !== false) { $colors['红']++; $total++; }
|
||||
elseif (strpos($color, '蓝') !== false) { $colors['蓝']++; $total++; }
|
||||
elseif (strpos($color, '绿') !== false) { $colors['绿']++; $total++; }
|
||||
}
|
||||
}
|
||||
return [
|
||||
'red' => $colors['红'], 'blue' => $colors['蓝'], 'green' => $colors['绿'],
|
||||
'red_pct' => $total ? round($colors['红']/$total*100,1) : 0,
|
||||
'blue_pct' => $total ? round($colors['蓝']/$total*100,1) : 0,
|
||||
'green_pct' => $total ? round($colors['绿']/$total*100,1) : 0,
|
||||
'total' => $total
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生肖分析
|
||||
*/
|
||||
public function getZodiacAnalysis($periods = 30, $type = 'all')
|
||||
{
|
||||
$num_model = new Num();
|
||||
$animalMap = $num_model->column('animal', 'num');
|
||||
$colorMap = $num_model->column('color', 'num');
|
||||
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['list' => []];
|
||||
|
||||
$fields = ($type === 'special') ? ['num7'] : ['num1','num2','num3','num4','num5','num6','num7'];
|
||||
$counts = [];
|
||||
foreach ($history as $row) {
|
||||
foreach ($fields as $f) {
|
||||
$num = (int)$row[$f];
|
||||
$animal = $animalMap[$num] ?? '未知';
|
||||
if (!isset($counts[$animal])) $counts[$animal] = ['animal' => $animal, 'count' => 0, 'color' => $colorMap[$num] ?? '—'];
|
||||
$counts[$animal]['count']++;
|
||||
}
|
||||
}
|
||||
$list = array_values($counts);
|
||||
usort($list, function ($a, $b) { return $b['count'] - $a['count']; });
|
||||
$total = array_sum(array_column($list, 'count'));
|
||||
foreach ($list as &$item) { $item['percent'] = $total ? round($item['count']/$total*100, 1) : 0; }
|
||||
return ['list' => $list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 奇偶分析
|
||||
*/
|
||||
public function getOddEvenAnalysis($periods = 30, $type = 'all')
|
||||
{
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['odd' => 0, 'even' => 0, 'odd_pct' => 0, 'even_pct' => 0, 'per_period' => []];
|
||||
|
||||
$fields = ($type === 'special') ? ['num7'] : ['num1','num2','num3','num4','num5','num6','num7'];
|
||||
$odd = 0; $even = 0; $perPeriod = [];
|
||||
foreach ($history as $row) {
|
||||
$p_odd = 0; $p_even = 0;
|
||||
foreach ($fields as $f) {
|
||||
$num = (int)$row[$f];
|
||||
if ($num % 2 == 0) { $even++; $p_even++; } else { $odd++; $p_odd++; }
|
||||
}
|
||||
$perPeriod[] = ['expect' => $row['expect'], 'odd' => $p_odd, 'even' => $p_even];
|
||||
}
|
||||
$total = $odd + $even;
|
||||
return [
|
||||
'odd' => $odd, 'even' => $even,
|
||||
'odd_pct' => $total ? round($odd/$total*100, 1) : 0,
|
||||
'even_pct' => $total ? round($even/$total*100, 1) : 0,
|
||||
'per_period' => $perPeriod
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 大小分析(1-24为小,25-49为大)
|
||||
*/
|
||||
public function getBigSmallAnalysis($periods = 30, $type = 'all')
|
||||
{
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['big' => 0, 'small' => 0, 'big_pct' => 0, 'small_pct' => 0, 'per_period' => []];
|
||||
|
||||
$fields = ($type === 'special') ? ['num7'] : ['num1','num2','num3','num4','num5','num6','num7'];
|
||||
$big = 0; $small = 0; $perPeriod = [];
|
||||
foreach ($history as $row) {
|
||||
$p_big = 0; $p_small = 0;
|
||||
foreach ($fields as $f) {
|
||||
$num = (int)$row[$f];
|
||||
if ($num >= 25) { $big++; $p_big++; } else { $small++; $p_small++; }
|
||||
}
|
||||
$perPeriod[] = ['expect' => $row['expect'], 'big' => $p_big, 'small' => $p_small];
|
||||
}
|
||||
$total = $big + $small;
|
||||
return [
|
||||
'big' => $big, 'small' => $small,
|
||||
'big_pct' => $total ? round($big/$total*100, 1) : 0,
|
||||
'small_pct' => $total ? round($small/$total*100, 1) : 0,
|
||||
'per_period' => $perPeriod
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 和值分析
|
||||
*/
|
||||
public function getSumAnalysis($periods = 30)
|
||||
{
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'asc')->limit($periods)->select();
|
||||
if (empty($history)) return ['expects' => [], 'sums' => []];
|
||||
|
||||
$expects = []; $sums = [];
|
||||
foreach ($history as $row) {
|
||||
$expects[] = (string)$row['expect'];
|
||||
$sum = (int)$row['num1'] + (int)$row['num2'] + (int)$row['num3'] + (int)$row['num4'] + (int)$row['num5'] + (int)$row['num6'] + (int)$row['num7'];
|
||||
$sums[] = $sum;
|
||||
}
|
||||
$avg = round(array_sum($sums) / count($sums), 1);
|
||||
$max = max($sums); $min = min($sums);
|
||||
return ['expects' => $expects, 'sums' => $sums, 'avg' => $avg, 'max' => $max, 'min' => $min];
|
||||
}
|
||||
|
||||
/**
|
||||
* 连号分析
|
||||
*/
|
||||
public function getConsecutiveNumbers($periods = 30)
|
||||
{
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['pairs' => [], 'triples' => []];
|
||||
|
||||
$pairCount = []; $tripleCount = [];
|
||||
foreach ($history as $row) {
|
||||
$nums = [];
|
||||
for ($i = 1; $i <= 7; $i++) $nums[] = (int)$row['num' . $i];
|
||||
sort($nums);
|
||||
// 找连号对
|
||||
for ($i = 0; $i < count($nums) - 1; $i++) {
|
||||
if ($nums[$i + 1] - $nums[$i] === 1) {
|
||||
$pair = $nums[$i] . '-' . $nums[$i + 1];
|
||||
$pairCount[$pair] = isset($pairCount[$pair]) ? $pairCount[$pair] + 1 : 1;
|
||||
}
|
||||
}
|
||||
// 找连号三连
|
||||
for ($i = 0; $i < count($nums) - 2; $i++) {
|
||||
if ($nums[$i + 1] - $nums[$i] === 1 && $nums[$i + 2] - $nums[$i + 1] === 1) {
|
||||
$triple = $nums[$i] . '-' . $nums[$i + 1] . '-' . $nums[$i + 2];
|
||||
$tripleCount[$triple] = isset($tripleCount[$triple]) ? $tripleCount[$triple] + 1 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
arsort($pairCount); arsort($tripleCount);
|
||||
return ['pairs' => $pairCount, 'triples' => $tripleCount];
|
||||
}
|
||||
|
||||
/**
|
||||
* 尾数分析
|
||||
*/
|
||||
public function getTailNumbers($periods = 30, $type = 'all')
|
||||
{
|
||||
$num_model = new Num();
|
||||
$colorMap = $num_model->column('color', 'num');
|
||||
$animalMap = $num_model->column('animal', 'num');
|
||||
|
||||
$history = $this->field('expect,num1,num2,num3,num4,num5,num6,num7')->order('openTime', 'desc')->limit($periods)->select();
|
||||
if (empty($history)) return ['tails' => [], 'all' => []];
|
||||
|
||||
$fields = ($type === 'special') ? ['num7'] : ['num1','num2','num3','num4','num5','num6','num7'];
|
||||
$tailCount = array_fill(0, 10, 0);
|
||||
$all = [];
|
||||
foreach ($history as $row) {
|
||||
foreach ($fields as $f) {
|
||||
$num = (int)$row[$f];
|
||||
$tail = $num % 10;
|
||||
$tailCount[$tail]++;
|
||||
}
|
||||
}
|
||||
$total = array_sum($tailCount);
|
||||
for ($t = 0; $t <= 9; $t++) {
|
||||
$all[] = ['tail' => $t, 'count' => $tailCount[$t], 'percent' => $total ? round($tailCount[$t]/$total*100, 1) : 0];
|
||||
}
|
||||
usort($all, function ($a, $b) { return $b['count'] - $a['count']; });
|
||||
return ['all' => $all];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user