Forecast { get; set; }
}
public class Current
{
- public string Date { get; set; }
- public double Feelslike { get; set; }
- public int IsDay { get; set; }
+ public string Date { get; set; } = string.Empty;
+ public double Feelslike { get; set; } = 0;
+ public int IsDay { get; set; } = 1;
public double WindPerMeterSecond { get; set; } = 0;
public double WindGustPerMeterSecond { get; set; } = 0;
public double Temperature { get; set; } = 0;
public string LastUpdated { get; set; } = string.Empty;
- public int Cloud { get; set; }
+ public int Cloud { get; set; } = 0;
public string WindDirection { get; set; } = string.Empty;
public Location WeatherDataLocation { get; set; } = new();
public AirQuality AirQuality { get; set; }
@@ -28,72 +30,72 @@ public class Current
public class Location
{
- public string Name { get; set; }
- public string Region { get; set; }
- public string Country { get; set; }
- public double Lat { get; set; }
- public double Lon { get; set; }
+ public string Name { get; set; } = string.Empty;
+ public string Region { get; set; } = string.Empty;
+ public string Country { get; set; } = string.Empty;
+ public double Lat { get; set; } = 0;
+ public double Lon { get; set; } = 0;
}
public class Probability
{
- public DateTime Date { get; set; }
- public CalculatedProbability Calculated { get; set; } // my location?
- public string Colour { get; set; }
- public int Value { get; set; }
- public Highest HighestProbability { get; set; }
+ public DateTime Date { get; set; } = DateTime.Now;
+ public CalculatedProbability Calculated { get; set; } = new();
+ public string Colour { get; set; } = string.Empty;
+ public string Value { get; set; } = string.Empty;
+ public Highest HighestProbability { get; set; } = new();
}
public class Highest
{
- public DateTime Date { get; set; }
- public string Colour { get; set; }
- public double Lat { get; set; }
- public double Long { get; set; }
- public int Value { get; set; }
+ public DateTime Date { get; set; } = DateTime.Now;
+ public string Colour { get; set; } = string.Empty;
+ public double Lat { get; set; } = 0;
+ public double Long { get; set; } = 0;
+ public int Value { get; set; } = 0;
}
public class Forecast
{
- public string Date { get; set; }
- public double MinTempC { get; set; }
- public double MaxTempC { get; set; }
- public string DayIcon { get; set; }
- public WeatherSummary? Day { get; set; }
- public WeatherSummary? Night { get; set; }
- public Astro Astro { get; set; }
- public int IconCode { get; set; }
+ public string Date { get; set; } = string.Empty;
+ public double MinTempC { get; set; } = 0;
+ public double MaxTempC { get; set; } = 0;
+ public string DayIcon { get; set; } = string.Empty;
+ public WeatherSummary? Day { get; set; } = null;
+ public WeatherSummary? Night { get; set; } = null;
+ public Astro Astro { get; set; } = new();
+ public int IconCode { get; set; } = 0;
- public int ChanceOfRain { get; set; }
+ public int ChanceOfRain { get; set; } = 0;
}
public class Astro
{
- public string Sunrise { get; set; }
- public string Sunset { get; set; }
- public string Moonrise { get; set; }
- public string Moonset { get; set; }
- public string Moon_Phase { get; set; }
+ public string Sunrise { get; set; } = string.Empty;
+ public string Sunset { get; set; } = string.Empty;
+ public string Moonrise { get; set; } = string.Empty;
+ public string Moonset { get; set; } = string.Empty;
+ public string Moon_Phase { get; set; } = string.Empty;
public double? Moon_Illumination { get; set; }
}
public class AirQuality
{
- public double Co { get; set; }
- public double No2 { get; set; }
- public double O3 { get; set; }
- public double So2 { get; set; }
- public double Pm2_5 { get; set; }
- public double Pm10 { get; set; }
- public int Us_Epa_Index { get; set; }
- public int Gb_Defra_Index { get; set; }
+ public double Co { get; set; } = 0;
+ public double No2 { get; set; } = 0;
+ public double O3 { get; set; } = 0;
+ public double So2 { get; set; } = 0;
+ public double Pm2_5 { get; set; } = 0;
+ public double Pm10 { get; set; } = 0;
+ public int Us_Epa_Index { get; set; } = 0;
+ public int Gb_Defra_Index { get; set; } = 0;
}
public class WeatherSummary
{
- public string ConditionText { get; set; }
- public string ConditionIcon { get; set; }
- public double AvgTempC { get; set; }
- public double AvgFeelslikeC { get; set; }
- public int TotalChanceOfRain { get; set; }
- public int TotalChanceOfSnow { get; set; }
+ public string ConditionText { get; set; } = string.Empty;
+ public string ConditionIcon { get; set; } = string.Empty;
+ public double AvgTempC { get; set; } = 0;
+ public double AvgFeelslikeC { get; set; } = 0;
+ public int TotalChanceOfRain { get; set; } = 0;
+ public int TotalChanceOfSnow { get; set; } = 0;
}
\ No newline at end of file
diff --git a/HomeApi/wwwroot/index.cshtml b/HomeApi/wwwroot/index.cshtml
index 67a163a..c6915e1 100644
--- a/HomeApi/wwwroot/index.cshtml
+++ b/HomeApi/wwwroot/index.cshtml
@@ -43,8 +43,11 @@
return "fa-question-circle";
}
- private string GetAirQualityStatus(AirQuality data)
+ private string GetAirQualityStatus(AirQuality? data)
{
+ if(data == null)
+ return "No Data";
+
var highestAqi = Math.Max(data.Us_Epa_Index, data.Gb_Defra_Index);
return highestAqi switch
@@ -487,12 +490,12 @@
- @Model.Weather.CityName
+ @(Model.Weather?.CityName ?? "Failed to fetch data")
-
@Model.Weather.Current.Temperature°C
-
Feels like @Model.Weather.Current.Feelslike°C
+
@Model.Weather?.Current.Temperature°C
+
Feels like @Model.Weather?.Current.Feelslike°C
@@ -501,7 +504,7 @@
Clouds
-
@Model.Weather.Current.Cloud%
+
@Model?.Weather?.Current.Cloud%
@@ -509,7 +512,7 @@
Wind
- @Model.Weather.Current.WindPerMeterSecond.ToString("0.##") m/s @Model.Weather.Current.WindDirection
+ @Model?.Weather?.Current.WindPerMeterSecond.ToString("0.##") m/s @Model?.Weather?.Current.WindDirection
@@ -517,7 +520,7 @@
Gusts
- @Model.Weather.Current.WindGustPerMeterSecond.ToString("0.##") m/s
+ @Model?.Weather?.Current.WindGustPerMeterSecond.ToString("0.##") m/s
@@ -525,21 +528,21 @@
Aurora
- @Model.Weather.Current.AuroraProbability.Value%
+ @Model?.Weather?.Current.AuroraProbability.Value%
- Air Quality: @GetAirQualityStatus(Model.Weather.Current.AirQuality)
+ Air Quality: @GetAirQualityStatus(Model?.Weather?.Current.AirQuality)
-
@Model.Weather.Forecast.Count-Day Forecast
+
@Model?.Weather?.Forecast.Count-Day Forecast
- @foreach (var day in Model.Weather.Forecast)
+ @foreach (var day in Model?.Weather?.Forecast ?? Enumerable.Empty
())
{
@GetDayStatus(day.Date)
@@ -559,7 +562,7 @@
Sunrise
- @Model.Weather.Forecast[0].Astro.Sunrise
+ @Model?.Weather?.Forecast[0].Astro.Sunrise
@@ -567,7 +570,7 @@
Sunset
-
@Model.Weather.Forecast[0].Astro.Sunset
+
@Model?.Weather?.Forecast[0].Astro.Sunset
@@ -575,7 +578,7 @@
Moonrise
- @Model.Weather.Forecast[0].Astro.Moonrise
+ @Model?.Weather?.Forecast[0].Astro.Moonrise
@@ -583,12 +586,12 @@
Moonset
- @Model.Weather.Forecast[0].Astro.Moonset
+ @Model?.Weather?.Forecast[0].Astro.Moonset
Moon phase
- @Model.Weather.Forecast[0].Astro.Moon_Illumination%
+ @Model?.Weather?.Forecast[0].Astro.Moon_Illumination%
@@ -598,7 +601,7 @@
Upcoming Departures
- @foreach (var transport in Model.TimeTable.Take(5))
+ @foreach (var transport in Model?.TimeTable?.Take(5) ?? Enumerable.Empty())
{
var departureTime = DateTime.Parse(transport.DepartureTime);