Esempio n. 1
0
        private IEnumerable <WeatherData <Int32> > ProcessValues(WeatherValue <Int32> data, IEnumerable <TimeLayout> timeLayouts)
        {
            var list = new List <WeatherData <Int32> >();

            if (data != null)
            {
                var timeLayout = timeLayouts.FirstOrDefault(t => t.Key.Equals(data.TimeLayoutKey));
                if (timeLayout != null)
                {
                    for (var index = 0; index < data.Values.Length; index++)
                    {
                        var startTime = timeLayout.StartTimes[index];
                        var endTime   = new DateTime?();
                        if (timeLayout.EndTimes != null)
                        {
                            endTime = timeLayout.EndTimes[index];
                        }
                        list.Add(new WeatherData <Int32>
                        {
                            Value = data.Values[index],
                            Start = startTime,
                            End   = endTime
                        });
                    }
                }
            }
            return(list);
        }
Esempio n. 2
0
        public HttpResponseMessage GetVal(long id, bool?isCorrect = null)
        {
            WeatherValue wv = db.WeatherValues.Find(id);

            wv.IsCorrect = isCorrect;
            if (isCorrect == true || isCorrect == null)
            {
                wv.ActualIcon = null;
            }

            var vals = db.WeatherValues.Where(v => v.DateTime == wv.DateTime);

            foreach (WeatherValue v in vals)
            {
                if (wv.PgoIconId == v.PgoIconId)
                {
                    if (isCorrect == true || isCorrect == null)
                    {
                        v.ActualIcon = null;
                        v.IsCorrect  = isCorrect;
                    }
                    else
                    {
                        v.IsCorrect = isCorrect;
                    }
                }
            }
            db.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 public static void MapData <TFromType, TToType>(WeatherValue <TFromType> from, WeatherValue <TToType> to)
 {
     to.Name          = from.Name;
     to.TimeLayoutKey = from.TimeLayoutKey;
     to.Type          = from.Type;
     to.Units         = from.Units;
 }
Esempio n. 4
0
        private IEnumerable <WeatherData <Int32> > ProcessValues(WeatherValue <float> data,
                                                                 IEnumerable <TimeLayout> timeLayouts)
        {
            var newVal = data.ToInt32();

            return(ProcessValues(newVal, timeLayouts));
        }
Esempio n. 5
0
 public static void SaveWeather(WeatherObject wo, WeatherTranslation wt)
 {
     using (PokeEntities db = new PokeEntities())
     {
         WeatherValue wv = new WeatherValue()
         {
             DateTime    = wo.DateTime.ToUniversalTime(),
             WeatherIcon = wo.WeatherIcon,
             IconPhrase  = wo.IconPhrase,
             IsDaylight  = wo.IsDaylight,
             TempValue   = wo.Temperature.Value,
             TempUnit    = wo.Temperature.Unit,
             WindSpeed   = wo.Wind.Speed.Value,
             WindUnit    = wo.Wind.Speed.Unit,
             GustSpeed   = wo.WindGust.Speed.Value,
             GustUnit    = wo.WindGust.Speed.Unit,
             PrecipitationProbability = wo.PrecipitationProbability,
             RainProbability          = wo.RainProbability,
             SnowProbability          = wo.SnowProbability,
             IceProbability           = wo.IceProbability,
             CloudCover = wo.CloudCover,
             RainAmt    = wo.Rain.Value,
             SnowAmt    = wo.Snow.Value,
             IceAmt     = wo.Ice.Value,
             PgoIconId  = wt.PgoWeather.Id,
             DateAdded  = DateTime.Now.ToUniversalTime()
         };
         db.WeatherValues.Add(wv);
         db.SaveChanges();
     }
 }
        public static WeatherValue <Int32> ToInt32(this WeatherValue <float> data)
        {
            var newVal = new WeatherValue <Int32>();

            MapData(data, newVal);
            newVal.Values = data.Values.ToList().ConvertAll(Convert.ToInt32).ToArray();

            return(newVal);
        }
Esempio n. 7
0
 protected void ValidateBaseParameter <TValue>(WeatherValue <TValue> param)
 {
     param.Name.ShouldNotBeEmpty();
     param.Values.Length.ShouldBeGreaterThan(0);
     param.Units.ShouldNotBeEmpty();
     param.TimeLayoutKey.ShouldNotBeEmpty();
     param.Type.ShouldNotBeEmpty();
     _sut.Data.TimeLayouts.Any(x => x.Key.Equals(param.TimeLayoutKey)).ShouldBeTrue();
 }
Esempio n. 8
0
        public HttpResponseMessage PostCorrect(WeatherValue val)
        {
            WeatherValue wv     = db.WeatherValues.Find(val.Id);
            var          values = db.WeatherValues.Where(w => w.DateTime == wv.DateTime && w.PgoIconId == wv.PgoIconId).ToArray();

            for (var i = 0; i < values.Length; i++)
            {
                long vId = values[i].Id;
                var  v   = db.WeatherValues.Find(val.Id);
                v.ActualIconid = val.ActualIconid;
                db.SaveChanges();
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 9
0
        public HttpResponseMessage GetWeather()
        {
            // get forecast from AccuWeather and save in DB
            // this needs to get called hourly at about 5 past the hour (or 35 past if your time zone is a half hour off)

            using (WebClient client = new WebClient())
            {
                var             resp       = client.DownloadString("http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/" + Resources.LocationId + "?apikey=" + Resources.ApiKey + "&metric=true&details=true");
                var             now        = DateTime.UtcNow;
                DateTime        thisTime   = DateTime.Now;
                string          tzId       = Resources.TimeZoneId;
                TimeZoneInfo    tst        = TimeZoneInfo.FindSystemTimeZoneById(tzId);
                bool            isDaylight = tst.IsDaylightSavingTime(thisTime);
                WeatherObject[] response   = null;
                try
                {
                    response = JsonConvert.DeserializeObject <WeatherObject[]>(resp);
                }
                catch (Exception ex)
                {
                    Trace.Write(ex);
                }
                var LindsayTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(now, tst.Id);

                List <WeatherValue> wvs = new List <WeatherValue>();
                for (var i = 0; i < response.Length; i++)
                {
                    var w = response[i];
                    //w.PokeWeather = new PgoWeather();
                    WeatherTranslation wt = db.WeatherTranslations.Find(w.WeatherIcon);
                    int weatherId;
                    if (wt.CanWindy == true && (w.Wind.Speed.Value > 29 || w.WindGust.Speed.Value > 31)) // (OR IS IT SUM OF THESE ? 55? This works for me, anyway)
                    {
                        w.PokeWeather = db.PgoWeathers.Find(6);
                        weatherId     = 6;
                    }
                    else
                    {
                        weatherId = wt.PgoWeather.Id;
                    }

                    WeatherValue wv = new WeatherValue()
                    {
                        DateTime    = w.DateTime,
                        WeatherIcon = w.WeatherIcon,
                        IconPhrase  = w.IconPhrase,
                        IsDaylight  = w.IsDaylight,
                        TempUnit    = w.Temperature.Unit,
                        TempValue   = w.Temperature.Value,
                        WindSpeed   = w.Wind.Speed.Value,
                        WindUnit    = w.Wind.Speed.Unit,
                        GustSpeed   = w.WindGust.Speed.Value,
                        GustUnit    = w.WindGust.Speed.Unit,
                        PrecipitationProbability = w.PrecipitationProbability,
                        RainProbability          = w.RainProbability,
                        RainAmt         = w.Rain.Value,
                        RainUnit        = w.Rain.Unit,
                        SnowProbability = w.SnowProbability,
                        SnowAmt         = w.Snow.Value,
                        SnowUnit        = w.Snow.Unit,
                        IceProbability  = w.IceProbability,
                        IceAmt          = w.Ice.Value,
                        IceUnit         = w.Ice.Unit,
                        CloudCover      = w.CloudCover,
                        PgoIconId       = weatherId,
                        DateAdded       = now
                    };
                    wvs.Add(wv);
                }
                WeatherEntry entry = new WeatherEntry()
                {
                    DateCreated   = LindsayTime,
                    Date          = LindsayTime,
                    Hour          = LindsayTime.Hour,
                    WeatherValues = wvs
                };
                db.WeatherEntries.Add(entry);
                db.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, "got it"));
            }
        }
Esempio n. 10
0
        public static void FixTime(WeatherValue w, DateTime date)
        {
            TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(Resources.TimeZoneId);

            w.DateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(w.DateTime, tst.Id);
        }
Esempio n. 11
0
 private IEnumerable<WeatherData<Int32>> ProcessValues(WeatherValue<Int32> data, IEnumerable<TimeLayout> timeLayouts)
 {
     var list = new List<WeatherData<Int32>>();
     if (data != null)
     {
         var timeLayout = timeLayouts.FirstOrDefault(t => t.Key.Equals(data.TimeLayoutKey));
         if (timeLayout != null)
         {
             for (var index = 0; index < data.Values.Length; index++)
             {
                 var startTime = timeLayout.StartTimes[index];
                 var endTime = new DateTime?();
                 if (timeLayout.EndTimes != null)
                 {
                     endTime = timeLayout.EndTimes[index];
                 }
                 list.Add(new WeatherData<Int32>
                 {
                     Value = data.Values[index],
                     Start = startTime,
                     End = endTime
                 });
             }
         }
     }
     return list;
 }
Esempio n. 12
0
 private IEnumerable<WeatherData<Int32>> ProcessValues(WeatherValue<float> data,
     IEnumerable<TimeLayout> timeLayouts)
 {
     var newVal = data.ToInt32();
     return ProcessValues(newVal, timeLayouts);
 }