Example #1
0
        public void TestSo2AqiExpectedCategories()
        {
            Tuple <int, int> result = So2Aqi.CalculateAQIAndCategory(0);

            // 0.0 to 0.034 should be green
            for (double d = 0.0; d <= 0.034; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(1, result.Item2);
            }

            // 0.035 to 0.144 should be yellow
            for (double d = 0.035; d <= 0.144; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(2, result.Item2);
            }

            // 0.145 to 0.244 should be orange
            for (double d = 0.145; d <= 0.224; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(3, result.Item2);
            }

            // 0.245 to 0.304 should be red
            for (double d = 0.225; d <= 0.304; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(4, result.Item2);
            }

            // 0.305 to 0.604 should be purple
            for (double d = 0.305; d <= 0.604; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(5, result.Item2);
            }

            // 0.605 to 1.004 should be maroon
            for (double d = 0.605; d <= 1.004; d += 0.001)
            {
                result = So2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(6, result.Item2);
            }
        }
Example #2
0
        public IHttpActionResult AddStationDataPointSet([FromBody] DataPoint[] dataSet)
        {
            DateTime start = DateTime.Now;

            if (dataSet.Length == 0)
            {
                return(NotFound());
            }

            foreach (DataPoint dataPoint in dataSet)
            {
                if (dataPoint.Category == 0 && dataPoint.AQI == 0 || dataPoint.AQI < 0)
                {
                    Tuple <int, int> result = null;

                    switch (dataPoint.Parameter.Name)
                    {
                    case "PM2.5":
                        result             = Pm25Aqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;

                    case "PM10":
                        result             = Pm10Aqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;

                    case "CO":
                        result             = CoAqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;

                    case "NO2":
                        result             = No2Aqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;

                    case "OZONE":
                        result             = OzoneAqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;

                    case "SO2":
                        result             = So2Aqi.CalculateAQIAndCategory(dataPoint.Value);
                        dataPoint.AQI      = result.Item1;
                        dataPoint.Category = result.Item2;
                        break;
                    }
                }
            }

            IEnumerable <DataPoint> response = _stationRepo.SetDataPointsFromStation(dataSet);
            DateTime end = DateTime.Now;

            if (response == null)
            {
                return(NotFound());
            }

            return(Ok(response));
        }