概述文本补全格式
This commit is contained in:
@@ -58,6 +58,10 @@ export interface SummaryMeta {
|
||||
month: number;
|
||||
day: number;
|
||||
count: number;
|
||||
/** 实际数据中最早年份 */
|
||||
dataFromYear?: number;
|
||||
/** 实际数据中最晚年份 */
|
||||
dataToYear?: number;
|
||||
}
|
||||
|
||||
// ---------- 纯函数 ----------
|
||||
@@ -201,14 +205,17 @@ export function buildStatCards(stats: WeatherStats): StatCard[] {
|
||||
}
|
||||
|
||||
export function buildSummary(stats: WeatherStats, meta: SummaryMeta): string {
|
||||
const { stationName, fromYear, toYear, month, day, count } = meta;
|
||||
const { stationName, fromYear, toYear, month, day, count, dataFromYear, dataToYear } = meta;
|
||||
const d = String(day).padStart(2, "0");
|
||||
const dataRange = dataFromYear != null && dataToYear != null
|
||||
? `(${dataFromYear}-${dataToYear})`
|
||||
: "";
|
||||
return [
|
||||
`${stationName}在 ${fromYear}~${toYear} 年间,每年${month}月${d}日这一天共回溯 ${count} 条单日记录。`,
|
||||
`${stationName}在 ${fromYear}~${toYear} 年间,每年${month}月${d}日这一天共回溯 ${count} 条单日记录${dataRange}。`,
|
||||
`其中 ${stats.rainyCount} 年当天出现降水,历史平均单日降雨量 ${stats.avgRain}mm,`,
|
||||
`单日最大降雨 ${stats.maxRain}mm(${stats.maxRainYear}年)。`,
|
||||
`气候整体${+stats.avgRain > 15 ? "偏湿润" : "较干燥"},`,
|
||||
`需关注${stats.rainyCount / (count || 1) > 0.5 ? "短时强降水" : "高温干旱"}风险。`
|
||||
`多年平均最高气温 ${stats.avgTmax}℃,多年平均最低气温 ${stats.avgTmin}℃,`,
|
||||
`历史最高气温 ${stats.maxTmax}℃(${stats.maxTmaxYear}年),历史最低气温 ${stats.minTmin}℃(${stats.minTminYear}年)。`
|
||||
].join("");
|
||||
}
|
||||
|
||||
@@ -237,7 +244,7 @@ export function useWeatherStats(displayRows: Ref<WeatherDataRow[]>) {
|
||||
}
|
||||
});
|
||||
|
||||
const items = RAIN_LEVELS.map((l, i) => ({
|
||||
const items: { label: string; count: number; pct: string }[] = RAIN_LEVELS.map((l, i) => ({
|
||||
label: l.label,
|
||||
count: counts[i],
|
||||
pct: total > 0 ? ((counts[i] / total) * 100).toFixed(1) : "0.0"
|
||||
|
||||
@@ -58,7 +58,8 @@
|
||||
历年「<b class="hero-date-em">{{ anchorMonth }}月{{ padDay }}日</b>」情况
|
||||
</h2>
|
||||
<p class="hero-desc">
|
||||
{{ currentAreaLabel }} 过去 <b>{{ computedSpan }}</b> 年间,每年此日的气象实况,共 <b>{{ pageState.weatherData.length }}</b> 条单日数据。
|
||||
{{ currentAreaLabel }} 过去 <b>{{ computedSpan }}</b> 年间,每年此日的气象实况,共 <b>{{ pageState.weatherData.length }}</b> 条单日数据
|
||||
<template v-if="pageState.dataFromYear != null">({{ pageState.dataFromYear }}-{{ pageState.dataToYear }})</template>。
|
||||
其中 <b>{{ pageState.stats.rainyCount }}</b> 年当天出现降水(占比 {{ pageState.stats.rainyPct }}%),最大单日降雨
|
||||
<b>{{ pageState.stats.maxRain }}</b> mm({{ pageState.stats.maxRainYear }}年),历史单日最高温 <b class="hot">{{ pageState.stats.maxTmax }}℃</b>({{ pageState.stats.maxTmaxYear }}年),
|
||||
历史单日最低温 <b class="cold">{{ pageState.stats.minTmin }}℃</b>({{ pageState.stats.minTminYear }}年)。
|
||||
@@ -396,7 +397,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="平均风向" align="center" min-width="90">
|
||||
<template #default="{ row }">{{ windDirectionLabel(row.windDirection) }}</template>
|
||||
<template #default="{ row }">{{ windDirectionLabelLocal(row.windDirection) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="hasActiveFilter" label="匹配" align="center" min-width="65">
|
||||
<template #default="{ row }"
|
||||
@@ -499,6 +500,7 @@ import { useWeatherStats, computeStats, buildStatCards, buildSummary, emptyStats
|
||||
import { useWeatherChart } from "@/composables/useWeatherChart";
|
||||
import { useWeatherExport } from "@/composables/useWeatherExport";
|
||||
import type { WeatherDataRow } from "@/composables/useWeatherStats";
|
||||
import { windDirectionCode, windDirectionLabel } from "@/utils/windDirection";
|
||||
|
||||
// =============================================================================
|
||||
// Date / Constants
|
||||
@@ -575,7 +577,9 @@ const pageState = reactive({
|
||||
stats: emptyStats(),
|
||||
summary: "",
|
||||
statCards: [] as ReturnType<typeof buildStatCards>,
|
||||
disasters: [] as any[]
|
||||
disasters: [] as any[],
|
||||
dataFromYear: undefined as number | undefined,
|
||||
dataToYear: undefined as number | undefined
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
@@ -583,19 +587,8 @@ const pageState = reactive({
|
||||
// =============================================================================
|
||||
const _store = useAppStore();
|
||||
|
||||
function _windDirectionCode(deg: number | null | string) {
|
||||
if (deg == null || deg === "" || isNaN(Number(deg))) return null;
|
||||
const d = Number(deg);
|
||||
if (d < 0 || d > 360) return null;
|
||||
return ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor((d + 22.5) / 45) % 8];
|
||||
}
|
||||
|
||||
function windDirectionLabel(deg: number | null | string) {
|
||||
const code = _windDirectionCode(deg);
|
||||
if (!code) return "—";
|
||||
const type = _store.state.dicts.find((d: any) => d.dictType === "wind_direction_type");
|
||||
const entry = type?.dataList?.find((e: any) => e.dictValue === code);
|
||||
return entry?.dictLabel || code;
|
||||
function windDirectionLabelLocal(deg: number | null | string) {
|
||||
return windDirectionLabel(deg, _store.state.dicts);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -834,13 +827,19 @@ async function refreshAll() {
|
||||
pageState.weatherData = mapped;
|
||||
pageState.stats = stats;
|
||||
pageState.statCards = buildStatCards(stats);
|
||||
const dataYears = mapped.map((r: WeatherDataRow) => r.year).filter((y: number) => !isNaN(y));
|
||||
pageState.dataFromYear = dataYears.length ? Math.min(...dataYears) : undefined;
|
||||
pageState.dataToYear = dataYears.length ? Math.max(...dataYears) : undefined;
|
||||
|
||||
pageState.summary = buildSummary(stats, {
|
||||
stationName: sName,
|
||||
fromYear: from,
|
||||
toYear: to,
|
||||
month: m,
|
||||
day: d,
|
||||
count: mapped.length
|
||||
count: mapped.length,
|
||||
dataFromYear: pageState.dataFromYear,
|
||||
dataToYear: pageState.dataToYear
|
||||
});
|
||||
pageState.disasters = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user