mirror of
https://github.com/syuilo/ai.git
synced 2025-03-25 21:12:56 +00:00
wip
This commit is contained in:
parent
587a385238
commit
fb4ed538c6
2 changed files with 32 additions and 38 deletions
|
@ -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');
|
||||||
|
|
|
@ -1,41 +1,42 @@
|
||||||
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; // 震源地
|
||||||
depth: string; // 震源の深さ
|
depth: string; // 震源の深さ
|
||||||
magnitude: string; // 地震の規模を示すマグニチュード
|
magnitude: string; // 地震の規模を示すマグニチュード
|
||||||
latitude: string; // 緯度らしいが謎
|
latitude: string; // 緯度らしいが謎
|
||||||
longitude: string; // 経度らしいが謎
|
longitude: string; // 経度らしいが謎
|
||||||
intensity: string; // 地震の強さ
|
intensity: string; // 地震の強さ
|
||||||
index: number; // 謎
|
index: number; // 謎
|
||||||
}
|
}
|
||||||
|
|
||||||
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: {
|
||||||
intensity: string;
|
intensity: string;
|
||||||
index: number;
|
index: number;
|
||||||
region_list: string[];
|
region_list: string[];
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
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: 地震検知 = {
|
const data: 震度レポート = {
|
||||||
type: rawDataJSON.type,
|
type: rawDataJSON.type,
|
||||||
time: new Date(parseInt(rawDataJSON.time)),
|
time: new Date(parseInt(rawDataJSON.time)),
|
||||||
max_pga: rawDataJSON.max_pga,
|
max_index: rawDataJSON.max_index,
|
||||||
new: rawDataJSON.new,
|
intensity_list: rawDataJSON.intensity_list,
|
||||||
estimated_intensity: rawDataJSON.estimated_intensity,
|
|
||||||
region_list: rawDataJSON.region_list,
|
|
||||||
};
|
};
|
||||||
this.message =
|
this.message = `震度レポート\n${data.time.toLocaleString()}\n\n${
|
||||||
// region_listはオブジェクトなので、2行改行してから列挙する
|
data.intensity_list.map((intensity) =>
|
||||||
`PGA Alert\n${data.time.toLocaleString()}\n${data.max_pga}\n${data.estimated_intensity}\n\n${data.region_list.join("\n")}`;
|
`震度${intensity.intensity}: ${intensity.region_list.join(" ")}`
|
||||||
}else if (rawDataJSON.type == 'intensity_report'){
|
).join("\n")
|
||||||
const data: 震度レポート = {
|
}`;
|
||||||
type: rawDataJSON.type,
|
}
|
||||||
time: new Date(parseInt(rawDataJSON.time)),
|
console.log(rawDataJSON); // デバッグ用
|
||||||
max_index: rawDataJSON.max_index,
|
|
||||||
intensity_list: rawDataJSON.intensity_list,
|
|
||||||
}
|
|
||||||
this.message =
|
|
||||||
`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
|
||||||
|
|
Loading…
Reference in a new issue