Ejemplo n.º 1
0
        public ActionResult Index(float latitude, float longitude, DateTime start, DateTime end, TimeSpan maxGapSize, int maxNumberOfStations = 50, int maxMiles = 100)
        {
            StationYearBloomMaker.Instance.Prefetch();
            StationIdentifier[] stationsIdentifier = StationFinder.Find(latitude, longitude, maxNumberOfStations, maxMiles);

            if (start > end)
            {
                return(new EmptyResult());
            }

            TimeSpan maxRequest = TimeSpan.FromDays(ConfigHelper.MaxDaysWeatherRequest);

            if (end.Subtract(start) < maxRequest)
            {
                start = end.Subtract(maxRequest);
            }

            StationWeatherReading[] stationWeather = WeatherMerger.Get(stationsIdentifier, start, end, maxGapSize).ToArray();

            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, stationWeather);
                data = ms.ToArray();
            }
            Response.Filter = new GZipStream(Response.Filter, CompressionLevel.Fastest);

            return(this.File(data, "application/gzip"));
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch full  = Stopwatch.StartNew();
            long      total = 0;

            //Parallel.ForEach(latLongs.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries).Take(50000), latlong =>
            Parallel.ForEach(new[] { "45.167,-93.833" }, latlong =>
            {
                var parts = latlong.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                float lat = float.Parse(parts[0]);
                float lon = float.Parse(parts[1]);


                Stopwatch mines = Stopwatch.StartNew();
                StationYearBloomMaker.Instance.Prefetch();
                StationIdentifier[] stationsIdentifier = StationFinder.Find(lat, lon);


                mines.Stop();

                //MessageBox.Show("start Time " + mines.Elapsed);

                var enumerable = WeatherMerger.Get(stationsIdentifier, DateTime.Now.AddYears(-4),
                                                   DateTime.Now, TimeSpan.FromHours(24));

                mines    = Stopwatch.StartNew();
                var list = enumerable.ToList();
                //MessageBox.Show("end Time " + mines.Elapsed + Environment.NewLine + "end count " + list.Count);
                lock (_lock)
                {
                    total += list.Count;
                }
            });

            full.Stop();
            MessageBox.Show(String.Format("end Time {0}{1}end count {2:N0}", full.Elapsed, Environment.NewLine, total));
        }