-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from AlienDwarf/develop
9 - Support for Air Quality API
- Loading branch information
Showing
15 changed files
with
706 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenMeteo | ||
{ | ||
/// <summary> | ||
/// Air Quality Api response | ||
/// </summary> | ||
public class AirQuality | ||
{ | ||
/// <summary> | ||
/// WGS84 of the center of the weather grid-cell which was used to generate this forecast. | ||
/// </summary> | ||
[JsonPropertyName("latitude")] | ||
public float Latitude { get; set; } | ||
|
||
/// <summary> | ||
/// WGS84 of the center of the weather grid-cell which was used to generate this forecast. | ||
/// </summary> | ||
[JsonPropertyName("longitude")] | ||
public float Longitude { get; set; } | ||
|
||
/// <summary> | ||
/// Generation time of the weather forecast in milliseconds. | ||
/// </summary> | ||
[JsonPropertyName("generationtime_ms")] | ||
public float GenerationTime { get; set; } | ||
|
||
/// <summary> | ||
/// Timezone offset from <see cref="AirQualityOptions.Timezone"/> | ||
/// </summary> | ||
[JsonPropertyName("utc_offset_seconds")] | ||
public int UtcOffset { get; set; } | ||
|
||
/// <summary> | ||
/// Timezone identifier | ||
/// </summary> | ||
[JsonPropertyName("timezone")] | ||
public string? Timezone { get; set; } | ||
|
||
/// <summary> | ||
/// Timezone abbreviation | ||
/// </summary> | ||
[JsonPropertyName("timezone_abbreviation")] | ||
public string? TimezoneAbbreviation { get; set; } | ||
|
||
/// <summary> | ||
/// Returned data for each selected variable in <see cref="AirQualityOptions.Hourly"/> | ||
/// </summary> | ||
[JsonPropertyName("hourly")] | ||
public HourlyValues? Hourly { get; set; } | ||
|
||
/// <summary> | ||
/// For each selected variable in <see cref="AirQuality.Hourly"/>, the unit | ||
/// </summary> | ||
[JsonPropertyName("hourly_units")] | ||
public HourlyUnits? Hourly_Units { get; set; } | ||
|
||
public class HourlyUnits | ||
{ | ||
public string? Time { get; set; } | ||
public string? Pm10 { get; set; } | ||
public string? Pm2_5 { get; set; } | ||
public string? Carbon_monoxide { get; set; } | ||
public string? Nitrogen_dioxide { get; set; } | ||
public string? Sulphur_dioxide { get; set; } | ||
public string? Ozone { get; set; } | ||
public string? Aerosol_optical_depth { get; set; } | ||
public string? Dust { get; set; } | ||
public string? Uv_index { get; set; } | ||
public string? Uv_index_clear_sky { get; set; } | ||
public string? Alder_pollen { get; set; } | ||
public string? Birch_pollen { get; set; } | ||
public string? Grass_pollen { get; set; } | ||
public string? Mugwort_pollen { get; set; } | ||
public string? Olive_pollen { get; set; } | ||
public string? Ragweed_pollen { get; set; } | ||
} | ||
|
||
public class HourlyValues | ||
{ | ||
public string[]? Time { get; set; } | ||
public float?[]? Pm10 { get; set; } | ||
public float?[]? Pm2_5 { get; set; } | ||
public float?[]? Carbon_monoxide { get; set; } | ||
public float?[]? Nitrogen_dioxide { get; set; } | ||
public float?[]? Sulphur_dioxide { get; set; } | ||
public float?[]? Ozone { get; set; } | ||
public float?[]? Aerosol_optical_depth { get; set; } | ||
public float?[]? Dust { get; set; } | ||
public float?[]? Uv_index { get; set; } | ||
public float?[]? Uv_index_clear_sky { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Alder_pollen { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Birch_pollen { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Grass_pollen { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Mugwort_pollen { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Olive_pollen { get; set; } | ||
|
||
/// <summary> | ||
/// Only available in Europe during pollen season with 4 days forecast | ||
/// </summary> | ||
public float?[]? Ragweed_pollen { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenMeteo | ||
{ | ||
public class AirQualityOptions | ||
{ | ||
/// <summary> | ||
/// Geographical WGS84 coordinate of the location | ||
/// </summary> | ||
public float Latitude { get; set; } | ||
|
||
/// <summary> | ||
/// Geographical WGS84 coordinate of the location | ||
/// </summary> | ||
public float Longitude { get; set; } | ||
|
||
/// <summary> | ||
/// A list of air quality variables which should be returned. | ||
/// </summary> | ||
public HourlyOptions Hourly { get { return _hourly; } set { if (value != null) _hourly = value; } } | ||
|
||
/// <summary> | ||
/// Default value: "auto". Other values: "cams_europe" for europe or "cams_global" for global domain | ||
/// </summary> | ||
public string Domains { get; set; } | ||
|
||
/// <summary> | ||
/// Default value: "iso8601". Other options: "unixtime" | ||
/// </summary> | ||
public string Timeformat { get; set; } | ||
|
||
/// <summary> | ||
/// Default value: "GMT". | ||
/// </summary> | ||
public string Timezone { get; set; } | ||
|
||
/// <summary> | ||
/// Past days data which should also be returned | ||
/// </summary> | ||
public int Past_Days { get; set; } | ||
|
||
/// <summary> | ||
/// A day must be specified as an ISO8601 | ||
/// </summary> | ||
public string Start_date { get; set; } | ||
|
||
/// <summary> | ||
/// A day must be specified as an ISO8601 | ||
/// </summary> | ||
public string End_date { get; set; } | ||
|
||
private HourlyOptions _hourly = new HourlyOptions(); | ||
|
||
public AirQualityOptions() | ||
{ | ||
Latitude = 0; | ||
Longitude = 0; | ||
Hourly = new HourlyOptions(); | ||
Domains = "auto"; | ||
Timeformat = "iso8601"; | ||
Timezone = "GMT"; | ||
Past_Days = 0; | ||
Start_date = ""; | ||
End_date = ""; | ||
} | ||
|
||
public AirQualityOptions(float latitude, float longitude) | ||
{ | ||
Latitude = latitude; | ||
Longitude = longitude; | ||
Hourly = new HourlyOptions(); | ||
Domains = "auto"; | ||
Timeformat = "iso8601"; | ||
Timezone = "GMT"; | ||
Past_Days = 0; | ||
Start_date = ""; | ||
End_date = ""; | ||
} | ||
|
||
public AirQualityOptions(float latitude, float longitude, HourlyOptions hourly, string domains, string timeformat, string timezone, int past_Days, string start_date, string end_date) | ||
{ | ||
Latitude = latitude; | ||
Longitude = longitude; | ||
if (hourly != null) | ||
Hourly = hourly; | ||
Domains = domains; | ||
Timeformat = timeformat; | ||
Timezone = timezone; | ||
Past_Days = past_Days; | ||
Start_date = start_date; | ||
End_date = end_date; | ||
} | ||
|
||
public class HourlyOptions : IEnumerable<HourlyOptionsParameter>, ICollection<HourlyOptionsParameter> | ||
{ | ||
public static HourlyOptions All { get { return new HourlyOptions((HourlyOptionsParameter[])Enum.GetValues(typeof(HourlyOptionsParameter))); } } | ||
|
||
public List<AirQualityOptions.HourlyOptionsParameter> Parameter { get { return new List<HourlyOptionsParameter>(_parameter); } } | ||
|
||
public int Count => _parameter.Count; | ||
|
||
public bool IsReadOnly => false; | ||
|
||
private readonly List<HourlyOptionsParameter> _parameter = new List<HourlyOptionsParameter>(); | ||
|
||
public HourlyOptions(HourlyOptionsParameter parameter) | ||
{ | ||
Add(parameter); | ||
} | ||
|
||
public HourlyOptions(HourlyOptionsParameter[] parameter) | ||
{ | ||
Add(parameter); | ||
} | ||
|
||
public HourlyOptions() | ||
{ | ||
|
||
} | ||
|
||
public HourlyOptionsParameter this[int index] | ||
{ | ||
get { return _parameter[index]; } | ||
set | ||
{ | ||
_parameter[index] = value; | ||
} | ||
} | ||
|
||
public void Add(HourlyOptionsParameter param) | ||
{ | ||
if (this._parameter.Contains(param)) return; | ||
|
||
_parameter.Add(param); | ||
} | ||
|
||
public void Add(HourlyOptionsParameter[] param) | ||
{ | ||
foreach (HourlyOptionsParameter paramToAdd in param) | ||
{ | ||
Add(paramToAdd); | ||
} | ||
} | ||
|
||
public IEnumerator<HourlyOptionsParameter> GetEnumerator() | ||
{ | ||
return _parameter.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return this.GetEnumerator(); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
_parameter.Clear(); | ||
} | ||
|
||
public bool Contains(HourlyOptionsParameter item) | ||
{ | ||
return _parameter.Contains(item); | ||
} | ||
|
||
public void CopyTo(HourlyOptionsParameter[] array, int arrayIndex) | ||
{ | ||
_parameter.CopyTo(array, arrayIndex); | ||
} | ||
|
||
public bool Remove(HourlyOptionsParameter item) | ||
{ | ||
return _parameter.Remove(item); | ||
} | ||
} | ||
|
||
public enum HourlyOptionsParameter | ||
{ | ||
pm10, | ||
pm2_5, | ||
carbon_monoxide, | ||
nitrogen_dioxide, | ||
sulphur_dioxide, | ||
ozone, | ||
aerosol_optical_depth, | ||
dust, | ||
uv_index, | ||
uv_index_clear_sky, | ||
alder_pollen, | ||
birch_pollen, | ||
grass_pollen, | ||
mugwort_pollen, | ||
olive_pollen, | ||
ragweed_pollen | ||
} | ||
} | ||
} |
Oops, something went wrong.