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 GetLocationFromAddress_ResultFail() { GeoCoderClient myGeoCoderClient = new GeoCoderClient(); string address = "Chez moi"; GeoLocation resultGeoLocation = myGeoCoderClient.GetLocationFromAddress(address); Assert.AreEqual(true, resultGeoLocation.success); Assert.AreEqual(5, resultGeoLocation.results[0].accuracy); }
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); }
public void GetLocationFromAddress_SimpleTest() { GeoCoderClient myGeoCoderClient = new GeoCoderClient(); string address = "560 rue de Neudorf 2220 Luxembourg"; GeoLocation resultGeoLocation = myGeoCoderClient.GetLocationFromAddress(address); Assert.AreEqual(true, resultGeoLocation.success); Assert.AreEqual(1, resultGeoLocation.results.Count()); Assert.AreEqual(8, resultGeoLocation.results[0].accuracy); Assert.AreEqual("560 Rue de Neudorf,2220 Luxembourg", resultGeoLocation.results[0].address); Assert.AreEqual(6.18447006860937, resultGeoLocation.results[0].geomlonlat.coordinates[0]); Assert.AreEqual(49.6223621694221, resultGeoLocation.results[0].geomlonlat.coordinates[1]); //Assert.AreEqual(new List<double>() {6.18447006860937, 49.6223621694221 }, resultGeoLocation.results[0].GetLonLatCoordinates()); }
public ActionResult GetPOIFromAddress(string address) { GeoCoderClient geoClient = new GeoCoderClient(); GeoLocation geoLocation = geoClient.GetLocationFromAddress(address); //GeoCoderClient myGeoCoderClient = new GeoCoderClient(); //CityParksClient myCityParksClient = new CityParksClient(); //Finder myFinder = new Finder(myGeoCoderClient, myCityParksClient); //ResultParkEntity[] resultParks = myFinder.GetParksByAddress("560 rue de Neudorf 2220 Luxembourg"); string geoJSon = JsonConvert.SerializeObject(geoLocation.results[0].geomlonlat); //string result = @"{""type"": ""FeatureCollection"", ""features"": ["; return(Json(geoLocation.results[0].geomlonlat, JsonRequestBehavior.AllowGet)); //result += makeJsonItem(geoLocation.results[0]); //result += "]}"; //return Content(result, "application/vnd.geo+json"); }
public Finder(GeoCoderClient geoCoder, CityParksClient cityParks) { this.geoCoder = geoCoder; this.cityParks = cityParks; }