Пример #1
0
        public static void ProcessIniaData(IWebDriver driver, string stationIniaId)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

            wait.Until(d => d.FindElement(By.CssSelector("#tabla .Tresumen")));

            var row = driver.FindElements(By.CssSelector("#tabla .Tresumen"));

            int index = 0;

            var filterRow = new List <IWebElement>();

            foreach (var item in row)
            {
                if (index >= RowIndex && index <= row.Count)
                {
                    filterRow.Add(item);
                }

                index++;
            }

            emailLines.Add(GetWeatherStationName(stationIniaId));

            emailLines.Add("\n \n");

            foreach (var item in filterRow)
            {
                string[] values = item.Text.Split(' ');

                IniaDTO dto = LoadIniaDTO(values, stationIniaId);

                SaveIniaRecords(dto, stationIniaId);
            }
        }
Пример #2
0
        private static int SaveIniaRecords(IniaDTO dto, string stationIniaId)
        {
            int currentWeatherStationId = 0;

            switch (stationIniaId)
            {
            case "1":
                currentWeatherStationId = (int)Enums.WeatherStations.LasBrujas;
                break;

            case "2":
                currentWeatherStationId = (int)Enums.WeatherStations.LaEstanzuela;
                break;

            case "3":
                currentWeatherStationId = (int)Enums.WeatherStations.Tacuarembo;
                break;

            case "5":
                currentWeatherStationId = (int)Enums.WeatherStations.SaltoGrande;
                break;

            default:
                break;
            }

            IrrigationAdvisorEntities context = new IrrigationAdvisorEntities();

            WeatherStation weatherStation = context.WeatherStations.SingleOrDefault(w => w.WeatherStationId == currentWeatherStationId);

            if (weatherStation != null)
            {
                weatherStation.UpdateTime = DateTime.Now;
            }
            else
            {
                logger.Error("No se pudo encontrar la WeatherStation = {0}", currentWeatherStationId);
            }

            WeatherData existingWeatherData = context.WeatherDatas.SingleOrDefault(w => w.Date == dto.Date && w.WeatherStationId == currentWeatherStationId && w.WeatherDataInputType == (int)Enums.WeatherDataInputType.IniaWeatherService);

            if (existingWeatherData == null)
            {
                WeatherData weatherData = new WeatherData()
                {
                    Date = dto.Date,
                    Evapotranspiration   = dto.ET,
                    Humidity             = dto.AvgHumidity,
                    HumidityMax          = dto.MaxHumidity,
                    HumidityMin          = dto.MinHumidity,
                    RainDay              = dto.RainDay,
                    SolarRadiation       = dto.SolarRadiation,
                    Temperature          = dto.AvgTemperature,
                    TemperatureMax       = dto.MaxTemperature,
                    TemperatureMin       = dto.MinTemperature,
                    WeatherDataInputType = (int)Enums.WeatherDataInputType.IniaWeatherService,
                    WeatherStationId     = currentWeatherStationId,
                    WeatherDataType      = 0,
                    WindSpeed            = dto.WindSpeed
                };

                context.WeatherDatas.Add(weatherData);

                emailLines.Add("Registro nuevo. ");
                emailLines.Add("\n");
            }
            else
            {
                existingWeatherData.Date = dto.Date;
                existingWeatherData.Evapotranspiration   = dto.ET;
                existingWeatherData.Humidity             = dto.AvgHumidity;
                existingWeatherData.HumidityMax          = dto.MaxHumidity;
                existingWeatherData.HumidityMin          = dto.MinHumidity;
                existingWeatherData.RainDay              = dto.RainDay;
                existingWeatherData.SolarRadiation       = dto.SolarRadiation;
                existingWeatherData.Temperature          = dto.AvgTemperature;
                existingWeatherData.TemperatureMax       = dto.MaxTemperature;
                existingWeatherData.TemperatureMin       = dto.MinTemperature;
                existingWeatherData.WeatherDataInputType = (int)Enums.WeatherDataInputType.IniaWeatherService;
                existingWeatherData.WeatherStationId     = currentWeatherStationId;
                existingWeatherData.WeatherDataType      = 0;
                existingWeatherData.WindSpeed            = dto.WindSpeed;

                emailLines.Add("Registro Actualizado");
                emailLines.Add("\n");
            }

            return(context.SaveChanges());
        }
Пример #3
0
        private static IniaDTO LoadIniaDTO(string[] values, string stationIniaId)
        {
            // Get ET
            IniaDTO dto = new IniaDTO();

            string[] dateData = values[Date].Split('-');
            int      year     = Convert.ToInt32(dateData[2]);
            int      month    = Convert.ToInt32(dateData[1]);
            int      day      = Convert.ToInt32(dateData[0]);

            dto.Date = new DateTime(year, month, day);

            string weatherStationName = GetWeatherStationName(stationIniaId);

            if (!lastDates.ContainsKey(weatherStationName))
            {
                lastDates.Add(weatherStationName, dto.Date);
            }

            emailLines.Add("Date : " + dto.Date.ToShortDateString());
            emailLines.Add("\n");
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";

            dto.ET = Convert.ToDouble(values[ET], provider);
            emailLines.Add("ET : " + dto.ET);
            emailLines.Add("\n");

            // Get temperatures
            dto.AvgTemperature = Convert.ToDouble(values[AvgTemperature], provider);
            emailLines.Add("Average Temperature : " + dto.AvgTemperature);
            emailLines.Add("\n");
            dto.MaxTemperature = Convert.ToDouble(values[MaxTemperature], provider);
            emailLines.Add("Max Temperature : " + dto.MaxTemperature);
            emailLines.Add("\n");
            dto.MinTemperature = Convert.ToDouble(values[MinTemperature], provider);
            emailLines.Add("Min Temperature : " + dto.MinTemperature);
            emailLines.Add("\n");

            try
            {
                dto.AvgHumidity = Convert.ToDouble(values[AvgHumedity], provider);
                emailLines.Add("Average Humidity : " + dto.AvgHumidity);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Average Humidity");
            }

            try
            {
                dto.SolarRadiation = Convert.ToDouble(values[Radiation], provider);
                emailLines.Add("Solar Radiation : " + dto.SolarRadiation);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Solar Radiation");
            }

            try
            {
                dto.MaxHumidity = Convert.ToDouble(values[MaxHumedity], provider);
                emailLines.Add("Max Humidity : " + dto.MaxHumidity);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Max Humidity");
            }

            try
            {
                dto.MinHumidity = Convert.ToDouble(values[MinHumedity], provider);
                emailLines.Add("Min Humidity : " + dto.MinHumidity);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Min Humidity");
            }

            try
            {
                dto.RainDay = Convert.ToDouble(values[RainDay], provider);
                emailLines.Add("Rain Day : " + dto.RainDay);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Rain Day");
            }

            try
            {
                dto.WindSpeed = Convert.ToDouble(values[WindSpeed], provider);
                emailLines.Add("Wind Speed : " + dto.RainDay);
                emailLines.Add("\n");
            }
            catch (Exception)
            {
                logger.Warn("Error al cargar Wind Speed");
            }

            return(dto);
        }