清理市场概览残留:删除 MarketOverviewBanner+refresh_policy 中的 marketOverview 条目
This commit is contained in:
@@ -22,6 +22,7 @@ import type {
|
||||
DailyModelForecast,
|
||||
} from "@/lib/dashboard-types";
|
||||
import { buildDebBaselinePath } from "@/lib/temperature-chart-paths";
|
||||
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
|
||||
import { Panel } from "@/components/dashboard/scan-terminal/Panel";
|
||||
import { rowName, temp } from "@/components/dashboard/scan-terminal/utils";
|
||||
|
||||
@@ -176,7 +177,7 @@ type RunwayHistorySeries = {
|
||||
};
|
||||
|
||||
const MAX_OBS_POINTS = 1440;
|
||||
const HOURLY_CACHE_TTL_MS = 30 * 60 * 1000;
|
||||
const HOURLY_CACHE_TTL_MS = DASHBOARD_REFRESH_POLICY_MS.observation;
|
||||
const FULL_DAY_SLOT_MINUTES = 30;
|
||||
const FULL_DAY_SLOTS = 48;
|
||||
const SLOT_INTERVAL_MS = FULL_DAY_SLOT_MINUTES * 60 * 1000;
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
.root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid var(--color-border-default, rgba(159, 178, 199, 0.16));
|
||||
border-radius: var(--radius-md, 10px);
|
||||
background: var(--color-bg-card, rgba(17, 26, 46, 0.88));
|
||||
backdrop-filter: var(--glass-blur-1, blur(10px));
|
||||
margin: 0 0 var(--space-3, 12px) 0;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.root.loading {
|
||||
opacity: 0.7;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary, #9FB2C7);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: var(--color-accent-primary, #4DA3FF);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--color-text-primary, #E6EDF3);
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.header:hover {
|
||||
background: rgba(77, 163, 255, 0.04);
|
||||
}
|
||||
|
||||
.preview {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--color-text-secondary, #9FB2C7);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
flex-shrink: 0;
|
||||
color: var(--color-text-muted, #7D8FA3);
|
||||
}
|
||||
|
||||
.body {
|
||||
padding: 0 14px 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.65;
|
||||
color: var(--color-text-primary, #E6EDF3);
|
||||
}
|
||||
|
||||
.highlights {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.highlightItem {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 5px;
|
||||
padding: 5px 10px;
|
||||
border-radius: var(--radius-sm, 6px);
|
||||
background: rgba(77, 163, 255, 0.08);
|
||||
border: 1px solid rgba(77, 163, 255, 0.14);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--color-text-secondary, #9FB2C7);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.highlightItem strong {
|
||||
color: var(--color-accent-primary, #4DA3FF);
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 11px;
|
||||
color: var(--color-text-muted, #7D8FA3);
|
||||
}
|
||||
|
||||
/* Mobile < 768px */
|
||||
@media (max-width: 768px) {
|
||||
.header {
|
||||
padding: 8px 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.body {
|
||||
padding: 0 10px 10px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.highlights {
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.highlightItem {
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Mobile < 640px */
|
||||
@media (max-width: 640px) {
|
||||
.header {
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.preview {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.body {
|
||||
padding: 0 8px 8px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
font-size: 11px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
}
|
||||
|
||||
/* Light theme */
|
||||
:global(.scan-terminal.light) .root {
|
||||
background: rgba(255, 255, 255, 0.78);
|
||||
border-color: rgba(15, 23, 42, 0.1);
|
||||
}
|
||||
|
||||
:global(.scan-terminal.light) .summary {
|
||||
color: #0F172A;
|
||||
}
|
||||
|
||||
:global(.scan-terminal.light) .preview,
|
||||
:global(.scan-terminal.light) .highlightItem {
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
:global(.scan-terminal.light) .highlightItem {
|
||||
background: rgba(77, 163, 255, 0.06);
|
||||
border-color: rgba(77, 163, 255, 0.18);
|
||||
}
|
||||
|
||||
:global(.scan-terminal.light) .header:hover {
|
||||
background: rgba(77, 163, 255, 0.05);
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import clsx from "clsx";
|
||||
import { ChevronDown, ChevronUp, Sparkles } from "lucide-react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { fetchBackendApi, buildBrowserBackendHeaders } from "@/lib/backend-api";
|
||||
import styles from "./MarketOverviewBanner.module.css";
|
||||
import type { ScanOpportunityRow } from "@/lib/dashboard-types";
|
||||
|
||||
interface OverviewPayload {
|
||||
overview_zh: string;
|
||||
overview_en: string;
|
||||
highlights: Array<{ city: string; note_zh: string; note_en: string }>;
|
||||
generated_at: string | null;
|
||||
}
|
||||
|
||||
export function MarketOverviewBanner({
|
||||
isEn,
|
||||
isPro,
|
||||
rows,
|
||||
}: {
|
||||
isEn: boolean;
|
||||
isPro: boolean;
|
||||
rows: ScanOpportunityRow[];
|
||||
}) {
|
||||
const [collapsed, setCollapsed] = useState(true);
|
||||
const [data, setData] = useState<OverviewPayload | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const fetchedRef = useRef(false);
|
||||
|
||||
const fetchOverview = useCallback(async () => {
|
||||
if (!isPro || !rows.length || fetchedRef.current) return;
|
||||
fetchedRef.current = true;
|
||||
setLoading(true);
|
||||
setError(false);
|
||||
try {
|
||||
const headers = await buildBrowserBackendHeaders({
|
||||
"Content-Type": "application/json",
|
||||
});
|
||||
const resp = await fetchBackendApi("/api/scan/terminal/overview", {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
rows: rows.slice(0, 40).map((row) => ({
|
||||
city: row.city ?? row.display_name ?? "",
|
||||
display_name: row.display_name ?? row.city ?? "",
|
||||
local_date: row.local_date ?? "",
|
||||
deb_prediction: row.deb_prediction ?? null,
|
||||
current_temp: row.current_temp ?? null,
|
||||
current_max_so_far: row.current_max_so_far ?? null,
|
||||
risk_level: row.risk_level ?? "",
|
||||
temp_symbol: row.temp_symbol ?? "°C",
|
||||
})),
|
||||
}),
|
||||
});
|
||||
if (resp.ok) {
|
||||
const json = await resp.json();
|
||||
setData(json);
|
||||
} else {
|
||||
setError(true);
|
||||
}
|
||||
} catch {
|
||||
setError(true);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [isPro, rows]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isPro && rows.length > 0 && !fetchedRef.current) {
|
||||
fetchOverview();
|
||||
}
|
||||
}, [isPro, rows.length, fetchOverview]);
|
||||
|
||||
if (!isPro || rows.length === 0) return null;
|
||||
if (loading && !data) {
|
||||
return (
|
||||
<div className={clsx(styles.root, styles.loading)}>
|
||||
<Sparkles size={14} className={styles.icon} />
|
||||
<span>{isEn ? "AI is generating market overview…" : "AI 正在生成市场概览…"}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (error && !data) return null;
|
||||
|
||||
const overviewText = data ? (isEn ? data.overview_en : data.overview_zh) : "";
|
||||
const highlights = data?.highlights ?? [];
|
||||
|
||||
return (
|
||||
<div className={clsx(styles.root, collapsed && styles.collapsed)}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.header}
|
||||
onClick={() => setCollapsed((c) => !c)}
|
||||
aria-label={isEn ? "Toggle market overview" : "切换市场概览"}
|
||||
>
|
||||
<span className={styles.preview}>
|
||||
{collapsed && overviewText ? overviewText.slice(0, isEn ? 120 : 60) + "…" : ""}
|
||||
</span>
|
||||
<span className={styles.toggle}>
|
||||
{collapsed ? <ChevronDown size={16} /> : <ChevronUp size={16} />}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{!collapsed && (
|
||||
<div className={styles.body}>
|
||||
<p className={styles.summary}>{overviewText}</p>
|
||||
{highlights.length > 0 && (
|
||||
<ul className={styles.highlights}>
|
||||
{highlights.map((h) => (
|
||||
<li key={h.city} className={styles.highlightItem}>
|
||||
<strong>{h.city}</strong>
|
||||
<span>{isEn ? h.note_en : h.note_zh}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{data?.generated_at && (
|
||||
<time className={styles.time} dateTime={data.generated_at}>
|
||||
{isEn ? "Generated " : "生成于 "}
|
||||
{new Date(data.generated_at).toLocaleTimeString(isEn ? "en-US" : "zh-CN", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
})}
|
||||
</time>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
YAxis,
|
||||
} from "recharts";
|
||||
import { Panel } from "@/components/dashboard/scan-terminal/Panel";
|
||||
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
|
||||
|
||||
type StreamPoint = { timestamp: string; temp: number; source: string };
|
||||
type Threshold = { label: string; threshold_c: number; breached: boolean };
|
||||
@@ -21,7 +22,7 @@ type StreamPayload = {
|
||||
thresholds: Threshold[];
|
||||
};
|
||||
|
||||
const POLL_INTERVAL_MS = 30_000;
|
||||
const POLL_INTERVAL_MS = DASHBOARD_REFRESH_POLICY_MS.observation;
|
||||
|
||||
export function RealtimeScrollChart({
|
||||
city,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {
|
||||
DASHBOARD_REFRESH_POLICY_MS,
|
||||
DASHBOARD_REFRESH_POLICY_SEC,
|
||||
} from "@/lib/refresh-policy";
|
||||
import { scanTerminalQueryPolicy } from "@/components/dashboard/scan-terminal/scan-terminal-client";
|
||||
|
||||
function assert(condition: unknown, message: string) {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
export function runTests() {
|
||||
assert(DASHBOARD_REFRESH_POLICY_MS.observation === 60_000, "observation layer should refresh every 60 seconds");
|
||||
assert(DASHBOARD_REFRESH_POLICY_MS.scanRows === 5 * 60_000, "region/city rows should refresh every 5 minutes");
|
||||
assert(DASHBOARD_REFRESH_POLICY_MS.model === 30 * 60_000, "DEB and multi-model data should refresh every 30 minutes");
|
||||
assert(DASHBOARD_REFRESH_POLICY_SEC.metar === 5 * 60, "METAR polling should be 5 minutes");
|
||||
assert(scanTerminalQueryPolicy.autoRefreshMs === DASHBOARD_REFRESH_POLICY_MS.scanRows, "scan terminal auto refresh should use the shared row cadence");
|
||||
|
||||
const projectRoot = process.cwd();
|
||||
const querySource = fs.readFileSync(
|
||||
path.join(projectRoot, "components", "dashboard", "scan-terminal", "use-scan-terminal-query.ts"),
|
||||
"utf8",
|
||||
);
|
||||
const chartSource = fs.readFileSync(
|
||||
path.join(projectRoot, "components", "dashboard", "scan-terminal", "LiveTemperatureThresholdChart.tsx"),
|
||||
"utf8",
|
||||
);
|
||||
const overviewApiSource = fs.readFileSync(
|
||||
path.join(projectRoot, "..", "web", "services", "market_overview_api.py"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
assert(
|
||||
querySource.includes("DASHBOARD_REFRESH_POLICY_MS.scanRows"),
|
||||
"scan list local cache should use the shared 5-minute row cadence",
|
||||
);
|
||||
assert(
|
||||
chartSource.includes("DASHBOARD_REFRESH_POLICY_MS.observation"),
|
||||
"selected city chart detail cache should use the shared 60-second observation cadence",
|
||||
);
|
||||
assert(
|
||||
!overviewApiSource.includes("/chat/completions") &&
|
||||
!overviewApiSource.includes("SCAN_CITY_AI_MODEL") &&
|
||||
!overviewApiSource.includes("_scan_ai_api_key"),
|
||||
"market overview must be deterministic and must not call AI providers",
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
buildBrowserBackendHeaders,
|
||||
fetchBackendApi,
|
||||
} from "@/lib/backend-api";
|
||||
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
|
||||
import type {
|
||||
CityDetail,
|
||||
MarketScan,
|
||||
@@ -17,7 +18,7 @@ export type RemoteData<T> =
|
||||
| { status: "error"; error: string; previous?: T };
|
||||
|
||||
export const scanTerminalQueryPolicy = {
|
||||
autoRefreshMs: 10 * 60_000,
|
||||
autoRefreshMs: DASHBOARD_REFRESH_POLICY_MS.scanRows,
|
||||
manualForceRefreshCooldownMs: 2 * 60_000,
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
} from "@/components/dashboard/scan-terminal/scan-terminal-client";
|
||||
import { useRemoteDataQuery } from "@/components/dashboard/scan-terminal/use-remote-data-query";
|
||||
import { REGIONS } from "@/components/dashboard/scan-terminal/continent-grouping";
|
||||
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
|
||||
import type { ScanTerminalResponse } from "@/lib/dashboard-types";
|
||||
|
||||
const SCAN_CACHE_PREFIX = "polyweather_scan_v2";
|
||||
const SCAN_CACHE_TTL_MS = 10 * 60 * 1000; // 10 min — cities list instant on revisit
|
||||
const SCAN_CACHE_TTL_MS = DASHBOARD_REFRESH_POLICY_MS.scanRows;
|
||||
|
||||
function scanCacheKey(tradingRegion: string): string {
|
||||
return `${SCAN_CACHE_PREFIX}:${tradingRegion || "all"}`;
|
||||
|
||||
Reference in New Issue
Block a user