This commit is contained in:
na2na 2022-04-05 01:50:23 +09:00
parent 587a385238
commit fb4ed538c6
2 changed files with 32 additions and 38 deletions

View file

@ -12,6 +12,7 @@ type Config = {
mecab?: string; mecab?: string;
mecabDic?: string; mecabDic?: string;
memoryDir?: string; memoryDir?: string;
earthQuakeMonitorPort?: number;
}; };
const config = require('../config.json'); const config = require('../config.json');

View file

@ -1,12 +1,13 @@
import autobind from "autobind-decorator"; import autobind from "autobind-decorator";
import Module from "@/module"; import Module from "@/module";
import config from "@/config";
import Message from "@/message"; import Message from "@/message";
import * as http from "http"; import * as http from "http";
// 基本的に生データはstringばっかり。都合のいい形に加工済みの状態の型定義を書いています。 // 基本的に生データはstringばっかり。都合のいい形に加工済みの状態の型定義を書いています。
// ここでいくらか言及されてる(https://bultar.bbs.fc2.com/?act=reply&tid=5645851); // ここでいくらか言及されてる(https://bultar.bbs.fc2.com/?act=reply&tid=5645851);
interface { interface {
type: 'eew'; type: "eew";
time: Date; time: Date;
report: string; // 第n報 最終報はstringで'final'となるので、とりあえずstring型 report: string; // 第n報 最終報はstringで'final'となるので、とりあえずstring型
epicenter: string; // 震源地 epicenter: string; // 震源地
@ -19,12 +20,12 @@ interface 緊急地震速報 {
} }
interface { interface {
type: 'pga_alert_cancel'; type: "pga_alert_cancel";
time: Date; time: Date;
} }
interface { interface {
type: 'intensity_report'; type: "intensity_report";
time: Date; time: Date;
max_index: number; max_index: number;
intensity_list: { intensity_list: {
@ -35,7 +36,7 @@ interface 震度レポート {
} }
interface { interface {
type: 'pga_alert'; type: "pga_alert";
time: Date; time: Date;
max_pga: number; max_pga: number;
new: boolean; new: boolean;
@ -71,28 +72,20 @@ export default class extends Module {
}), }),
); );
if (rawDataJSON.type == "pga_alert") { if (rawDataJSON.type == "intensity_report") {
const data: 地震検知 = {
type: rawDataJSON.type,
time: new Date(parseInt(rawDataJSON.time)),
max_pga: rawDataJSON.max_pga,
new: rawDataJSON.new,
estimated_intensity: rawDataJSON.estimated_intensity,
region_list: rawDataJSON.region_list,
};
this.message =
// region_listはオブジェクトなので、2行改行してから列挙する
`PGA Alert\n${data.time.toLocaleString()}\n${data.max_pga}\n${data.estimated_intensity}\n\n${data.region_list.join("\n")}`;
}else if (rawDataJSON.type == 'intensity_report'){
const data: 震度レポート = { const data: 震度レポート = {
type: rawDataJSON.type, type: rawDataJSON.type,
time: new Date(parseInt(rawDataJSON.time)), time: new Date(parseInt(rawDataJSON.time)),
max_index: rawDataJSON.max_index, max_index: rawDataJSON.max_index,
intensity_list: rawDataJSON.intensity_list, intensity_list: rawDataJSON.intensity_list,
};
this.message = `震度レポート\n${data.time.toLocaleString()}\n\n${
data.intensity_list.map((intensity) =>
`震度${intensity.intensity}: ${intensity.region_list.join(" ")}`
).join("\n")
}`;
} }
this.message = console.log(rawDataJSON); // デバッグ用
`Intensity Report\n${data.time.toLocaleString()}\n\n${data.intensity_list.map(intensity => `震度${intensity.intensity} ${intensity.region_list.join(" ")}`).join("\n")}`;
}
this.returnResponse(res, "ok"); this.returnResponse(res, "ok");
if (this.message) { if (this.message) {
this.ai.post({ this.ai.post({
@ -103,7 +96,7 @@ export default class extends Module {
} else { } else {
this.returnResponse(res, "debobigego"); this.returnResponse(res, "debobigego");
} }
}).listen(process.env.EARTHQUAKE_PORT || 9999); }).listen(config.earthQuakeMonitorPort || 9999);
} }
@autobind @autobind