Skip to content

Commit

Permalink
Merge pull request #169 from AirQualityControl/feature/implement-get-…
Browse files Browse the repository at this point in the history
…airpollution-by-geolocation

Feature/implement get airpollution by geolocation
  • Loading branch information
ArturLavrov authored Dec 29, 2023
2 parents 39092e3 + 37ba2e1 commit 5d3e849
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AirSnitch.Api.Controllers.AirQualityIndexController.ViewModel;
Expand Down Expand Up @@ -60,13 +61,16 @@ public async Task<IActionResult> GetIndexValue([FromQuery]AirQualityIndexRequest

var airPollution = activeStation.GetAirPollution();

var usaAqi = new UsaAirQualityIndex();
var index = airPollution.GetAirQualityIndexValue();

if (index == null)
{
throw new Exception("Index needs to be calculated");
}

var indexValue = usaAqi.Calculate(airPollution);

var aqiViewModel = new AirQualityIndexViewModel(
index: usaAqi,
indexValue:indexValue,
index: new UsaAirQualityIndex(),
indexValue:index,
Request);

aqiViewModel.SetMeasurementDateTime(airPollution.GetMeasurementsDateTime());
Expand Down
7 changes: 6 additions & 1 deletion src/AirSnitch.Domain/Models/DangerLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ namespace AirSnitch.Domain.Models
{
public enum DangerLevel
{
Good
Good,
Moderate,
UnhealthyForSensitiveGroups,
Unhealthy,
VeryUnhealthy,
Hazardous
}
}
12 changes: 11 additions & 1 deletion src/AirSnitch.Domain/Models/UsaAiqIndexValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace AirSnitch.Domain.Models
{
Expand All @@ -17,7 +18,16 @@ internal UsaAiqIndexValue(int calculatedValue, DateTime measurementDateTime)

public DangerLevel GetDangerLevel()
{
return DangerLevel.Good;
return _calculatedValue switch
{
> 0 and <= 50 => DangerLevel.Good,
> 50 and <= 100 => DangerLevel.Moderate,
> 100 and <= 150 => DangerLevel.UnhealthyForSensitiveGroups,
> 150 and <= 200 => DangerLevel.Unhealthy,
> 200 and <= 300 => DangerLevel.VeryUnhealthy,
> 300 and <= 500 => DangerLevel.Hazardous,
_ => throw new ArgumentException($"Invalid Index value: {_calculatedValue}")
};
}

public AirQualityDescription GetDescription()
Expand Down

0 comments on commit 5d3e849

Please sign in to comment.