Ejemplo n.º 1
0
        public void TestNo2AqiExpectedCategories()
        {
            Tuple <int, int> result = No2Aqi.CalculateAQIAndCategory(0);

            // 0.65 to 1.24 should be purple
            for (double d = 0.65; d <= 1.24; d += 0.01)
            {
                result = No2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(5, result.Item2);
            }

            // 1.25 to 2.04 should be purple
            for (double d = 1.25; d <= 2.04; d += 0.01)
            {
                result = No2Aqi.CalculateAQIAndCategory(d);
                Assert.AreEqual(6, result.Item2);
            }
        }
Ejemplo n.º 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));
        }