Beispiel #1
0
        public static FilteredSamples getSamples(NoiseMapEntities db, RequestSamplesOptions options)
        {
            // filter the region
            if (options == null)
            {
                return(new FilteredSamples(db.NOISE_SAMPLE));
            }
            // swap values if start > end
            if (options.LongitudeStart > options.LongitudeEnd)
            {
                var tmp = options.LongitudeStart;
                options.LongitudeStart = options.LongitudeEnd;
                options.LongitudeEnd   = tmp;
            }
            if (options.LatitudeStart > options.LatitudeEnd)
            {
                var tmp = options.LatitudeStart;
                options.LatitudeStart = options.LatitudeEnd;
                options.LatitudeEnd   = tmp;
            }

            var filteredData = db.NOISE_SAMPLE.Where(x => x.longitude >= options.LongitudeStart && x.longitude <= options.LongitudeEnd &&
                                                     x.latitude >= options.LatitudeStart && x.latitude <= options.LatitudeEnd);

            filteredData = applyTimeFilter(options, filteredData);
            return(new FilteredSamples(filteredData));
        }
Beispiel #2
0
        private static IQueryable <NOISE_SAMPLE> applyTimeFilter(RequestSamplesOptions options, IQueryable <NOISE_SAMPLE> data)
        {
            var startTimeSplitted = options.StartTime.Split(':');
            var endTimeSplitted   = options.EndTime.Split(':');
            int hour;
            int minute;
            var success = int.TryParse(startTimeSplitted[0], out hour);

            if (!success)
            {
                return(data);
            }
            success = int.TryParse(startTimeSplitted[1], out minute);
            if (!success)
            {
                return(data);
            }

            var start = new TimeWindow
            {
                Hour   = hour,
                Minute = minute
            };

            success = int.TryParse(endTimeSplitted[0], out hour);
            if (!success)
            {
                return(data);
            }
            success = int.TryParse(endTimeSplitted[1], out minute);
            if (!success)
            {
                return(data);
            }

            var end = new TimeWindow
            {
                Hour   = hour,
                Minute = minute
            };

            if (start.Hour == end.Hour && start.Minute == end.Minute)
            {
                return(data);
            }
            else if (start.Hour != end.Hour && start.Hour < end.Hour)
            {
                return(data.Where(x => x.timestamp.Value.Hour == start.Hour && x.timestamp.Value.Minute >= start.Minute ||
                                  x.timestamp.Value.Hour > start.Hour && x.timestamp.Value.Hour < end.Hour ||
                                  x.timestamp.Value.Hour == end.Hour && x.timestamp.Value.Minute <= end.Minute));
            }
            else if (start.Hour == end.Hour)
            {
                return(data.Where(x => x.timestamp.Value.Hour == start.Hour &&
                                  x.timestamp.Value.Minute >= start.Minute &&
                                  x.timestamp.Value.Minute <= end.Minute));
            }
            else
            {   //start > end
                return(data.Where(x => x.timestamp.Value.Hour == end.Hour && x.timestamp.Value.Minute <= end.Minute ||
                                  x.timestamp.Value.Hour <= end.Hour ||
                                  x.timestamp.Value.Hour == start.Hour && x.timestamp.Value.Minute >= start.Minute ||
                                  x.timestamp.Value.Hour > start.Hour));
            }
        }