From c2311fb7a4a7b353f4c19bbaac235564595a27e0 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 17 Jun 2025 01:15:25 +0800 Subject: [PATCH] feat: Add new event sources --- Assets/Cryville.EEW.Unity/Config.cs | 4 ++-- .../Map/MapElementManager.cs | 2 ++ Assets/Cryville.EEW.Unity/Worker.cs | 22 +++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Assets/Cryville.EEW.Unity/Config.cs b/Assets/Cryville.EEW.Unity/Config.cs index 6d28485..cc3127d 100644 --- a/Assets/Cryville.EEW.Unity/Config.cs +++ b/Assets/Cryville.EEW.Unity/Config.cs @@ -61,7 +61,7 @@ namespace Cryville.EEW.Unity { [JsonDerivedType(typeof(JMAAtomEventSourceConfig), "JMAAtom")] [JsonDerivedType(typeof(NOAAEventSourceConfig), "NOAA")] [JsonDerivedType(typeof(UpdateCheckerEventSourceConfig), "UpdateChecker")] - [JsonDerivedType(typeof(USGSQuakeMLEventSourceConfig), "USGSQuakeML")] + [JsonDerivedType(typeof(USGSEventSourceConfig), "USGSQuakeML")] [JsonDerivedType(typeof(WolfxEventSourceConfig), "Wolfx")] abstract record EventSourceConfig(); record BMKGOpenDataEventSourceConfig([property: JsonRequired] string[] Subtypes) : EventSourceConfig; @@ -73,7 +73,7 @@ namespace Cryville.EEW.Unity { record JMAAtomEventSourceConfig(IReadOnlyCollection Filter = null, bool IsFilterWhitelist = false) : EventSourceConfig; record NOAAEventSourceConfig([property: JsonRequired] string Subtype) : EventSourceConfig; record UpdateCheckerEventSourceConfig : EventSourceConfig; - record USGSQuakeMLEventSourceConfig([property: JsonRequired] string Subtype) : EventSourceConfig; + record USGSEventSourceConfig([property: JsonRequired] string Subtype, bool UseGeoJSONFeeds, string[] Products) : EventSourceConfig; record WolfxEventSourceConfig(IReadOnlyCollection Filter = null, bool IsFilterWhitelist = false, bool UseRawCENCLocationName = false) : EventSourceConfig; [JsonSerializable(typeof(Config))] diff --git a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs index 5b12ab5..7ef7821 100644 --- a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs +++ b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs @@ -9,6 +9,7 @@ using Cryville.EEW.Map; using Cryville.EEW.NOAA.Map; using Cryville.EEW.QuakeML.Map; using Cryville.EEW.Report; +using Cryville.EEW.USGS.Map; using Cryville.EEW.Wolfx.Map; using System.Collections.Generic; using System.Drawing; @@ -145,6 +146,7 @@ namespace Cryville.EEW.Unity.Map { new NOAAMapGenerator(), new QuakeMLEventMapGenerator(), new SichuanEEWMapGenerator(), + new USGSContoursMapGenerator(), }); public UnityMapElement Build(object e, out CultureInfo culture, out int order) { culture = CultureInfo.InvariantCulture; diff --git a/Assets/Cryville.EEW.Unity/Worker.cs b/Assets/Cryville.EEW.Unity/Worker.cs index 75f3333..ac26f7b 100644 --- a/Assets/Cryville.EEW.Unity/Worker.cs +++ b/Assets/Cryville.EEW.Unity/Worker.cs @@ -111,8 +111,11 @@ namespace Cryville.EEW.Unity { worker.RegisterViewModelGenerator(new JMAAtomRVMGenerator()); worker.RegisterViewModelGenerator(new JMAEEWRVMGenerator()); worker.RegisterViewModelGenerator(new NOAAAtomRVMGenerator()); - worker.RegisterViewModelGenerator(new QuakeMLEventRVMGenerator()); + var quakemlEventRVMGenerator = new QuakeMLEventRVMGenerator(); + quakemlEventRVMGenerator.AddExtension(new USGSQuakeMLExtension()); + worker.RegisterViewModelGenerator(quakemlEventRVMGenerator); worker.RegisterViewModelGenerator(new SichuanEEWRVMGenerator()); + worker.RegisterViewModelGenerator(new USGSContoursRVMGenerator()); worker.RegisterViewModelGenerator(new VersionRVMGenerator()); } CENCEarthquakeTTSMessageGenerator _cencEarthquakeTTSMessageGenerator; @@ -168,7 +171,10 @@ namespace Cryville.EEW.Unity { _ => throw new InvalidOperationException("Unknown NOAA sub-type."), }, UpdateCheckerEventSourceConfig => new UpdateCheckerWorker(typeof(Worker).Assembly.GetName().Version?.ToString(3) ?? "", "unity"), - USGSQuakeMLEventSourceConfig usgsQuakeML => BuildUSGSQuakeMLWorkerUri(new USGSQuakeMLWorker(new("https://earthquake.usgs.gov/earthquakes/feed/v1.0/quakeml.php")), usgsQuakeML), + USGSEventSourceConfig usgs => BuildUSGSWorker(usgs.UseGeoJSONFeeds + ? new USGSGeoJSONWorker(new Uri("https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php")) + : new USGSQuakeMLWorker(new Uri("https://earthquake.usgs.gov/earthquakes/feed/v1.0/quakeml.php")) + , usgs), WolfxEventSourceConfig wolfx => BuildWolfxWorkerFilter(new WolfxWorker(new("wss://ws-api.wolfx.jp/all_eew")), wolfx), _ => throw new InvalidOperationException("Unknown event source type."), }); @@ -208,8 +214,16 @@ namespace Cryville.EEW.Unity { worker.DoGetStrongMotionInfo = pref.DoGetStrongMotionInfo; return worker; } - static USGSQuakeMLWorker BuildUSGSQuakeMLWorkerUri(USGSQuakeMLWorker worker, USGSQuakeMLEventSourceConfig config) { - worker.SetFeedRelativeUri(new(string.Format(CultureInfo.InvariantCulture, "/earthquakes/feed/v1.0/summary/{0}.quakeml", config.Subtype), UriKind.Relative)); + static USGSWorker BuildUSGSWorker(USGSWorker worker, USGSEventSourceConfig config) { + worker.SetFeedRelativeUri(new(string.Format(CultureInfo.InvariantCulture, "/earthquakes/feed/v1.0/summary/{0}{1}", config.Subtype, config.UseGeoJSONFeeds ? ".geojson" : ".quakeml"), UriKind.Relative)); + if (worker is USGSGeoJSONWorker geojsonWorker) { + geojsonWorker.SetFilter( + config.Products + .Select(i => i.Split('/', 2)) + .GroupBy(i => i[0]) + .ToDictionary(g => g.Key, g => g.Select(i => i[1])) + ); + } return worker; }