feat: add warning areas

This commit is contained in:
Louis Dalibard 2024-08-25 13:52:26 +02:00
parent 67827e958c
commit f892ba3f09
4 changed files with 13 additions and 5 deletions

View File

@ -3,7 +3,7 @@ package constants
// https://earthquake.usgs.gov/earthquakes/eventpage/us6000d3zh/dyfi/intensity-vs-distance ignored since too tame // https://earthquake.usgs.gov/earthquakes/eventpage/us6000d3zh/dyfi/intensity-vs-distance ignored since too tame
// https://earthquake.usgs.gov/earthquakes/eventpage/us6000nith/dyfi/intensity-vs-distance used // https://earthquake.usgs.gov/earthquakes/eventpage/us6000nith/dyfi/intensity-vs-distance used
const MagnitudeDecreasePerKM = 0.00814867762 // 0.01159528707 const MagnitudeDecreasePerKM = 0.00814867762 // 0.01159528707
var TestMessage = []byte(`{"type":"jma_eew","Title": "緊急地震速報(予報)", "CodeType": "M、最大予測震度及び主要動到達予測時刻の緊急地震速報", "Issue": {"Source": "東京", "Status": "通常"}, "EventID": "20240824093249", "Serial": 5, "AnnouncedTime": "2024/08/24 09:33:35", "OriginTime": "2024/08/24 09:32:40", "Hypocenter": "四国沖", "Latitude": 32.9, "Longitude": 134.3, "Magunitude": 4.0, "Depth": 10, "MaxIntensity": "2", "Accuracy": {"Epicenter": "IPF 法5 点以上)", "Depth": "IPF 法5 点以上)", "Magnitude": "防災科研システム"}, "MaxIntChange": {"String": "ほとんど変化なし", "Reason": "不明、未設定時、キャンセル時"}, "WarnArea": [], "isSea": true, "isTraining": false, "isAssumption": false, "isWarn": false, "isFinal": true, "isCancel": false, "OriginalText": "37 03 00 240824093335 C11 240824093240 ND20240824093249 NCN905 JD////////////// JN/// 902 N329 E1343 010 40 02 RK44209 RT10/// RC0//// 9999=", "Pond": "41"}`) var TestMessage = []byte(`{"type":"jma_eew","Title": "緊急地震速報(予報)", "CodeType": "M、最大予測震度及び主要動到達予測時刻の緊急地震速報", "Issue": {"Source": "東京", "Status": "通常"}, "EventID": "20240824093249", "Serial": 5, "AnnouncedTime": "2024/08/24 09:33:35", "OriginTime": "2024/08/24 09:32:40", "Hypocenter": "四国沖", "Latitude": 32.9, "Longitude": 134.3, "Magunitude": 4.0, "Depth": 10, "MaxIntensity": "2", "Accuracy": {"Epicenter": "IPF 法5 点以上)", "Depth": "IPF 法5 点以上)", "Magnitude": "防災科研システム"}, "MaxIntChange": {"String": "ほとんど変化なし", "Reason": "不明、未設定時、キャンセル時"}, "WarnArea": [ {"Chiiki": "Test area", "Shindo1":"1","Shindo2":"2","Time":"2024/08/24 09:33:35","Type":"警報","Arrive":false} ], "isSea": true, "isTraining": false, "isAssumption": false, "isWarn": false, "isFinal": true, "isCancel": false, "OriginalText": "37 03 00 240824093335 C11 240824093240 ND20240824093249 NCN905 JD////////////// JN/// 902 N329 E1343 010 40 02 RK44209 RT10/// RC0//// 9999=", "Pond": "41"}`)
const WSHost = "ws-api.wolfx.jp" const WSHost = "ws-api.wolfx.jp"

2
go.mod
View File

@ -23,5 +23,5 @@ require (
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect
golang.org/x/sys v0.6.0 // indirect golang.org/x/sys v0.18.0 // indirect
) )

3
go.sum
View File

@ -53,8 +53,9 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -50,7 +50,7 @@ type WarnArea struct {
Shindo2 string Shindo2 string
Time string Time string
Type string Type string
Arrive string Arrive bool
} }
type JMAEEW struct { type JMAEEW struct {
@ -134,7 +134,14 @@ func Listen() {
} }
equivalentMagnitude := seismo.CalculateEquivalentMagnitude(jmaeew.Magunitude, jmaeew.Latitude, jmaeew.Longitude, config.Config.Latitude, config.Config.Longitude) equivalentMagnitude := seismo.CalculateEquivalentMagnitude(jmaeew.Magunitude, jmaeew.Latitude, jmaeew.Longitude, config.Config.Latitude, config.Config.Longitude)
if config.Config.IssueWarningAtAnyMagnitude || config.Config.IssueWarningAtEquivalentMagnitude < equivalentMagnitude { if config.Config.IssueWarningAtAnyMagnitude || config.Config.IssueWarningAtEquivalentMagnitude < equivalentMagnitude {
alert_body := fmt.Sprintf("Epicenter: %s\nMagnitude %0.1f\nApproximately magnitude %0.1f at your location\nStrong shaking is expected soon.\nStay calm and seek shelter nearby.\n\nOrigin time: %s JST\nAnnouncement time: %s JST\nDepth: %dkm\nCoordinates: %0.1f, %0.1f\n\nSource: %s\nStatus: %s\n\n%s", jmaeew.Hypocenter, jmaeew.Magunitude, equivalentMagnitude, jmaeew.OriginTime, jmaeew.AnnouncedTime, jmaeew.Depth, jmaeew.Latitude, jmaeew.Longitude, jmaeew.Issue.Source, jmaeew.Issue.Status, jmaeew.OriginalText) warnareas := ""
if len(jmaeew.WarnArea) != 0 {
warnareas += "\nWarnings issued for:"
}
for _, warnarea := range jmaeew.WarnArea {
warnareas += fmt.Sprintf("\n - %s (at %s) [Shindo %s / %s] [%s]", warnarea.Chiiki, warnarea.Time, warnarea.Shindo1, warnarea.Shindo2, warnarea.Type)
}
alert_body := fmt.Sprintf("Epicenter: %s\nMagnitude %0.1f\nApproximately magnitude %0.1f at your location%s\n\nStrong shaking is expected soon.\nStay calm and seek shelter nearby.\n\nOrigin time: %s JST\nAnnouncement time: %s JST\nDepth: %dkm\nCoordinates: %0.1f, %0.1f\n\nSource: %s\nStatus: %s\n\n%s", jmaeew.Hypocenter, jmaeew.Magunitude, equivalentMagnitude, warnareas, jmaeew.OriginTime, jmaeew.AnnouncedTime, jmaeew.Depth, jmaeew.Latitude, jmaeew.Longitude, jmaeew.Issue.Source, jmaeew.Issue.Status, jmaeew.OriginalText)
if config.Config.IssuePopup { if config.Config.IssuePopup {
go dialog.Message("%s", alert_body).Title("Early Earthquake Warning!").Info() go dialog.Message("%s", alert_body).Title("Early Earthquake Warning!").Info()
} }