mirror of
https://github.com/MistWeatherMedia/i2ME.git
synced 2026-11-28 14:20:00 -08:00
add TideForecast
This commit is contained in:
1 parent
b5b336f4d7
commit
d2cb90a32d
4 files changed
+94
No files matched your search
@@ -0,0 +1,18 @@
|
||||
using MistWX_i2Me.Schema.ibm;
|
||||
|
||||
namespace MistWX_i2Me.API.Products;
|
||||
|
||||
public class TideForecastProduct : Base
|
||||
{
|
||||
public TideForecastProduct()
|
||||
{
|
||||
this.RecordName = "TidesForecast";
|
||||
this.DataUrl =
|
||||
"https://api.weather.com/v1/location/{locId}:{locType}:{cntryCd}/forecast/tides.xml?language=en-US&startDate={curDate}&endDate={curDatePlusFive}&units=e&apiKey={apiKey}";
|
||||
}
|
||||
|
||||
public async Task<List<GenericResponse<TideForecastResponse>>> Populate(string[] locations)
|
||||
{
|
||||
return await GetData<TideForecastResponse>(locations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using MistWX_i2Me.API;
|
||||
using MistWX_i2Me.Schema.ibm;
|
||||
|
||||
namespace MistWX_i2Me.RecordGeneration;
|
||||
|
||||
public class TideForecastRecord : I2Record
|
||||
{
|
||||
public async Task<string> MakeRecord(List<GenericResponse<TideForecastResponse>> results)
|
||||
{
|
||||
Log.Info("Creating current observations record..");
|
||||
string recordPath = Path.Combine(AppContext.BaseDirectory, "temp", "TideForecast.xml");
|
||||
string recordScript = "<Data type=\"TidesForecast\">";
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
recordScript +=
|
||||
$"<TidesForecast id=\"000000000\" locationKey=\"{result.Location.primTecci}\" isWxScan=\"0\">" +
|
||||
$"{result.RawResponse}<clientKey>{result.Location.primTecci}</clientKey></TidesForecast>";
|
||||
}
|
||||
|
||||
recordScript += "</Data>";
|
||||
|
||||
await File.WriteAllTextAsync(recordPath, ValidateXml(recordScript));
|
||||
|
||||
return recordPath;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,15 @@ public class CurrentObservationsMetadata
|
||||
public int status_code { get; set; }
|
||||
}
|
||||
|
||||
public class TideForecastMetadata
|
||||
{
|
||||
public string language { get; set; }
|
||||
public string transaction_id { get; set; }
|
||||
public string version { get; set; }
|
||||
public string location_id { get; set; }
|
||||
public string units { get; set; }
|
||||
public int status_code { get; set; }
|
||||
}
|
||||
public class DailyForecastMetadata
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace MistWX_i2Me.Schema.ibm;
|
||||
|
||||
[XmlRoot(ElementName = "tide")]
|
||||
public class Tide
|
||||
{
|
||||
[XmlElement(ElementName = "class")] public string Class { get; set; }
|
||||
[XmlElement(ElementName = "tide_id")] public int TideId { get; set; }
|
||||
[XmlElement(ElementName = "station_id")] public int StationId { get; set; }
|
||||
[XmlElement(ElementName = "present_nm")] public string PresentNM { get; set; }
|
||||
[XmlElement(ElementName = "st_cd")] public string StCD { get; set; }
|
||||
[XmlElement(ElementName = "country_cd")] public string CountryCD { get; set; }
|
||||
[XmlElement(ElementName = "station_latitude")] public float StationLatitude { get; set; }
|
||||
[XmlElement(ElementName = "station_longitude")] public float StationLongitude { get; set; }
|
||||
[XmlElement(ElementName = "prediction_type")] public string PredictionType { get; set; }
|
||||
[XmlElement(ElementName = "tide_tm")] public string TideTM { get; set; }
|
||||
[XmlElement(ElementName = "tide_epoch")] public int TideEpoch { get; set; }
|
||||
[XmlElement(ElementName = "tide_type")] public string TideType { get; set; }
|
||||
[XmlElement(ElementName = "tide_ht")] public float TideHt { get; set; }
|
||||
[XmlElement(ElementName = "annual_max_ht")] public float AnnualMaxHt { get; set; }
|
||||
[XmlElement(ElementName = "annual_min_ht")] public float AnnualMinHt { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "tides")]
|
||||
public class Tides
|
||||
{
|
||||
[XmlElement(ElementName = "tide")] public List<Tide> Tide { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
[XmlRoot(ElementName = "tidesResponse")]
|
||||
public class TideForecastResponse
|
||||
{
|
||||
[XmlElement(ElementName = "metadata")] public TideForecastMetadata Metadata { get; set; }
|
||||
|
||||
[XmlElement(ElementName = "tides")]
|
||||
public Tides Tides { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user