From 54d1019413958e0ba24b85007c1f5f97ca19a0b3 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 4 Dec 2017 13:01:04 +0100 Subject: Added levels of AQI. --- PollutometerWebApi.Tests/Test.cs | 1 + .../bin/Debug/PollutometerWebApi.Tests.dll | Bin 4096 -> 4096 bytes .../bin/Debug/PollutometerWebApi.Tests.pdb | Bin 532 -> 536 bytes .../bin/Debug/PollutometerWebApi.dll | Bin 16384 -> 16896 bytes .../bin/Debug/PollutometerWebApi.pdb | Bin 3984 -> 4216 bytes ...bApi.Tests.csprojResolveAssemblyReference.cache | Bin 109342 -> 109342 bytes .../obj/Debug/PollutometerWebApi.Tests.dll | Bin 4096 -> 4096 bytes .../obj/Debug/PollutometerWebApi.Tests.pdb | Bin 532 -> 536 bytes PollutometerWebApi.userprefs | 13 ++++--- PollutometerWebApi/EmailSender.cs | 39 +++++++++++---------- PollutometerWebApi/Models/Aqi.cs | 28 ++++++++++++++- 11 files changed, 56 insertions(+), 25 deletions(-) diff --git a/PollutometerWebApi.Tests/Test.cs b/PollutometerWebApi.Tests/Test.cs index cc17234..abec015 100644 --- a/PollutometerWebApi.Tests/Test.cs +++ b/PollutometerWebApi.Tests/Test.cs @@ -9,6 +9,7 @@ namespace PollutometerWebApi.Tests public void TestCase() { var result = AqiCalculator.CalculateAqi(new Models.Reading() {Co = 30.4, No = 1.0, So = 0.4}); + EmailSender.SendEmail(result); } } } diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll index 4fec8a3..29a96a6 100644 Binary files a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll and b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll differ diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb index 4b521ed..d4059a7 100644 Binary files a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb and b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb differ diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.dll b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.dll index 205cb6b..ebf4ce3 100644 Binary files a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.dll and b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.dll differ diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.pdb b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.pdb index 176b41e..ca309d7 100644 Binary files a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.pdb and b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.pdb differ diff --git a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csprojResolveAssemblyReference.cache b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csprojResolveAssemblyReference.cache index e810d97..2906fc7 100644 Binary files a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csprojResolveAssemblyReference.cache and b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csprojResolveAssemblyReference.cache differ diff --git a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.dll b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.dll index 4fec8a3..29a96a6 100644 Binary files a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.dll and b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.dll differ diff --git a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.pdb b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.pdb index 4b521ed..d4059a7 100644 Binary files a/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.pdb and b/PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.pdb differ diff --git a/PollutometerWebApi.userprefs b/PollutometerWebApi.userprefs index 36d72e1..822fb73 100644 --- a/PollutometerWebApi.userprefs +++ b/PollutometerWebApi.userprefs @@ -1,16 +1,19 @@ - - + + - + - + + - + + + diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs index f62a9ca..6cc60fc 100644 --- a/PollutometerWebApi/EmailSender.cs +++ b/PollutometerWebApi/EmailSender.cs @@ -8,26 +8,27 @@ namespace PollutometerWebApi { public static void SendEmail(Aqi aqi) { - MailMessage mail = new MailMessage("***REMOVED***", "alek2026@edu.easj.dk"); - SmtpClient client = new SmtpClient() - { - Host = "mail.cock.li", - Port = 587, - EnableSsl = true, - Timeout = 100, - DeliveryMethod = SmtpDeliveryMethod.Network, - UseDefaultCredentials = false, - Credentials = new System.Net.NetworkCredential("***REMOVED***", "***REMOVED***") - }; - mail.Subject = $"Pollutometer warning - {DateTime.Now}"; - mail.IsBodyHtml = true; - mail.Body = "

WARNING!

\n" + - "\n" + - "\n" + - "\n" + + MailMessage mail = new MailMessage("***REMOVED***", "alek2026@edu.easj.dk"); + SmtpClient client = new SmtpClient() + { + Host = "mail.cock.li", + Port = 587, + EnableSsl = true, + Timeout = 100, + DeliveryMethod = SmtpDeliveryMethod.Network, + UseDefaultCredentials = false, + Credentials = new System.Net.NetworkCredential("***REMOVED***", "***REMOVED***") + }; + mail.Subject = $"Pollutometer warning - {DateTime.Now}"; + mail.IsBodyHtml = true; + mail.Body = "

WARNING!

\n" + + "\n" + + "\n" + + "\n" + $"

The warning was triggered by {aqi.GasName}.

\n" + - $"

Air quality index: {aqi.Value}

"; - client.Send(mail); + $"

Air quality index: {aqi.Value}

" + + $"

The AQI level is {aqi.Level}!"; + client.Send(mail); } } } \ No newline at end of file diff --git a/PollutometerWebApi/Models/Aqi.cs b/PollutometerWebApi/Models/Aqi.cs index 490df85..b13ddb0 100644 --- a/PollutometerWebApi/Models/Aqi.cs +++ b/PollutometerWebApi/Models/Aqi.cs @@ -2,7 +2,33 @@ { public class Aqi { + double _value; + public string GasName { get; set; } - public double Value { get; set; } + public double Value + { + get + { + return _value; + } + set + { + _value = value; + + if (_value >= 0 && _value <= 50) + Level = "Good"; + else if (_value >= 51 && _value <= 100) + Level = "Moderate"; + else if (_value >= 101 && _value <= 150) + Level = "Unhealthy for Sensitive Groups"; + else if (_value >= 151 && _value <= 200) + Level = "Unhealthy"; + else if (_value >= 201 && _value <= 300) + Level = "Very Unhealthy"; + else if (_value >= 301 && _value <= 500) + Level = "Hazardous"; + } + } + public string Level { get; set; } } } -- cgit v1.2.3