Ejemplo n.º 1
0
        private static StationObservations CreateTestData()
        {
            var stationObservations = new StationObservations
            {
                Station = new Station()
                {
                    Identifier = "TEST"
                },
                Observations = new Observation[]
                {
                    new Observation()
                    {
                        Timestamp = new DateTime(2018, 11, 2, 0, 5, 0, DateTimeKind.Utc),
                        WindSpeed = 3
                    },
                    new Observation()
                    {
                        Timestamp = new DateTime(2018, 11, 2, 0, 10, 0, DateTimeKind.Utc),
                        WindSpeed = 18
                    },
                    new Observation()
                    {
                        Timestamp = new DateTime(2018, 11, 2, 0, 20, 0, DateTimeKind.Utc),
                        WindSpeed = 9
                    },
                }
            };

            return(stationObservations);
        }
Ejemplo n.º 2
0
        public WindSpeedBin[] Create(StationObservations stationObservations, NormalizeWindSpeedStrategy normalizeWindSpeedStrategy)
        {
            var stationIdentifier = stationObservations.Station.Identifier;

            if (!stationObservations.Observations.Any())
            {
                return(new WindSpeedBin[0]);
            }
            var grps = stationObservations.Observations
                       .GroupBy(x => new DateTime(x.Timestamp.Year, x.Timestamp.Month, x.Timestamp.Day, x.Timestamp.Hour, 0, 0, DateTimeKind.Utc));
            var date    = grps.Min(x => x.Key);
            var maxDate = grps.Max(x => x.Key);

            var bins = new List <WindSpeedBin>();

            while (date <= maxDate)
            {
                double?normalizedWindSpeed;
                var    grp = grps.SingleOrDefault(x => x.Key == date);
                if (grp == null)
                {
                    normalizedWindSpeed = null;
                }
                else
                {
                    var strategy = GetStrategyFunc(normalizeWindSpeedStrategy);
                    normalizedWindSpeed = strategy(grp);
                }
                var bin = new WindSpeedBin(stationIdentifier, date, normalizedWindSpeed);
                bins.Add(bin);
                date = date.AddHours(1);
            }

            return(bins.ToArray());
        }