Exemplo 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"));
        }
Exemplo n.º 2
0
        public void ShoudReturnIndexPageViewModel()
        {
            var mockIndexPageViewModel = new Mock <IIndexPageViewModel>();
            IIndexPageViewModel indexPageViewModel, IStationFinder stationFinder,
            IStationFinderResultPageViewModel stationFinderResultPageViewModel, IJourneyfinder journeyFinder,
            IJourneyDetailsPageViewModel      journeyDetailsPageViewModel, IPreviousJourneysViewModel p
            var homeController = new HomeController(mockIndexPageViewModel);
            var stat = new StationFinder();
            int one  = 1;

            Assert.AreEqual(one, 1);
        }
            public void ReturnSuggestionsFromStationFinderStrategy()
            {
                var expected = new Suggestions()
                {
                    Stations    = new [] { "DARTFORD", "DARTON " },
                    NextLetters = new [] { 'F', 'O' }
                };
                var stationFinderStrategyMock = new Mock <IStationFinderStrategy>();

                stationFinderStrategyMock.Setup(x => x.GetSuggestions("DART"))
                .Returns(expected);
                var sut = new StationFinder(stationFinderStrategyMock.Object);

                var actual = sut.GetSuggestions("DART");

                actual.Should().Be(expected);
            }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var rawDataGetter = new RawDataGetter();
            var dataStore     = new DataStore(rawDataGetter);

            var stationsTrie = new Trie();

            foreach (var station in dataStore.GetStations())
            {
                stationsTrie.AddWord(station);
            }

            IVisitor visitor = new DepthFirstVisitor();
            IStationFinderStrategy finderStrategy = new TrieBasedStationFinderStrategy(stationsTrie, visitor);

            if (args.Length > 0)
            {
                if (args.First() == "perf")
                {
                    var basicStrategy = new BasicStationFinderStrategy(dataStore.GetStations());

                    var timedTest = new TimedTest();
                    timedTest.Execute("TrieBased", dataStore, finderStrategy);

                    timedTest = new TimedTest();
                    timedTest.Execute("Basic", dataStore, basicStrategy);
                    return;
                }

                if (args.First() == "basic")
                {
                    Console.WriteLine("[Strategy: Basic]");
                    finderStrategy = new BasicStationFinderStrategy(dataStore.GetStations());
                }
            }

            var finder = new StationFinder(finderStrategy);

            string userInput = "";

            while (true)
            {
                Console.WriteLine("Enter a letter:");
                Console.WriteLine("(or Escape to quit, backspace to delete)");

                var read = Console.ReadKey();

                if (read.Key == ConsoleKey.Escape)
                {
                    break;
                }

                if (read.Key == ConsoleKey.Backspace)
                {
                    if (userInput.Length > 0)
                    {
                        userInput = userInput.Substring(0, userInput.Length - 1);
                    }
                }
                else
                {
                    userInput += read.KeyChar.ToString().ToUpperInvariant();
                }

                var suggestions = finder.GetSuggestions(userInput);

                Console.WriteLine($"\n\nUserInput: {userInput}");
                Console.WriteLine($"NextLetters: {string.Join(" | ", suggestions.NextLetters)}");
                Console.WriteLine($"Stations: {string.Join(" | ", suggestions.Stations)}\n");
            }
        }
Exemplo n.º 6
0
 public void SetupBeforeEachTest()
 {
     stationFinder = new StationFinder();
 }