From f892ba3f093c6167c386bbde08ce9286b9f7ea7f Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Sun, 25 Aug 2024 13:52:26 +0200 Subject: [PATCH] feat: add warning areas --- constants/constants.go | 2 +- go.mod | 2 +- go.sum | 3 ++- wolfx/wolfx.go | 11 +++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/constants/constants.go b/constants/constants.go index c6d9872..6a9bb1a 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -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/us6000nith/dyfi/intensity-vs-distance used 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" diff --git a/go.mod b/go.mod index a600250..d1289b5 100644 --- a/go.mod +++ b/go.mod @@ -23,5 +23,5 @@ require ( golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // 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 ) diff --git a/go.sum b/go.sum index 34e3c6a..f0532f8 100644 --- a/go.sum +++ b/go.sum @@ -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-20190429190828-d89cdac9e872/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.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= 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= diff --git a/wolfx/wolfx.go b/wolfx/wolfx.go index f156d17..50d3ce0 100644 --- a/wolfx/wolfx.go +++ b/wolfx/wolfx.go @@ -50,7 +50,7 @@ type WarnArea struct { Shindo2 string Time string Type string - Arrive string + Arrive bool } type JMAEEW struct { @@ -134,7 +134,14 @@ func Listen() { } equivalentMagnitude := seismo.CalculateEquivalentMagnitude(jmaeew.Magunitude, jmaeew.Latitude, jmaeew.Longitude, config.Config.Latitude, config.Config.Longitude) 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 { go dialog.Message("%s", alert_body).Title("Early Earthquake Warning!").Info() }