129 lines
4.7 KiB
TypeScript
129 lines
4.7 KiB
TypeScript
'use client';
|
||
|
||
import { useState } from 'react';
|
||
import { detectReverseLineMovement, type RlmResponse, type RlmRequestPayload } from '@/lib/analytics-api';
|
||
import { RLMRadarBoard } from '@/components/RLMRadarBoard';
|
||
|
||
export default function RlmPage() {
|
||
const [matchId, setMatchId] = useState('MATCH-RLM-2026-01');
|
||
const [marketType, setMarketType] = useState('1x2');
|
||
const [selection, setSelection] = useState('home');
|
||
const [ticketThreshold, setTicketThreshold] = useState(80);
|
||
const [oddsChangeThreshold, setOddsChangeThreshold] = useState(0.05);
|
||
const [loading, setLoading] = useState(false);
|
||
const [errorMessage, setErrorMessage] = useState('');
|
||
const [result, setResult] = useState<RlmResponse | null>(null);
|
||
|
||
async function runRlm() {
|
||
setLoading(true);
|
||
setErrorMessage('');
|
||
try {
|
||
const payload: RlmRequestPayload = {
|
||
match_id: matchId,
|
||
market_type: marketType,
|
||
selection,
|
||
ticket_threshold: ticketThreshold,
|
||
odds_change_threshold: oddsChangeThreshold,
|
||
};
|
||
const data = await detectReverseLineMovement(payload);
|
||
setResult(data);
|
||
} catch (error) {
|
||
setErrorMessage(error instanceof Error ? error.message : '反向盤口偵測暫時無法使用');
|
||
setResult(null);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}
|
||
|
||
return (
|
||
<div className="space-y-4">
|
||
<h2 className="dot-matrix text-2xl text-[#7d2a15]">反向盤口移動追蹤</h2>
|
||
<section className="panel-glow rounded-2xl border-dashed p-4">
|
||
<p className="text-sm leading-6 text-[#7a5b46]">
|
||
此頁只在同時有資金流與開收盤賠率時才會產生警示;預設欄位只是偵測器參數,不代表正式賽事訊號。
|
||
</p>
|
||
</section>
|
||
|
||
<section className="panel-glow rounded-2xl p-4">
|
||
<h3 className="dot-matrix text-lg text-[#7d2a15]">偵測條件</h3>
|
||
<div className="mt-3 grid gap-3 md:grid-cols-2 lg:grid-cols-4">
|
||
<label className="text-sm text-[#7a5b46]">
|
||
場次 ID
|
||
<input
|
||
className="mt-2 w-full rounded-lg border border-[#e0c6a8] bg-white/70 px-3 py-2"
|
||
value={matchId}
|
||
onChange={(event) => setMatchId(event.target.value)}
|
||
/>
|
||
</label>
|
||
<label className="text-sm text-[#7a5b46]">
|
||
市場類型
|
||
<input
|
||
className="mt-2 w-full rounded-lg border border-[#e0c6a8] bg-white/70 px-3 py-2"
|
||
value={marketType}
|
||
onChange={(event) => setMarketType(event.target.value)}
|
||
/>
|
||
</label>
|
||
<label className="text-sm text-[#7a5b46]">
|
||
選項
|
||
<input
|
||
className="mt-2 w-full rounded-lg border border-[#e0c6a8] bg-white/70 px-3 py-2"
|
||
value={selection}
|
||
onChange={(event) => setSelection(event.target.value)}
|
||
/>
|
||
</label>
|
||
<label className="text-sm text-[#7a5b46]">
|
||
票據偏好門檻(%)
|
||
<input
|
||
className="mt-2 w-full rounded-lg border border-[#e0c6a8] bg-white/70 px-3 py-2"
|
||
type="number"
|
||
value={ticketThreshold}
|
||
onChange={(event) => setTicketThreshold(Number(event.target.value))}
|
||
/>
|
||
</label>
|
||
<label className="text-sm text-[#7a5b46]">
|
||
賠率上拋門檻
|
||
<input
|
||
className="mt-2 w-full rounded-lg border border-[#e0c6a8] bg-white/70 px-3 py-2"
|
||
type="number"
|
||
step={0.01}
|
||
value={oddsChangeThreshold}
|
||
onChange={(event) => setOddsChangeThreshold(Number(event.target.value))}
|
||
/>
|
||
</label>
|
||
</div>
|
||
|
||
<div className="mt-4">
|
||
<button
|
||
className="rounded-lg bg-[#7d2a15] px-4 py-2 text-white"
|
||
type="button"
|
||
onClick={runRlm}
|
||
disabled={loading}
|
||
>
|
||
{loading ? '偵測中…' : '執行反向盤口偵測'}
|
||
</button>
|
||
</div>
|
||
{errorMessage ? <p className="mt-3 text-xs text-[#8c2f2f]">{errorMessage}</p> : null}
|
||
</section>
|
||
|
||
<RLMRadarBoard
|
||
alerts={(result?.alerts || []).map((a) => ({
|
||
matchName: a.match_id,
|
||
market: a.market_type,
|
||
selection: a.selection,
|
||
ticketPct: a.ticket_pct,
|
||
handlePct: a.handle_pct,
|
||
openingOdds: a.opening_odds,
|
||
currentOdds: a.current_odds,
|
||
}))}
|
||
/>
|
||
<section className="panel-glow rounded-2xl p-4">
|
||
<p className="text-sm text-[#7a5b46]">
|
||
偵測總筆數:{result?.total ?? 0}
|
||
{' '}
|
||
| 觸發異常:{result?.alerts ? result.alerts.filter((item) => item.is_triggered).length : 0}
|
||
</p>
|
||
</section>
|
||
</div>
|
||
);
|
||
}
|