public JsonResult GetParks(string address, string expectedHour) { // TODO check that the string is valid (not an attack) double parsedHouer = expectedHour == "" ? 0.0 : double.Parse(expectedHour); //CityPark API + finder GeoCoderClient myGeoCoderClient = new GeoCoderClient(); CityParksClient myCityParksClient = new CityParksClient(); Finder parkFinder = new Finder(myGeoCoderClient, myCityParksClient); ResultParkEntity[] resultParks = parkFinder.GetParksByAddress(address); //Forecast Factory ParkOccupancyFactory forecastFactory = new ParkOccupancyFactory(new Models.DAL.GameOfCode2016Entities()); foreach (ResultParkEntity parkResult in resultParks) { if (parkResult.Id != 0)//To avoid Parks without Id ! { OccupancyForecast occupancyForecast = forecastFactory.GetForecast(parkResult.Id, parsedHouer == 0 ? DateTime.Now : DateTime.Now.AddHours(parsedHouer)); if (occupancyForecast != null) { parkResult.FreeSlots = occupancyForecast.FreeSlots; parkResult.Rate = occupancyForecast.Rate; } } } //Order result by Rate return(Json(BuildTop3(resultParks), JsonRequestBehavior.AllowGet)); }
public void GetParksByAddress_SimpleTest() { GeoCoderClient myGeoCoderClient = new GeoCoderClient(); CityParksClient myCityParksClient = new CityParksClient(); Finder myFinder = new Finder(myGeoCoderClient, myCityParksClient); ResultParkEntity[] resultParks = myFinder.GetParksByAddress("560 rue de Neudorf 2220 Luxembourg"); Assert.AreEqual(26, resultParks.Count()); Assert.AreEqual("Auchan", resultParks[0].Name); Assert.AreEqual("Luxexpo", resultParks[1].Name); Assert.AreEqual("Kirchberg", resultParks[2].Name); }
private static void Worker() { Thread.CurrentThread.Name = "Worker Thread"; DateTime lastUpdate = DateTime.MinValue; CityParksClient parksClient = new CityParksClient(); ARIMAEngine2 engine = new ARIMAEngine2(); while (continueToWork) { var now = DateTime.Now; if (now > lastUpdate.AddMinutes(frequencyInMinutes)) { // Refresh Occupancy var items = parksClient.GetCityParks().ToDictionary(k => k.Id ?? 666, k => k); var parkingIds = items.Keys.ToArray(); var occupancy = items.Values.Select(cp => new Occupancy() { Date = now, FreeSlots = cp.Actuel ?? 666, Rate = (1.0 - (cp.Actuel ?? 666.0) / (cp.Total ?? 666.0)) * 100.0, ParkingId = cp.Id ?? 666, }).ToArray(); ParkOccupancyFactory factory = new ParkOccupancyFactory(new GameOfCode2016Entities()); factory.SaveOccupancy(occupancy); Console.WriteLine("Saving Status"); // Forecast DateTime dataStartDate = DateTime.Now.AddMonths(-1); var forecasts = parkingIds.SelectMany(parkingId => { var sourceData = factory.GetForecastsSince(dataStartDate, parkingId).Select(f => f.Rate).ToArray(); var occ = engine.ForeCast(sourceData, 2 * 60 / frequencyInMinutes); // 2 hours with 5min interval var toSave = new List <Forecast>(); int count = 0; foreach (double item in occ) { var rate = Math.Max(Math.Min(item, 100.0), 0); count++; toSave.Add(new Forecast() { Date = now.AddMinutes(frequencyInMinutes * count), ParkingId = parkingId, Rate = rate, FreeSlots = (int)(items[parkingId].Total * (100 - rate) / 100), }); } return(toSave); }).ToArray(); ParkOccupancyFactory factory2 = new ParkOccupancyFactory(new GameOfCode2016Entities()); factory2.SaveForecast(forecasts); Console.WriteLine("Forecast saved"); lastUpdate = now; } Thread.Sleep(5000); } }
public Finder(GeoCoderClient geoCoder, CityParksClient cityParks) { this.geoCoder = geoCoder; this.cityParks = cityParks; }
public void GetCityParks_SimpleTest() { CityParksClient client = new CityParksClient(); CityCarPark[] parks = client.GetCityParks(); }