From 371e80eb89b8b05d15629ef341d3769abdc53f43 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 1 Jun 2023 16:43:39 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=90=8E=E5=8F=B0]=20=E4=BF=AE=E6=94=B9api=5F?= =?UTF-8?q?weather=20fix=20problem=20api=20of=20rain,=20and=20typhoon=20wi?= =?UTF-8?q?th=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Quartz/Jobs/WeatherAPIJob.cs | 244 +++++++++++------------ Backend/Services/Implement/RainApi.cs | 31 +-- Backend/Services/Implement/TyphoonApi.cs | 142 ++++--------- Backend/appsettings.Development.json | 2 +- Backend/root/PowerfulRain.xml | 136 ------------- Backend/root/Typhoon.xml | 197 ------------------ 6 files changed, 167 insertions(+), 585 deletions(-) delete mode 100644 Backend/root/PowerfulRain.xml delete mode 100644 Backend/root/Typhoon.xml diff --git a/Backend/Quartz/Jobs/WeatherAPIJob.cs b/Backend/Quartz/Jobs/WeatherAPIJob.cs index eb850d8..77adc5f 100644 --- a/Backend/Quartz/Jobs/WeatherAPIJob.cs +++ b/Backend/Quartz/Jobs/WeatherAPIJob.cs @@ -200,71 +200,71 @@ namespace Backend.Quartz.Jobs doc.Load("root/PowerfulRain.xml"); var json = JsonConvert.SerializeXmlNode(doc); var haveinfo = json.Split("info"); - //if (haveinfo.Length > 2) - //{ - // var observation = RainApi.Welcome.FromJson(json); - // var area = observation.Alert.Info[0].Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); - // var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; - // var NeedCallApi = await backendRepository.GetOneAsync(sql); + if (haveinfo.Length > 2) + { + var observation = RainApi.Welcome.FromJson(json); + var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); + var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; + var NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary RainAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@onset", observation.Alert.Info[0].Onset}, - // { "@expires", observation.Alert.Info[0].Expires}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); - // if (NeedCallApi != 0) - // { - // var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); - // if (val < 5) - // { - // var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); - // UpdatedNiagara("api_rain", ReStr, id); - // } - // } + Dictionary RainAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@onset", observation.Alert.Info.Onset}, + { "@expires", observation.Alert.Info.Expires}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); + if (NeedCallApi != 0) + { + var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline); + if (val < 5) + { + var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); + UpdatedNiagara("api_rain", ReStr, id); + } + } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/PowerfulRain.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); - //} - //else - //{ - // var observation = RainApi.Welcome.FromJson(json); - // var area = observation.Alert.Info[0].Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); - // var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; - // var NeedCallApi = await backendRepository.GetOneAsync(sql); + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/PowerfulRain.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); + } + else + { + var observation = RainApi.Welcome.FromJson(json); + var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); + var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; + var NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary RainAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@onset", observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@expires", observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); - // if (NeedCallApi != 0) - // { - // var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); - // if (val < 5) - // { - // var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); - // UpdatedNiagara("api_rain", ReStr, id); - // } - // } + Dictionary RainAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); + if (NeedCallApi != 0) + { + var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline); + if (val < 5) + { + var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); + UpdatedNiagara("api_rain", ReStr, id); + } + } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/PowerfulRain.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/PowerfulRain.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); - //} + } } catch (Exception ex) { @@ -284,71 +284,71 @@ namespace Backend.Quartz.Jobs var json = JsonConvert.SerializeXmlNode(doc); var haveinfo = json.Split("info"); - //if (haveinfo.Length > 2) - //{ - // var observation = TyphoonApi.Welcome.FromJson(json); - // var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); - // var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; - // var NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary EarthquakeAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@urgency",observation.Alert.Info[0].Urgency}, - // { "@severity",observation.Alert.Info[0].Severity}, - // { "@onset", observation.Alert.Info[0].Onset}, - // { "@expires", observation.Alert.Info[0].Expires}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); - // if (NeedCallApi != 0) - // { - // if (observation.Alert.Info[0].Urgency != null && observation.Alert.Info[0].Urgency != "Expected") - // { + if (haveinfo.Length > 2) + { + var observation = TyphoonApi.Welcome.FromJson(json); + var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); + var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; + var NeedCallApi = await backendRepository.GetOneAsync(sql); + Dictionary EarthquakeAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@urgency",observation.Alert.Info.Urgency}, + { "@severity",observation.Alert.Info.Severity}, + { "@onset", observation.Alert.Info.Onset}, + { "@expires", observation.Alert.Info.Expires}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); + if (NeedCallApi != 0) + { + if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected") + { - // var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info[0].Urgency); - // UpdatedNiagara("api_typhoon", ReStr, id); - // } - // } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/Typhoon.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); - //} - //else - //{ - // var observation = TyphoonApi.Welcome.FromJson(json); - // //var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); - // var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; - // var NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary EarthquakeAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info.Headline}, - // //{ "@areaDesc", area}, - // { "@urgency",observation.Alert.Info.Urgency}, - // { "@severity",observation.Alert.Info.Severity}, - // { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); - // if (NeedCallApi != 0) - // { - // if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected") - // { + var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency); + UpdatedNiagara("api_typhoon", ReStr, id); + } + } + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/Typhoon.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); + } + else + { + var observation = TyphoonApi.Welcome.FromJson(json); + //var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); + var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; + var NeedCallApi = await backendRepository.GetOneAsync(sql); + Dictionary EarthquakeAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + //{ "@areaDesc", area}, + { "@urgency",observation.Alert.Info.Urgency}, + { "@severity",observation.Alert.Info.Severity}, + { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); + if (NeedCallApi != 0) + { + if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected") + { - // var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency); - // UpdatedNiagara("api_typhoon", ReStr, id); - // } - // } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/Typhoon.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); + var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency); + UpdatedNiagara("api_typhoon", ReStr, id); + } + } + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/Typhoon.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); - //} + } } catch (Exception ex) diff --git a/Backend/Services/Implement/RainApi.cs b/Backend/Services/Implement/RainApi.cs index ec870f9..2757671 100644 --- a/Backend/Services/Implement/RainApi.cs +++ b/Backend/Services/Implement/RainApi.cs @@ -55,7 +55,7 @@ namespace RainApi public string References { get; set; } [JsonProperty("info")] - public Info[] Info { get; set; } + public Info Info { get; set; } } public partial class Info @@ -69,9 +69,6 @@ namespace RainApi [JsonProperty("event")] public string Event { get; set; } - [JsonProperty("responseType")] - public string ResponseType { get; set; } - [JsonProperty("urgency")] public string Urgency { get; set; } @@ -102,14 +99,17 @@ namespace RainApi [JsonProperty("description")] public string Description { get; set; } + [JsonProperty("instruction")] + public string Instruction { get; set; } + [JsonProperty("web")] public Uri Web { get; set; } [JsonProperty("parameter")] - public EventCode[] Parameter { get; set; } + public EventCode Parameter { get; set; } [JsonProperty("area")] - public Area[] Area { get; set; } + public List Area { get; set; } } public partial class Area @@ -124,7 +124,7 @@ namespace RainApi public partial class EventCode { [JsonProperty("valueName")] - public ValueName ValueName { get; set; } + public string ValueName { get; set; } [JsonProperty("value")] public string Value { get; set; } @@ -139,7 +139,7 @@ namespace RainApi public string Encoding { get; set; } } - public enum ValueName { AlertColor, AlertTitle, ProfileCapTwpEvent10, SeverityLevel, TaiwanGeocode103, WebsiteColor }; + public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode103 }; public partial class Welcome { @@ -177,16 +177,10 @@ namespace RainApi { case "Taiwan_Geocode_103": return ValueName.TaiwanGeocode103; - case "alert_color": - return ValueName.AlertColor; case "alert_title": return ValueName.AlertTitle; case "profile:CAP-TWP:Event:1.0": return ValueName.ProfileCapTwpEvent10; - case "severity_level": - return ValueName.SeverityLevel; - case "website_color": - return ValueName.WebsiteColor; } throw new Exception("Cannot unmarshal type ValueName"); } @@ -204,21 +198,12 @@ namespace RainApi case ValueName.TaiwanGeocode103: serializer.Serialize(writer, "Taiwan_Geocode_103"); return; - case ValueName.AlertColor: - serializer.Serialize(writer, "alert_color"); - return; case ValueName.AlertTitle: serializer.Serialize(writer, "alert_title"); return; case ValueName.ProfileCapTwpEvent10: serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0"); return; - case ValueName.SeverityLevel: - serializer.Serialize(writer, "severity_level"); - return; - case ValueName.WebsiteColor: - serializer.Serialize(writer, "website_color"); - return; } throw new Exception("Cannot marshal type ValueName"); } diff --git a/Backend/Services/Implement/TyphoonApi.cs b/Backend/Services/Implement/TyphoonApi.cs index 07c8546..87a2e6d 100644 --- a/Backend/Services/Implement/TyphoonApi.cs +++ b/Backend/Services/Implement/TyphoonApi.cs @@ -69,9 +69,6 @@ namespace TyphoonApi [JsonProperty("event")] public string Event { get; set; } - [JsonProperty("responseType")] - public string ResponseType { get; set; } - [JsonProperty("urgency")] public string Urgency { get; set; } @@ -100,16 +97,19 @@ namespace TyphoonApi public string Headline { get; set; } [JsonProperty("description")] - public Description Description { get; set; } + public string Description { get; set; } + + [JsonProperty("instruction")] + public string Instruction { get; set; } [JsonProperty("web")] public Uri Web { get; set; } [JsonProperty("parameter")] - public EventCode[] Parameter { get; set; } + public EventCode Parameter { get; set; } [JsonProperty("area")] - public Area[] Area { get; set; } + public List Area { get; set; } } public partial class Area @@ -117,96 +117,8 @@ namespace TyphoonApi [JsonProperty("areaDesc")] public string AreaDesc { get; set; } - [JsonProperty("polygon")] - public string Polygon { get; set; } - } - - public partial class Description - { - [JsonProperty("typhoon-info")] - public TyphoonInfo TyphoonInfo { get; set; } - - [JsonProperty("section")] - public DescriptionSection[] Section { get; set; } - } - - public partial class DescriptionSection - { - [JsonProperty("@title")] - public string Title { get; set; } - - [JsonProperty("#text")] - public string Text { get; set; } - } - - public partial class TyphoonInfo - { - [JsonProperty("section")] - public TyphoonInfoSection[] Section { get; set; } - } - - public partial class TyphoonInfoSection - { - [JsonProperty("@title")] - public string Title { get; set; } - - [JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)] - public string Text { get; set; } - - [JsonProperty("typhoon_name", NullValueHandling = NullValueHandling.Ignore)] - public string TyphoonName { get; set; } - - [JsonProperty("cwb_typhoon_name", NullValueHandling = NullValueHandling.Ignore)] - public string CwbTyphoonName { get; set; } - - [JsonProperty("analysis", NullValueHandling = NullValueHandling.Ignore)] - public Analysis Analysis { get; set; } - - [JsonProperty("prediction", NullValueHandling = NullValueHandling.Ignore)] - public Analysis Prediction { get; set; } - } - - public partial class Analysis - { - [JsonProperty("time")] - public DateTimeOffset Time { get; set; } - - [JsonProperty("position")] - public string Position { get; set; } - - [JsonProperty("max_winds")] - public Gust MaxWinds { get; set; } - - [JsonProperty("gust")] - public Gust Gust { get; set; } - - [JsonProperty("pressure")] - public Gust Pressure { get; set; } - - [JsonProperty("radius_of_15mps")] - public Gust RadiusOf15Mps { get; set; } - - [JsonProperty("scale", NullValueHandling = NullValueHandling.Ignore)] - public Scale[] Scale { get; set; } - } - - public partial class Gust - { - [JsonProperty("@unit")] - public string Unit { get; set; } - - [JsonProperty("#text")] - [JsonConverter(typeof(ParseStringConverter))] - public long Text { get; set; } - } - - public partial class Scale - { - [JsonProperty("@lang")] - public string Lang { get; set; } - - [JsonProperty("#text")] - public string Text { get; set; } + [JsonProperty("geocode")] + public EventCode Geocode { get; set; } } public partial class EventCode @@ -227,6 +139,8 @@ namespace TyphoonApi public string Encoding { get; set; } } + public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode103 }; + public partial class Welcome { public static Welcome FromJson(string json) => JsonConvert.DeserializeObject(json, QuickType.Converter.Settings); @@ -245,25 +159,30 @@ namespace TyphoonApi DateParseHandling = DateParseHandling.None, Converters = { + ValueNameConverter.Singleton, new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } }, }; } - internal class ParseStringConverter : JsonConverter + internal class ValueNameConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?); + public override bool CanConvert(Type t) => t == typeof(ValueName) || t == typeof(ValueName?); public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) return null; var value = serializer.Deserialize(reader); - long l; - if (Int64.TryParse(value, out l)) + switch (value) { - return l; + case "Taiwan_Geocode_103": + return ValueName.TaiwanGeocode103; + case "alert_title": + return ValueName.AlertTitle; + case "profile:CAP-TWP:Event:1.0": + return ValueName.ProfileCapTwpEvent10; } - throw new Exception("Cannot unmarshal type long"); + throw new Exception("Cannot unmarshal type ValueName"); } public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) @@ -273,11 +192,22 @@ namespace TyphoonApi serializer.Serialize(writer, null); return; } - var value = (long)untypedValue; - serializer.Serialize(writer, value.ToString()); - return; + var value = (ValueName)untypedValue; + switch (value) + { + case ValueName.TaiwanGeocode103: + serializer.Serialize(writer, "Taiwan_Geocode_103"); + return; + case ValueName.AlertTitle: + serializer.Serialize(writer, "alert_title"); + return; + case ValueName.ProfileCapTwpEvent10: + serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0"); + return; + } + throw new Exception("Cannot marshal type ValueName"); } - public static readonly ParseStringConverter Singleton = new ParseStringConverter(); + public static readonly ValueNameConverter Singleton = new ValueNameConverter(); } } diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index d3d0353..6892d36 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -20,7 +20,7 @@ "RegularUpdateDBTableJob": "0 0 2 * * ?", "ParkingJob": "0 0 2 * * ?", "ArchiveElectricMeterHourJob": "0 0 2 * * ?", - "ArchiveElectricMeterDayJob": "0/5 * * * * ?", + "ArchiveElectricMeterDayJob": "0 0 2 * * ?", "WeatherAPIJob": "0/5 * * * * ?" }, "DBConfig": { diff --git a/Backend/root/PowerfulRain.xml b/Backend/root/PowerfulRain.xml deleted file mode 100644 index 01f5439..0000000 --- a/Backend/root/PowerfulRain.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - CWB-Weather_extremely-rain_202306011035001 - weather@cwb.gov.tw - 2023-06-01T10:43:55+08:00 - Actual - Update - Public - weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306010655001,2023-06-01T07:02:17+08:00 weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306010345001,2023-06-01T03:56:19+08:00 - - zh-TW - Met - 降雨 - Monitor - Future - Moderate - Likely - - profile:CAP-TWP:Event:1.0 - rainfall - - 2023-06-01T10:35:00+08:00 - 2023-06-01T10:36:00+08:00 - 2023-06-01T23:00:00+08:00 - 中央氣象局 - 大雨特報 - -颱風外圍環流影響,今(1)日新竹以北及宜蘭山區有局部大雨發生的機率,請注意瞬間大雨,山區請慎防坍方及落石。 - - https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html - - alert_title - 大雨特報 - - - severity_level - 大雨 - - - alert_color - 黃色 - - - website_color - 255,255,0 - - - - 新竹縣橫山鄉 - - Taiwan_Geocode_103 - 1000408 - - - 新竹縣北埔鄉 - - Taiwan_Geocode_103 - 1000409 - - - 桃園市復興區 - - Taiwan_Geocode_103 - 6801300 - - - 臺北市士林區 - - Taiwan_Geocode_103 - 6301100 - - - 新北市三峽區 - - Taiwan_Geocode_103 - 6500900 - - - 新北市石碇區 - - Taiwan_Geocode_103 - 6501900 - - - 臺北市北投區 - - Taiwan_Geocode_103 - 6301200 - - - 新竹縣五峰鄉 - - Taiwan_Geocode_103 - 1000413 - - - 新竹縣尖石鄉 - - Taiwan_Geocode_103 - 1000412 - - - 新北市烏來區 - - Taiwan_Geocode_103 - 6502900 - - - 新北市坪林區 - - Taiwan_Geocode_103 - 6502000 - - - 新北市平溪區 - - Taiwan_Geocode_103 - 6502400 - - - 宜蘭縣南澳鄉 - - Taiwan_Geocode_103 - 1000212 - - - 宜蘭縣大同鄉 - - Taiwan_Geocode_103 - 1000211 - - - - - \ No newline at end of file diff --git a/Backend/root/Typhoon.xml b/Backend/root/Typhoon.xml deleted file mode 100644 index 9dd9749..0000000 --- a/Backend/root/Typhoon.xml +++ /dev/null @@ -1,197 +0,0 @@ - - - - CWB-Weather_typhoon-warning_202305311730001 - weather@cwb.gov.tw - 2023-05-31T17:17:30+08:00 - Actual - Cancel - Public - weather@cwb.gov.tw,CWB-Weather_typhoon-warning_202305311430001,2023-05-31T14:22:23+08:00 - - zh-TW - Met - 颱風 - Past - Minor - Observed - - profile:CAP-TWP:Event:1.0 - typhoon - - 2023-05-31T17:30:00+08:00 - 2023-05-31T17:30:00+08:00 - 2023-05-31T17:40:00+08:00 - 中央氣象局 - 解除颱風警報 - -[颱風動態] -根據最新資料顯示,第2號颱風暴風半徑略為縮小,中心目前在鵝鑾鼻東北東方海面,向北北東轉東北移動,對巴士海峽及臺灣東半部近海威脅已解除。 - -[注意事項] -*巴士海峽及臺灣附近各海面風浪明顯偏大;基隆北海岸、南部、東半部(含蘭嶼、綠島)、恆春半島沿海及澎湖、馬祖易有長浪發生,尤其東半部(含蘭嶼、綠島)、基隆北海岸、恆春半島沿海易有4至5米浪高,請避免前往海邊活動。*陸上強風特報:今(31)日臺南至苗栗沿海空曠地區及澎湖、蘭嶼、綠島易有9至10級強陣風,新竹以北、基隆北海岸、東半部沿海空曠地區、臺南至苗栗地區、恆春半島、金門、馬祖亦有較強陣風,請特別注意。*30日0時至31日17時出現較大累積雨量如下:宜蘭縣翠峰湖334.5毫米,臺中市南湖圈谷257.0毫米。*本警報單之颱風半徑為平均半徑,第2號颱風之7級風暴風半徑近似正圓,平均半徑約為280公里。颱風詳細特性請參考本局颱輔助說明(https://www.cwb.gov.tw/Data/typhoon/TY_PDF.pdf)。*此為第2號颱風警報最後一次報告。 - - - - https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html - - alert_title - 颱風警報 - - - - 基隆市 - - Taiwan_Geocode_103 - 10017 - - - - 臺北市 - - Taiwan_Geocode_103 - 63 - - - - 新北市 - - Taiwan_Geocode_103 - 65 - - - - 桃園市 - - Taiwan_Geocode_103 - 68 - - - - 新竹市 - - Taiwan_Geocode_103 - 10018 - - - - 新竹縣 - - Taiwan_Geocode_103 - 10004 - - - - 苗栗縣 - - Taiwan_Geocode_103 - 10005 - - - - 臺中市 - - Taiwan_Geocode_103 - 66 - - - - 彰化縣 - - Taiwan_Geocode_103 - 10007 - - - - 雲林縣 - - Taiwan_Geocode_103 - 10009 - - - - 南投縣 - - Taiwan_Geocode_103 - 10008 - - - - 嘉義縣 - - Taiwan_Geocode_103 - 10010 - - - - 嘉義市 - - Taiwan_Geocode_103 - 10020 - - - - 臺南市 - - Taiwan_Geocode_103 - 67 - - - - 高雄市 - - Taiwan_Geocode_103 - 64 - - - - 屏東縣 - - Taiwan_Geocode_103 - 10013 - - - - 宜蘭縣 - - Taiwan_Geocode_103 - 10002 - - - - 花蓮縣 - - Taiwan_Geocode_103 - 10015 - - - - 臺東縣 - - Taiwan_Geocode_103 - 10014 - - - - 澎湖縣 - - Taiwan_Geocode_103 - 10016 - - - - 金門縣 - - Taiwan_Geocode_103 - 09020 - - - - 連江縣 - - Taiwan_Geocode_103 - 09007 - - - - \ No newline at end of file