Feat: 地震発生情報の地域を都道府県でグループ化する機能

This commit is contained in:
2026-05-03 14:23:49 +09:00
parent 6fd92973f8
commit 95aa0bdb45
+18 -16
View File
@@ -142,32 +142,34 @@ const processMessage = async (message: any) => {
"Potential": "🚨この地震によって**一般的に**この規模では津波の可能性があると考えられています。", "Potential": "🚨この地震によって**一般的に**この規模では津波の可能性があると考えられています。",
} }
let points: Record<string, any[]> = {}; const grouped: Record<string, { scale: number; prefs: Record<string, string[]> }> = {};
for (const point of message.points) { for (const point of message.points) {
const scaleMsg = scaleMessages[String(point.scale)]; const { addr, scale, pref } = point;
if (!scaleMsg)
continue;
points[scaleMsg]?.push(point);
}
const grouped: Record<string, { scale: number; addrs: string[] }> = {};
for (const point of message.points) {
const { addr, scale } = point;
const label = scaleMessages[String(scale)] ?? "不明"; const label = scaleMessages[String(scale)] ?? "不明";
if (!grouped[label]) { if (!grouped[label]) {
grouped[label] = { scale, addrs: [] }; grouped[label] = { scale, prefs: {} };
} }
grouped[label].addrs.push(addr); if (!grouped[label].prefs[pref]) {
grouped[label].prefs[pref] = [];
}
grouped[label].prefs[pref].push(addr);
} }
const pointsMsg = Object.entries(grouped) const pointsMsg = Object.entries(grouped)
.sort((a, b) => b[1].scale - a[1].scale) .sort((a, b) => b[1].scale - a[1].scale)
.map(([label, { addrs }]) => .map(([label, { prefs }]) => {
`${label}${EOL}${addrs.join("・")}`) const prefLines = Object.entries(prefs)
.join(EOL.repeat(2)).trim(); .map(([pref, addrs]) => `${pref}: ${addrs.join("・")}`)
.join(EOL);
return `${label}${EOL}${prefLines}`;
})
.join(EOL.repeat(2))
.trim();
await createUeuse({ await createUeuse({
text: i18next.t("earthquakeNotice", { text: i18next.t("earthquakeNotice", {