fix: bootstrap daily recommendation snapshots
Some checks failed
2026 World Cup Quant Platform - Production Deployment / Code Quality, Security Gate & Testing (push) Failing after 2m54s
2026 World Cup Quant Platform - Production Deployment / Deploy to Production VM via Gitea CD (push) Has been skipped

This commit is contained in:
ogt
2026-06-25 14:13:57 +08:00
parent f26def598f
commit 50ef2eac1d
2 changed files with 55 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ from .analytics.daily_card_generator import (
recalibrate_daily_card_confidence_payload,
update_runtime_market_calibration,
)
from .analytics.worldcup_seed import seed_venues
from .analytics.localization import (
localize_city,
localize_country,
@@ -3670,6 +3671,8 @@ async def relay_redis_events() -> None:
@app.on_event('startup')
async def on_startup() -> None:
seed_summary = await seed_venues()
logger.info('World Cup seed/schema bootstrap completed: %s', seed_summary)
app.state.redis_listener = asyncio.create_task(relay_redis_events())

View File

@@ -0,0 +1,52 @@
import { NextResponse } from 'next/server';
const ANALYTICS_BACKEND = process.env.ANALYTICS_BACKEND_URL || 'http://127.0.0.1:8000';
function getTaipeiDate(): string {
const parts = new Intl.DateTimeFormat('en-US', {
timeZone: 'Asia/Taipei',
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).formatToParts(new Date());
const year = parts.find((part) => part.type === 'year')?.value;
const month = parts.find((part) => part.type === 'month')?.value;
const day = parts.find((part) => part.type === 'day')?.value;
return `${year}-${month}-${day}`;
}
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const targetDate = searchParams.get('date') || getTaipeiDate();
if (!/^\d{4}-\d{2}-\d{2}$/.test(targetDate)) {
return NextResponse.json({ message: '日期格式必須為 YYYY-MM-DD' }, { status: 400 });
}
try {
const response = await fetch(`${ANALYTICS_BACKEND}/analytics/daily-card/${encodeURIComponent(targetDate)}`, {
method: 'GET',
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
const message = await response.text();
return NextResponse.json({ message }, { status: response.status });
}
const data = (await response.json()) as Record<string, unknown>;
return NextResponse.json({
generated_at: new Date().toISOString(),
target_date: targetDate,
...data,
});
} catch (error) {
const message = error instanceof Error ? error.message : '每日作戰室服務暫時無法連線';
return NextResponse.json({ message }, { status: 502 });
}
}