<?php
@set_time_limit(1200);@ini_set('memory_limit','1536M');require_once __DIR__.'/config/config.php';if(!isset($conn)&&isset($db))$conn=$db;if(!isset($conn)||!($conn instanceof mysqli))die('DB connection not found');$conn->set_charset('utf8mb4');require_once __DIR__.'/Chairman/consensus/ChairmanConsensusEngineV49.php';function h49($s){return htmlspecialchars((string)$s,ENT_QUOTES,'UTF-8');}$date=isset($_GET['race_date'])?$_GET['race_date']:(isset($_GET['date'])?$_GET['date']:date('Y-m-d'));$venue=isset($_GET['venue'])?$_GET['venue']:'';$action=isset($_GET['action'])?$_GET['action']:'latest';$e=new ChairmanConsensusEngineV49($conn);$build=$action==='build'?$e->build($date,$venue):null;$data=$e->latestData($date,$venue);
?><!doctype html><html lang="zh-Hant"><head><meta charset="utf-8"><title>V49 Chairman Consensus</title><style>body{margin:0;background:#050914;color:#eef;font-family:Arial,'Microsoft JhengHei';font-size:13px}.w{max-width:1880px;margin:auto;padding:22px}.p{background:#0b1424;border:1px solid #31486b;border-radius:14px;padding:16px;margin-bottom:14px}.g{color:#ffc107}.ok{color:#32ffa7}.r{color:#ff657f}.c{color:#52d9ff}.grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}.card{background:#08101d;border:1px solid #2c405c;border-radius:12px;padding:13px}input{background:#07111f;color:#fff;border:1px solid #345;padding:8px}button{background:#ffc107;border:0;padding:9px 14px;font-weight:900;border-radius:6px}table{width:100%;border-collapse:collapse}td,th{border-bottom:1px solid #243650;padding:7px;text-align:left;font-size:12px}.heat{height:8px;background:#17263b;border-radius:5px;overflow:hidden}.heat span{display:block;height:100%;background:linear-gradient(90deg,#1fa97a,#ffc107,#ff5c7a)}@media(max-width:1100px){.grid{grid-template-columns:1fr 1fr}}</style></head><body><div class="w"><div class="p"><h1>👑 V49 — Chairman <span class="g">Consensus Engine</span></h1><div>V44 + V47 + V48 → Chairman Final Decision</div><p class="g">純賽前版：不讀賽果。</p></div><div class="p"><form>Race Date <input type="date" name="race_date" value="<?=h49($date)?>"> Venue <input name="venue" value="<?=h49($venue)?>"> <button name="action" value="build">Build V49 Consensus</button></form></div><?php if($build):?><div class="p ok"><?=h49($build['message'])?></div><?php endif;?><div class="p"><h2>Race Final Consensus</h2><div class="grid"><?php foreach($data['summary'] as $r):?><div class="card"><h3 class="g">R<?=h49($r['race_num'])?>｜膽 #<?=h49($r['chairman_banker'])?></h3><p>Consensus <?=number_format((float)$r['race_consensus_pct'],1)?>%｜RSI <?=number_format((float)$r['race_stability_index'],1)?>%</p><p><?=h49($r['race_clarity'])?></p><p>Q <?=h49($r['q_top2'])?>｜Top4 <?=h49($r['trio_top4'])?></p><p>Value <?=h49($r['value_horses'])?>｜Avoid <?=h49($r['avoid_horses'])?></p></div><?php endforeach;?></div></div><div class="p"><h2>Chairman Final Ranking</h2><table><tr><th>Race</th><th>Rank</th><th>Horse</th><th>Name</th><th>Final</th><th>Consensus</th><th>RSI</th><th>Heat</th><th>Tag</th><th>Action</th></tr><?php foreach($data['ranking'] as $r):?><tr><td>R<?=h49($r['race_num'])?></td><td class="g">#<?=h49($r['final_rank'])?></td><td class="g"><?=h49($r['horse_num'])?></td><td><?=h49($r['horse_name'])?></td><td class="ok"><?=number_format((float)$r['chairman_final_score'],1)?></td><td><?=number_format((float)$r['consensus_pct'],1)?>%</td><td><?=number_format((float)$r['stability_score'],1)?>%</td><td><div class="heat"><span style="width:<?=max(0,min(100,(float)$r['heat_value']))?>%"></span></div></td><td><?=h49($r['final_tag'])?></td><td><?=h49($r['final_action'])?></td></tr><?php endforeach;?></table></div></div></body></html>
