Example #1
0
        public WeatherViewModel(WeatherCity weatherCity, AbstractPredictManager manager)
        {
            //var bufferDate = manager.UnixTimeStampToDateTime(weatherCity.dt);
            if (manager == null || (weatherCity?.weather == null || (!weatherCity.weather?.Any() ?? false)))
            {
                return;
            }
            CurrentDate = DateTime.Now
                          .ToString("dd.MM.yyyy", CultureInfo.InvariantCulture);       //bufferDate.ToShortDateString();
            CurrentTime = DateTime.Now
                          .ToString("HH:mm", CultureInfo.InvariantCulture);
            Temperature           = manager.KelvinToCelcia(kelvinTemperature: weatherCity.main?.temp ?? 0) + "`C";
            DirectionAndSpeedWind = manager.CreateDirectionAndSpeedWind(weatherCity.wind);
            SpeedWind             = ((int)(weatherCity.wind?.speed ?? 0)) + "м/с";
            PrecipationIcon       = DateTime.Now
                                    .TimeOfDay
                                    .ToString();
            var buffPrecipitation = weatherCity.weather
                                    .FirstOrDefault()
                                    ?.description ?? "";

            switch (buffPrecipitation)
            {
            case "overcast clouds":
                Precipation  = "Переменная облачность";
                Precipation2 = "Облачно";
                break;

            case "clear sky":
                Precipation = "Солнечно";
                break;

            case "few clouds":
                Precipation  = "Переменная облачность";
                Precipation2 = "Облачно";
                break;

            case "scattered clouds":
                Precipation  = "Небольшая облачность";
                Precipation2 = "Облачно";
                break;

            case "broken clouds":
                Precipation  = "Облачно";
                Precipation2 = "Облачно";
                break;

            case "shower rain":
                Precipation  = "Сильный дождь";
                Precipation2 = "Дождь";
                break;

            case "rain":
                Precipation  = "Дождь";
                Precipation2 = "Дождь";
                break;

            case "thunderstorm":
                Precipation  = "Гроза";
                Precipation2 = "Гроза";
                break;

            case "snow":
                Precipation  = "Снег";
                Precipation2 = "Снег";
                break;

            case "light snow":
                Precipation  = "Небольшой снег";
                Precipation2 = "Снег";
                break;

            case "mist":
                Precipation  = "Туман";
                Precipation2 = "Туман";
                break;

            default:
                Precipation  = "Переменная";
                Precipation2 = "Переменная";
                break;
            }
            PrecipationIcon = $"~/../../Content/Images/weatherIcons/" + (weatherCity.weather.Any() ? $"{weatherCity.weather.FirstOrDefault()?.icon ?? ""}.png" :"01d.png");
        }
Example #2
0
 public void Set(WeatherCity weatherCity)
 {
     if (weatherCity == null)
     {
         return;
     }
     @base  = weatherCity.@base;
     clouds = new Clouds()
     {
         all = weatherCity.clouds?.all ?? 0
     };
     cod   = weatherCity.cod;
     coord = new Coord()
     {
         Id  = weatherCity.coord?.Id,
         lat = weatherCity.coord?.lat,
         lon = weatherCity.coord?.lon
     };
     dt   = weatherCity.dt;
     id   = weatherCity.id;
     main = new Main()
     {
         humidity = weatherCity.main?.humidity ?? 0,
         pressure = weatherCity.main?.pressure ?? 0,
         temp     = weatherCity.main?.temp ?? 0,
         temp_max = weatherCity.main?.temp_max ?? 0,
         temp_min = weatherCity.main?.temp_min ?? 0
     };
     name = weatherCity.name;
     rain = new Rain()
     {
         Precipitation_In_The_Last_3_Hours = weatherCity.rain?.Precipitation_In_The_Last_3_Hours ?? 0
     };
     sys = new Sys()
     {
         country = weatherCity.sys?.country,
         id      = weatherCity.sys?.id ?? 0,
         message = weatherCity.sys?.message ?? 0,
         sunrise = weatherCity.sys?.sunrise ?? 0,
         sunset  = weatherCity.sys?.sunset ?? 0,
         type    = weatherCity.sys?.type ?? 0
     };
     weather = new List <Weather>()
     {
         new Weather()
         {
             description = weatherCity.weather
                           .ToList()
                           .FirstOrDefault()
                           ?.description ?? "",
             icon = weatherCity.weather
                    .ToList()
                    .FirstOrDefault()
                    ?.icon,
             id = weatherCity.weather
                  .FirstOrDefault()
                  ?.id ?? -1,
             main = weatherCity.weather
                    .FirstOrDefault()
                    ?.main ?? ""
         }
     };
 }