<?php
require_once __DIR__ . '/runtime/wr_bootstrap.php';
@set_time_limit(1200);
@ini_set('memory_limit','1536M');
require_once __DIR__ . '/config/config.php';
if (!wr_db_guard_normalize()) { throw new RuntimeException('DB connection unavailable'); }
require_once __DIR__ . '/Chairman/learning/ChairmanSelfLearningEngineV52.php';
function wr_v52_h($v){return htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');}
function wr_v52_date(){foreach(array('race_date','date','review_date') as $k){if(!isset($_GET[$k]))continue;$v=trim((string)$_GET[$k]);$d=DateTimeImmutable::createFromFormat('!Y-m-d',$v);$e=DateTimeImmutable::getLastErrors();if($d instanceof DateTimeImmutable&&($e===false||((int)$e['warning_count']===0&&(int)$e['error_count']===0))&&$d->format('Y-m-d')===$v)return $v;}return(new DateTimeImmutable('now',new DateTimeZone('Asia/Hong_Kong')))->format('Y-m-d');}
$date=wr_v52_date();$venue=isset($_GET['venue'])?preg_replace('/[^A-Za-z0-9_\-]/','',trim((string)$_GET['venue'])):'';$action=isset($_GET['action'])?trim((string)$_GET['action']):'latest';
$engine=new ChairmanSelfLearningEngineV52($conn);$data=$action==='build'?$engine->build($date,$venue):$engine->latest($date,$venue);
$summary=isset($data['summary'])&&is_array($data['summary'])?$data['summary']:array();$rows=isset($data['feedback'])&&is_array($data['feedback'])?$data['feedback']:array();$patterns=isset($data['patterns'])&&is_array($data['patterns'])?$data['patterns']:array();$errors=isset($data['error_analysis'])&&is_array($data['error_analysis'])?$data['error_analysis']:array();$discovery=isset($data['auto_pattern_discovery'])&&is_array($data['auto_pattern_discovery'])?$data['auto_pattern_discovery']:array();$dna=isset($data['race_dna_learning'])&&is_array($data['race_dna_learning'])?$data['race_dna_learning']:array();$memory=isset($data['chairman_memory'])&&is_array($data['chairman_memory'])?$data['chairman_memory']:array();
$simulation=isset($data['adaptive_weight_simulation'])&&is_array($data['adaptive_weight_simulation'])?$data['adaptive_weight_simulation']:array();
$analytics=isset($data['long_term_performance_analytics'])&&is_array($data['long_term_performance_analytics'])?$data['long_term_performance_analytics']:array();
$release=isset($data['ultimate_release_readiness'])&&is_array($data['ultimate_release_readiness'])?$data['ultimate_release_readiness']:array();
?>
<!doctype html><html lang="zh-Hant"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>WinRacing V52.9 Self-Learning Ultimate Release</title>
<style>:root{--bg:#050914;--panel:#0b1424;--card:#08101d;--line:#304765;--gold:#ffc107;--green:#36f2a3;--cyan:#5edbff;--red:#ff7589;--muted:#9eb0c7}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:#eef6ff;font:13px Arial,'Microsoft JhengHei',sans-serif}.wrap{max-width:1880px;margin:auto;padding:18px}.hero,.panel{background:var(--panel);border:1px solid #31486b;border-radius:14px;padding:15px;margin-bottom:12px}.grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px}.grid3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:12px}.gold{color:var(--gold)}.green{color:var(--green)}.cyan{color:var(--cyan)}.red{color:var(--red)}.muted{color:var(--muted)}.kpi{font-size:27px;font-weight:900}.badge{display:inline-block;padding:3px 8px;border-radius:999px;background:#162942;border:1px solid #36577e;font-weight:700}.bar{height:7px;background:#101d30;border-radius:99px;overflow:hidden}.bar span{display:block;height:100%;background:linear-gradient(90deg,#5edbff,#36f2a3)}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}.tp{border-color:#36f2a3}.fp{border-color:#ff7589}.fn{border-color:#ffc107}.tn{border-color:#5edbff}.pending{border-color:#5b6778}@media(max-width:1100px){.grid,.grid3{grid-template-columns:1fr 1fr}}@media(max-width:700px){.grid,.grid3{grid-template-columns:1fr}}</style></head>
<body><div class="wrap"><div class="hero"><h1>🏆 V52.9 — <span class="gold">Self-Learning Ultimate Release</span></h1><div class="muted">整合 Pattern、DNA、Error、Memory、Simulation 與 Long-term Analytics，輸出最終 Learning Readiness Gate；Advisory Only，不改正式 Engine。</div></div>
<div class="panel"><form>Race Date <input type="date" name="race_date" value="<?=wr_v52_h($date)?>"> <strong class="cyan">Selected: <?=wr_v52_h($date)?></strong> Venue <input name="venue" value="<?=wr_v52_h($venue)?>"> <button name="action" value="build">Build V52 Snapshot</button></form></div>
<div class="panel muted">Source Date: <b class="cyan"><?=wr_v52_h(isset($data['source_race_date'])?$data['source_race_date']:$date)?></b> ｜ Source V50 Run: <b class="cyan"><?=wr_v52_h(isset($data['source_v50_run'])?$data['source_v50_run']:'')?></b> ｜ Source V51: <b class="green"><?=wr_v52_h(isset($data['source_v51_version'])?$data['source_v51_version']:'')?></b> ｜ V52: <b class="green">52.9.0</b></div>
<?php if($summary):?><div class="panel"><h2>Feedback Command Center</h2><div class="grid"><div class="card"><small>Result Activation</small><div class="kpi gold"><?=wr_v52_h($summary['evaluated'])?> / <?=wr_v52_h($summary['race_count'])?></div><p><?=wr_v52_h($summary['result_state'])?> · <?=number_format((float)$summary['feedback_completion_pct'],1)?>%</p><p class="cyan"><?=wr_v52_h($summary['result_source'])?> (<?=wr_v52_h($summary['result_rows_found'])?> rows)</p></div><div class="card"><small>True / False Positive</small><div class="kpi"><span class="green"><?=wr_v52_h($summary['true_positive'])?></span> / <span class="red"><?=wr_v52_h($summary['false_positive'])?></span></div></div><div class="card"><small>False Negative</small><div class="kpi gold"><?=wr_v52_h($summary['false_negative'])?></div><p>True Negative <?=wr_v52_h($summary['true_negative'])?></p></div><div class="card"><small>Mean Absolute Error</small><div class="kpi cyan"><?=number_format((float)$summary['mean_absolute_error'],1)?></div><p>Learning Confidence <?=number_format((float)$summary['average_learning_confidence'],1)?></p></div></div></div><?php endif;?>
<div class="panel"><h2>False Positive / False Negative Analyzer</h2><?php if(!$errors||empty($errors['total_error_count'])):?><p class="muted">No FP / FN error available for this race date.</p><?php else:?><div class="grid"><div class="card"><small>Total Errors</small><div class="kpi gold"><?=wr_v52_h($errors['total_error_count'])?></div><p>FP <?=wr_v52_h($errors['false_positive_count'])?> ｜ FN <?=wr_v52_h($errors['false_negative_count'])?></p></div><div class="card"><small>False Positive Share</small><div class="kpi red"><?=number_format((float)$errors['false_positive_rate_pct'],1)?>%</div></div><div class="card"><small>False Negative Share</small><div class="kpi gold"><?=number_format((float)$errors['false_negative_rate_pct'],1)?>%</div></div><div class="card"><small>Top Root Cause</small><div class="cyan" style="font-size:18px;font-weight:900"><?=wr_v52_h($errors['top_root_cause'])?></div><p>Advisory Only</p></div></div><?php if(!empty($errors['root_causes'])):?><div class="grid3" style="margin-top:10px"><?php foreach($errors['root_causes'] as $e):?><div class="card"><h3 class="gold"><?=wr_v52_h($e['root_cause'])?></h3><p><span class="badge"><?=wr_v52_h($e['error_type'])?></span> Count <?=wr_v52_h($e['count'])?> ｜ Share <?=number_format((float)$e['error_share_pct'],1)?>%</p><div class="kpi"><?=number_format((float)$e['priority_score'],1)?></div><p>Priority Score ｜ Avg Severity <?=number_format((float)$e['average_severity'],1)?></p><p>Races: <?=wr_v52_h(implode(',',isset($e['races'])&&is_array($e['races'])?$e['races']:array()))?></p><p class="cyan"><?=wr_v52_h($e['correction_suggestion'])?></p></div><?php endforeach;?></div><?php endif;?><?php endif;?></div>
<div class="panel"><h2>Auto Pattern Discovery</h2><?php if(!$discovery||empty($discovery['candidate_count'])):?><p class="muted">No completed samples available for automatic discovery.</p><?php else:?><div class="grid"><div class="card"><small>Candidate Patterns</small><div class="kpi gold"><?=wr_v52_h($discovery['candidate_count'])?></div></div><div class="card"><small>Baseline Top3</small><div class="kpi cyan"><?=number_format((float)$discovery['baseline_top3_rate_pct'],1)?>%</div></div><div class="card"><small>Top Candidate</small><div class="cyan" style="font-size:17px;font-weight:900"><?=wr_v52_h($discovery['top_candidate'])?></div></div><div class="card"><small>Status Mix</small><p>PROMOTE <?=wr_v52_h($discovery['status_counts']['PROMOTE'])?> ｜ WATCH <?=wr_v52_h($discovery['status_counts']['WATCH'])?></p><p>DISCOVERED <?=wr_v52_h($discovery['status_counts']['DISCOVERED'])?> ｜ REJECT <?=wr_v52_h($discovery['status_counts']['REJECT'])?></p></div></div><div class="grid3" style="margin-top:10px"><?php foreach(array_slice($discovery['candidates'],0,12) as $c):?><div class="card"><h3 class="gold"><?=wr_v52_h($c['pattern'])?></h3><div class="kpi"><?=number_format((float)$c['discovery_confidence'],1)?></div><p>Discovery Confidence</p><div class="bar"><span style="width:<?=min(100,max(0,(float)$c['discovery_confidence']))?>%"></span></div><p>Eval <?=wr_v52_h($c['evaluated'])?> ｜ Hits <?=wr_v52_h($c['top3_hits'])?> ｜ Support <?=number_format((float)$c['support_pct'],1)?>%</p><p>Posterior <?=number_format((float)$c['posterior_hit_rate_pct'],1)?>% ｜ Lift <?=number_format((float)$c['lift'],2)?>x ｜ Error <?=number_format((float)$c['error_rate_pct'],1)?>%</p><span class="badge"><?=wr_v52_h($c['candidate_status'])?></span><p class="muted"><?=wr_v52_h($c['discovery_reason'])?></p></div><?php endforeach;?></div><?php endif;?></div>

<div class="panel"><h2>Race DNA Learning Engine</h2><?php if(!$dna||empty($dna['race_dna_count'])):?><p class="muted">No race DNA available for this race date.</p><?php else:?><div class="grid"><div class="card"><small>Race DNA Records</small><div class="kpi gold"><?=wr_v52_h($dna['race_dna_count'])?></div></div><div class="card"><small>DNA Profiles</small><div class="kpi cyan"><?=wr_v52_h($dna['profile_count'])?></div></div><div class="card"><small>Baseline Top3</small><div class="kpi green"><?=number_format((float)$dna['baseline_top3_rate_pct'],1)?>%</div></div><div class="card"><small>DNA Type Mix</small><p>STRONG <?=wr_v52_h($dna['type_counts']['STRONG'])?> ｜ BALANCED <?=wr_v52_h($dna['type_counts']['BALANCED'])?></p><p>VOLATILE <?=wr_v52_h($dna['type_counts']['VOLATILE'])?> ｜ DANGER <?=wr_v52_h($dna['type_counts']['DANGER'])?></p></div></div>
<div class="grid3" style="margin-top:10px"><?php foreach(array_slice($dna['races'],0,12) as $d):?><div class="card"><h3 class="gold">R<?=wr_v52_h($d['race_num'])?> #<?=wr_v52_h($d['banker_horse'])?> <?=wr_v52_h($d['banker_name'])?></h3><p><span class="badge"><?=wr_v52_h($d['dna_type'])?></span> <span class="badge"><?=wr_v52_h($d['dna_recommendation'])?></span></p><div class="kpi"><?=number_format((float)$d['dna_volatility_score'],1)?></div><p>DNA Volatility</p><div class="bar"><span style="width:<?=min(100,max(0,(float)$d['dna_volatility_score']))?>%"></span></div><p><?=wr_v52_h($d['score_band'])?> ｜ <?=wr_v52_h($d['consensus_band'])?> ｜ <?=wr_v52_h($d['reliability_band'])?></p><p>Finish <?=wr_v52_h($d['banker_finish_position']?:'-')?> ｜ <?=!empty($d['top3_hit'])?'TOP3 HIT':'NO TOP3'?></p><p class="muted"><?=wr_v52_h($d['dna_signature'])?></p></div><?php endforeach;?></div>
<h3 style="margin-top:14px">DNA Profile Library</h3><div class="grid3"><?php foreach(array_slice($dna['profiles'],0,12) as $p):?><div class="card"><h3 class="cyan"><?=wr_v52_h($p['dominant_dna_type'])?></h3><div class="kpi"><?=number_format((float)$p['dna_confidence'],1)?></div><p>DNA Confidence</p><div class="bar"><span style="width:<?=min(100,max(0,(float)$p['dna_confidence']))?>%"></span></div><p>Samples <?=wr_v52_h($p['samples'])?> ｜ Evaluated <?=wr_v52_h($p['evaluated'])?> ｜ Hits <?=wr_v52_h($p['top3_hits'])?></p><p>Posterior <?=number_format((float)$p['posterior_top3_rate_pct'],1)?>% ｜ Lift <?=number_format((float)$p['lift'],2)?>x</p><p>Stability <?=number_format((float)$p['stability'],1)?> ｜ Volatility <?=number_format((float)$p['average_volatility'],1)?></p><span class="badge"><?=wr_v52_h($p['dna_recommendation'])?></span><p class="muted"><?=wr_v52_h($p['dna_signature'])?></p></div><?php endforeach;?></div><?php endif;?></div>

<div class="panel"><h2>Chairman Memory Engine</h2><?php if(!$memory||empty($memory['memory_record_count'])):?><p class="muted">No memory records available. Build snapshots across race dates to strengthen long-term memory.</p><?php else:?><div class="grid"><div class="card"><small>Memory Records</small><div class="kpi gold"><?=wr_v52_h($memory['memory_record_count'])?></div><p>History Snapshots <?=wr_v52_h($memory['history_snapshot_count'])?></p></div><div class="card"><small>Memory Readiness</small><div class="kpi cyan"><?=!empty($memory['memory_ready'])?'ACTIVE':'SEEDING'?></div><p>Persistent advisory memory</p></div><div class="card"><small>Positive / Negative</small><div class="kpi"><span class="green"><?=wr_v52_h($memory['sentiment_counts']['POSITIVE'])?></span> / <span class="red"><?=wr_v52_h($memory['sentiment_counts']['NEGATIVE'])?></span></div><p>Neutral <?=wr_v52_h($memory['sentiment_counts']['NEUTRAL'])?></p></div><div class="card"><small>Memory Type Mix</small><p>Pattern <?=wr_v52_h($memory['type_counts']['PATTERN'])?> ｜ DNA <?=wr_v52_h($memory['type_counts']['DNA'])?></p><p>Error Guard <?=wr_v52_h($memory['type_counts']['ERROR'])?></p></div></div><div class="grid3" style="margin-top:10px"><?php foreach(array_slice($memory['memories'],0,15) as $m):?><div class="card"><h3 class="<?=($m['memory_sentiment']==='POSITIVE'?'green':($m['memory_sentiment']==='NEGATIVE'?'red':'cyan'))?>"><?=wr_v52_h($m['memory_type'])?> · <?=wr_v52_h($m['memory_recommendation'])?></h3><div class="kpi"><?=number_format((float)$m['memory_strength'],1)?></div><p>Memory Strength</p><div class="bar"><span style="width:<?=min(100,max(0,(float)$m['memory_strength']))?>%"></span></div><p>Samples <?=number_format((float)$m['sample_count'],1)?> ｜ Success <?=number_format((float)$m['memory_success_rate_pct'],1)?>%</p><p>Confidence <?=number_format((float)$m['memory_confidence'],1)?> ｜ Recency <?=number_format((float)$m['memory_recency_pct'],1)?>%</p><p>First <?=wr_v52_h($m['first_seen'])?> ｜ Last <?=wr_v52_h($m['last_seen'])?></p><p class="muted"><?=wr_v52_h($m['memory_label'])?></p></div><?php endforeach;?></div><?php endif;?></div>

<div class="panel"><h2>V52 Ultimate Release Readiness</h2><?php if(!$release):?><p class="muted">Release audit is unavailable.</p><?php else:$gate=isset($release['release_gate'])?$release['release_gate']:'NOT_READY';?><div class="grid"><div class="card"><small>Learning Readiness Score</small><div class="kpi <?=($gate==='READY'?'green':($gate==='CAUTION'?'gold':'red'))?>"><?=number_format((float)$release['learning_readiness_score'],1)?></div><div class="bar"><span style="width:<?=min(100,max(0,(float)$release['learning_readiness_score']))?>%"></span></div></div><div class="card"><small>Release Gate</small><div class="kpi <?=($gate==='READY'?'green':($gate==='CAUTION'?'gold':'red'))?>"><?=wr_v52_h($gate)?></div><p>V52.9 Advisory Release</p></div><div class="card"><small>Audit Checks</small><div class="kpi cyan"><?=wr_v52_h($release['checks_passed'])?> / <?=wr_v52_h($release['checks_total'])?></div><p>Failed: <?=wr_v52_h(implode(',',isset($release['failed_checks'])?$release['failed_checks']:array()))?></p></div><div class="card"><small>Production Safety</small><div class="kpi green">LOCKED</div><p>Live weights unchanged · DB schema unchanged</p></div></div><div class="grid3" style="margin-top:10px"><?php foreach($release['audit_checks'] as $check):?><div class="card <?=!empty($check['passed'])?'tp':'fp'?>"><h3 class="<?=!empty($check['passed'])?'green':'red'?>"><?=!empty($check['passed'])?'PASS':'FAIL'?> · <?=wr_v52_h($check['label'])?></h3><p>Weight <?=number_format((float)$check['weight'],1)?></p><p class="muted"><?=wr_v52_h($check['detail'])?></p></div><?php endforeach;?></div><p class="cyan" style="margin-top:12px"><?=wr_v52_h($release['final_advisory_summary'])?></p><?php endif;?></div>
<div class="panel"><h2>Long-term Performance Analytics</h2><?php if(!$analytics||empty($analytics['snapshot_count'])):?><p class="muted">No long-term snapshot history yet. Build V52 snapshots across completed race dates.</p><?php else:?><div class="grid"><div class="card"><small>Snapshots / Evaluated Races</small><div class="kpi gold"><?=wr_v52_h($analytics['snapshot_count'])?> / <?=wr_v52_h($analytics['evaluated_races'])?></div><p>Rolling window <?=wr_v52_h($analytics['rolling_5']['window_size'])?> dates</p></div><div class="card"><small>Overall Top3 Hit Rate</small><div class="kpi green"><?=number_format((float)$analytics['overall_top3_hit_rate_pct'],1)?>%</div><p>Rolling 5: <?=number_format((float)$analytics['rolling_5']['top3_hit_rate_pct'],1)?>%</p></div><div class="card"><small>FP / FN Rate</small><div class="kpi"><span class="red"><?=number_format((float)$analytics['overall_false_positive_rate_pct'],1)?>%</span> / <span class="gold"><?=number_format((float)$analytics['overall_false_negative_rate_pct'],1)?>%</span></div><p>Rolling <?=number_format((float)$analytics['rolling_5']['false_positive_rate_pct'],1)?>% / <?=number_format((float)$analytics['rolling_5']['false_negative_rate_pct'],1)?>%</p></div><div class="card"><small>MAE / Learning Confidence</small><div class="kpi cyan"><?=number_format((float)$analytics['average_mean_absolute_error'],1)?> / <?=number_format((float)$analytics['average_learning_confidence'],1)?></div><p>Memory <?=number_format((float)$analytics['average_memory_strength'],1)?> ｜ Simulation <?=number_format((float)$analytics['average_simulation_impact'],3)?></p></div></div>
<h3 style="margin-top:14px">Learning Trend</h3><div class="grid3"><?php foreach(array_slice(array_reverse($analytics['trend']),0,9) as $t):?><div class="card"><h3 class="gold"><?=wr_v52_h($t['race_date'])?> <?=wr_v52_h($t['venue'])?></h3><div class="kpi green"><?=number_format((float)$t['top3_hit_rate_pct'],1)?>%</div><p>Top3 Hit Rate ｜ Evaluated <?=wr_v52_h($t['evaluated'])?></p><p>FP <?=number_format((float)$t['false_positive_rate_pct'],1)?>% ｜ FN <?=number_format((float)$t['false_negative_rate_pct'],1)?>%</p><p>MAE <?=number_format((float)$t['mean_absolute_error'],1)?> ｜ Learning <?=number_format((float)$t['learning_confidence'],1)?></p><p>Memory <?=number_format((float)$t['memory_strength'],1)?> ｜ Sim Impact <?=number_format((float)$t['simulation_impact'],3)?></p></div><?php endforeach;?></div>
<h3 style="margin-top:14px">Best Long-term Profiles</h3><div class="grid3"><?php foreach(array_slice($analytics['best_profiles'],0,6) as $p):?><div class="card"><h3 class="cyan"><?=wr_v52_h($p['type'])?></h3><div class="kpi"><?=number_format((float)$p['performance_score'],1)?></div><p>Performance Score</p><p>Hit <?=number_format((float)$p['hit_rate_pct'],1)?>% ｜ Confidence <?=number_format((float)$p['average_confidence'],1)?></p><p>Stability <?=number_format((float)$p['average_stability'],1)?> ｜ Samples <?=wr_v52_h($p['samples'])?></p><p class="muted"><?=wr_v52_h($p['label'])?></p></div><?php endforeach;?></div>
<h3 style="margin-top:14px">Error Root Cause Trend</h3><div class="grid3"><?php foreach(array_slice($analytics['error_root_cause_ranking'],0,6) as $e):?><div class="card"><h3 class="red"><?=wr_v52_h($e['root_cause'])?></h3><div class="kpi"><?=number_format((float)$e['average_priority'],1)?></div><p>Average Priority ｜ Count <?=wr_v52_h($e['count'])?></p><p>Average Severity <?=number_format((float)$e['average_severity'],1)?></p></div><?php endforeach;?></div><?php endif;?></div>

<div class="panel"><h2>Adaptive Weight Simulation</h2><?php if(!$simulation||empty($simulation['race_count'])):?><p class="muted">No simulation data available.</p><?php else:?><div class="grid"><div class="card"><small>Apply Candidates</small><div class="kpi gold"><?=wr_v52_h($simulation['apply_candidate_count'])?></div><p>Hold <?=wr_v52_h($simulation['hold_count'])?> ｜ Reject <?=wr_v52_h($simulation['reject_count'])?></p></div><div class="card"><small>Average |Delta|</small><div class="kpi cyan"><?=number_format((float)$simulation['average_absolute_delta'],3)?></div><p>Max <?=number_format((float)$simulation['maximum_absolute_delta'],3)?> ｜ Cap ±<?=number_format((float)$simulation['safety_delta_cap'],1)?></p></div><div class="card"><small>Top Simulated Race</small><div class="kpi green">R<?=wr_v52_h($simulation['top_simulated_race'])?></div><p>Advisory Only</p></div><div class="card"><small>Production Weights</small><div class="kpi green">UNCHANGED</div><p>Live write-back disabled</p></div></div><div class="grid3" style="margin-top:10px"><?php foreach(array_slice($simulation['simulations'],0,12) as $sim):?><div class="card"><h3 class="gold">#<?=wr_v52_h($sim['simulated_rank'])?> R<?=wr_v52_h($sim['race_num'])?> #<?=wr_v52_h($sim['banker_horse'])?> <?=wr_v52_h($sim['banker_name'])?></h3><div class="kpi"><?=number_format((float)$sim['simulated_score'],1)?></div><p>Baseline <?=number_format((float)$sim['baseline_score'],1)?> → Simulated <?=number_format((float)$sim['simulated_score'],1)?></p><p>Delta <b class="<?=((float)$sim['weight_delta']>=0?'green':'red')?>"><?=number_format((float)$sim['weight_delta'],3)?></b> ｜ Confidence <?=number_format((float)$sim['simulation_confidence'],1)?></p><p>Pattern <?=number_format((float)$sim['pattern_delta'],3)?> ｜ DNA <?=number_format((float)$sim['dna_delta'],3)?></p><p>Memory <?=number_format((float)$sim['memory_delta'],3)?> ｜ Error Guard <?=number_format((float)$sim['error_guard_delta'],3)?></p><span class="badge"><?=wr_v52_h($sim['recommendation'])?></span><p class="muted"><?=wr_v52_h($sim['simulation_reason'])?></p></div><?php endforeach;?></div><?php endif;?></div>

<div class="panel"><h2>Race Feedback</h2><?php if(!$rows):?><p class="gold">No V51 source data or feedback available.</p><?php else:?><div class="grid3"><?php foreach($rows as $r):$c=strtolower(str_replace(array('true_positive','false_positive','false_negative','true_negative'),array('tp','fp','fn','tn'),(string)$r['feedback_class']));?><div class="card <?=$c?>"><h3 class="gold">R<?=wr_v52_h($r['race_num'])?> #<?=wr_v52_h($r['banker_horse'])?> <?=wr_v52_h($r['banker_name'])?></h3><p><span class="badge"><?=wr_v52_h($r['feedback_class'])?></span> Tier <?=wr_v52_h($r['tier'])?> / <?=wr_v52_h($r['action'])?></p><p><b><?=wr_v52_h(isset($r['error_root_cause'])?$r['error_root_cause']:'')?></b> ｜ Severity <?=number_format((float)(isset($r['error_severity'])?$r['error_severity']:0),1)?></p><div class="kpi"><?=number_format((float)$r['recommended_adjustment'],2)?></div><p>Recommended Adjustment</p><p>Predicted <?=number_format((float)$r['predicted_score'],1)?> ｜ Outcome <?=number_format((float)$r['actual_outcome_score'],1)?> ｜ Error <?=number_format((float)$r['calibration_error'],1)?></p><p>Finish: <?=wr_v52_h($r['banker_finish_position']?:'-')?> ｜ Source <?=wr_v52_h(isset($r['result_source'])?$r['result_source']:'NONE')?> ｜ Learning Confidence <?=number_format((float)$r['learning_confidence'],1)?></p><div class="bar"><span style="width:<?=min(100,max(0,(float)$r['learning_confidence']))?>%"></span></div><p class="muted"><?=wr_v52_h($r['pattern_key'])?></p><p class="cyan"><?=wr_v52_h($r['feedback_reason'])?></p><p class="gold"><?=wr_v52_h(isset($r['correction_suggestion'])?$r['correction_suggestion']:'')?></p></div><?php endforeach;?></div><?php endif;?></div>
<div class="panel"><h2>Pattern Confidence Learning</h2><?php if(!$patterns):?><p class="muted">No pattern feedback yet.</p><?php else:?><div class="grid3"><?php foreach($patterns as $p):$rec=isset($p['pattern_recommendation'])?$p['pattern_recommendation']:'HOLD';?><div class="card"><h3 class="cyan"><?=wr_v52_h($p['pattern_key'])?></h3><div class="kpi"><?=number_format((float)$p['pattern_confidence_score'],1)?></div><p>Pattern Confidence</p><div class="bar"><span style="width:<?=min(100,max(0,(float)$p['pattern_confidence_score']))?>%"></span></div><p>Samples <?=wr_v52_h($p['samples'])?> ｜ Evaluated <?=wr_v52_h($p['evaluated'])?> ｜ Weight <?=number_format((float)$p['sample_weight_pct'],1)?>%</p><p>Raw Top3 <?=number_format((float)$p['top3_rate'],1)?>% ｜ Bayesian <?=number_format((float)$p['posterior_hit_rate'],1)?>%</p><p>Stability <?=number_format((float)$p['pattern_stability'],1)?> ｜ FP <?=wr_v52_h($p['false_positive'])?> ｜ FN <?=wr_v52_h($p['false_negative'])?></p><p>Avg Adjustment <b><?=number_format((float)$p['average_adjustment'],2)?></b> ｜ Learning <?=number_format((float)$p['learning_confidence'],1)?></p><span class="badge"><?=wr_v52_h($rec)?></span><p class="muted"><?=wr_v52_h($p['recommendation_reason'])?></p></div><?php endforeach;?></div><?php endif;?></div>
</div></body></html>
