public void GetAddressFromCoordinates_GoodCoords() { //Arrange Address address = new Address { Longitude = "12.58514", Latitude = "55.68323" }; AddressCoordinates uut = new AddressCoordinates(); Address correctAddress = new Address { StreetName = "Landgreven", StreetNumber = "10", ZipCode = 1301, Town = "København K", Longitude = "12.58514", Latitude = "55.68323" }; //Act Address result = uut.GetAddressFromCoordinates(address); //Assert Assert.AreEqual(correctAddress.StreetName, result.StreetName); Assert.AreEqual(correctAddress.StreetNumber, result.StreetNumber); Assert.AreEqual(correctAddress.ZipCode, result.ZipCode); Assert.AreEqual(correctAddress.Town, result.Town); }
public void Setup() { ICustomSettings customSettings = new CustomSettings(); IUrlDefinitions urlDefinitions = new UrlDefinitions(customSettings); IAddressLaunderer addressLaunderer = new AddressLaundering(urlDefinitions); uut = new AddressCoordinates(addressLaunderer, urlDefinitions); }
public void GetCoordinates_BadAddress_ThrowException() { //Arrange Address address = new Address { StreetName = "Bjergvej Alle Troll", StreetNumber = "90", ZipCode = 8200 }; AddressCoordinates uut = new AddressCoordinates(); //Act //Assert Assert.Throws(typeof(AddressCoordinatesException), () => uut.GetCoordinates(address, Coordinates.CoordinatesType.Origin), "Errors in address, see inner exception."); }
public void GetAddressFromCoordinates_BadCoords_ThrowException() { //Arrange Address address = new Address { Longitude = "999.00", Latitude = "999.00" }; AddressCoordinates uut = new AddressCoordinates(); //Act //Assert Assert.Throws(typeof(AddressCoordinatesException), () => uut.GetAddressFromCoordinates(address), "Server error, coordinates invalid"); }
public void TryReClean() { var tempRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); var coords = new AddressCoordinates(); var i = 0; var rows = tempRepo.AsQueryable().Where(x => x.HomeIsDirty || x.WorkIsDirty).ToList(); foreach (var history in rows) { i++; Console.WriteLine(i + " of " + rows.Count); history.WorkIsDirty = false; history.HomeIsDirty = false; try { coords.GetAddressCoordinates(new Address { StreetName = SplitAddressOnNumber(history.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(history.HjemmeAdresse)[1], ZipCode = history.HjemmePostNr, Town = history.HjemmeBy }); } catch (Exception e) { history.HomeIsDirty = true; } try { coords.GetAddressCoordinates(new Address { StreetName = SplitAddressOnNumber(history.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(history.ArbejdsAdresse)[1], ZipCode = history.ArbejdsPostNr, Town = history.ArbejdsBy }); } catch (Exception e) { history.WorkIsDirty = true; } } tempRepo.Save(); }
public void GetCoordinates_GoodCoordinates() { //Arrange Address address = new Address { StreetName = "Katrinebjergvej", StreetNumber = "90", ZipCode = 8200 }; AddressCoordinates uut = new AddressCoordinates(); Coordinates correctCoord = new Coordinates { Longitude = "10.1906", Latitude = "56.1735", Type = Coordinates.CoordinatesType.Origin }; //Act Coordinates result = uut.GetCoordinates(address, Coordinates.CoordinatesType.Origin); //Assert Assert.IsTrue(correctCoord.Equals(result)); }
public void GetAddressCoordinatesSecond_GoodCoordinates() { //Arrange Address address = new Address { StreetName = "Katrinebjergvej", StreetNumber = "90", ZipCode = 8200 }; AddressCoordinates uut = new AddressCoordinates(); Address correctCoord = new Address { StreetName = "Katrinebjergvej", StreetNumber = "90", ZipCode = 8200, Longitude = "10.1906964757185", Latitude = "56.1735754688399", }; //Act Address result = uut.GetAddressCoordinates(address); //Assert Assert.IsTrue(correctCoord.Latitude == result.Latitude && correctCoord.Longitude == result.Longitude); }
public void GetAddressCoordinatesSecond_GoodCoordinates() { //Arrange Address address = new Address { StreetName = "Katrinebjergvej", StreetNumber = "90", ZipCode = 8200 }; AddressCoordinates uut = new AddressCoordinates(); Address correctCoord = new Address { StreetName = "Katrinebjergvej", StreetNumber = "90", ZipCode = 8200, Longitude = "10.19069648", Latitude = "56.17357547" }; //Act Address result = uut.GetAddressCoordinates(address); //Assert Assert.AreEqual(correctCoord.Latitude, result.Latitude); Assert.AreEqual(correctCoord.Longitude, result.Longitude); }
/// <summary> /// Returns the shortest route within the time limit. (Duration <= 300s , Length difference > 3000m) /// </summary> /// <param name="transportType">Type of transport. Car or bike.</param> /// <param name="addresses"></param> /// <exception cref="AddressLaunderingException"></exception> /// <exception cref="AddressCoordinatesException"></exception> /// <exception cref="RouteInformationException"></exception> /// <returns></returns> public RouteInformation GetRoute(DriveReportTransportType transportType, IEnumerable <Address> addresses) { if (addresses == null || !addresses.Any()) { return(null); } var addressesList = addresses.ToList(); List <Coordinates> routeCoordinates = new List <Coordinates>(); AddressCoordinates coordService = new AddressCoordinates(); SeptimaRouter septimaService = new SeptimaRouter(); var origin = addressesList[0]; var destination = addressesList[addressesList.Count - 1]; addressesList.Remove(origin); addressesList.Remove((destination)); if (String.IsNullOrEmpty(origin.Longitude)) { routeCoordinates.Add(coordService.GetCoordinates(origin, Coordinates.CoordinatesType.Origin)); } else { routeCoordinates.Add(new Coordinates() { Longitude = origin.Longitude, Latitude = origin.Latitude, Type = Coordinates.CoordinatesType.Origin }); } foreach (var address in addressesList) { if (String.IsNullOrEmpty(address.Longitude)) { routeCoordinates.Add(coordService.GetCoordinates(address, Coordinates.CoordinatesType.Via)); } else { routeCoordinates.Add(new Coordinates() { Longitude = address.Longitude, Latitude = address.Latitude, Type = Coordinates.CoordinatesType.Via }); } } if (String.IsNullOrEmpty(destination.Longitude)) { routeCoordinates.Add(coordService.GetCoordinates(destination, Coordinates.CoordinatesType.Destination)); } else { routeCoordinates.Add(new Coordinates() { Longitude = destination.Longitude, Latitude = destination.Latitude, Type = Coordinates.CoordinatesType.Destination }); } try { List <RouteInformation> routes = septimaService.GetRoute(transportType, routeCoordinates).OrderBy(x => x.Duration).ToList(); // Sort routes by duration and pick the one with the shortest duration. // OS2RouteMap.js in the frontend picks the route with the shortest duration // Therefore the backend should pick a route based on the same criteria. routes = routes.OrderBy(x => x.Duration).ToList(); var bestRoute = routes[0]; // Divide by 1000 to get it in kilometers. bestRoute.Length /= 1000; return(bestRoute); } catch (AddressCoordinatesException e) { //Logger.Error("Exception when getting route information", e); } return(null); }
public void TransferFromTempToActual() { var tempRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); var actualRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <AddressHistory> >(); var workAddressRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <WorkAddress> >(); var personalAddressRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <PersonalAddress> >(); var coords = new AddressCoordinates(); var emplRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <Employment> >(); var i = 0; var rows = tempRepo.AsQueryable().Where(x => !x.WorkIsDirty && !x.HomeIsDirty).ToList(); foreach (var tempHistory in rows) { i++; Console.WriteLine(i + " of " + rows.Count); var currentTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var empls = emplRepo.AsQueryable().Where(x => x.EmploymentId == tempHistory.MaNr).ToList(); if (empls.Count == 0) { continue;; } var empl = new Employment(); if (empls.Count == 1) { // If only one empl with manr exists just use that empl = empls.First(); } else { // If more than one exists then select the active one. // If an active one does not exist then select the one that ended most recently empl = empls.FirstOrDefault(x => x.EndDateTimestamp == 0) ?? empls.OrderByDescending(x => x.EndDateTimestamp).First(); } var workTemp = coords.GetAddressCoordinates(new WorkAddress() { StreetName = SplitAddressOnNumber(tempHistory.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(tempHistory.ArbejdsAdresse)[1], ZipCode = tempHistory.ArbejdsPostNr, Town = tempHistory.ArbejdsBy, }); var workAddress = new WorkAddress { StreetName = workTemp.StreetName, StreetNumber = workTemp.StreetNumber, ZipCode = workTemp.ZipCode, Town = workTemp.Town, Latitude = workTemp.Latitude, Longitude = workTemp.Longitude }; var homeTemp = coords.GetAddressCoordinates(new PersonalAddress { StreetName = SplitAddressOnNumber(tempHistory.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(tempHistory.HjemmeAdresse)[1], ZipCode = tempHistory.HjemmePostNr, Town = tempHistory.HjemmeBy, }); var homeAddress = new PersonalAddress() { StreetName = homeTemp.StreetName, StreetNumber = homeTemp.StreetNumber, ZipCode = homeTemp.ZipCode, Town = homeTemp.Town, Latitude = homeTemp.Latitude, Longitude = homeTemp.Longitude, PersonId = empl.PersonId, Type = PersonalAddressType.OldHome, }; workAddressRepo.Insert(workAddress); personalAddressRepo.Insert(homeAddress); workAddressRepo.Save(); personalAddressRepo.Save(); var addressHistory = new Core.DomainModel.AddressHistory { WorkAddressId = workAddress.Id, HomeAddressId = homeAddress.Id, StartTimestamp = tempHistory.AktivFra, EndTimestamp = tempHistory.AktivTil, EmploymentId = empl.Id, IsMigrated = true, }; actualRepo.Insert(addressHistory); } actualRepo.Save(); }
public HashSet <string> GetUncleanableAddresses() { var provider = new DataProvider(); var coords = new AddressCoordinates(); var repo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); Console.WriteLine("Loading histories"); var histories = provider.GetAddressHistoriesAsQueryable(); var i = 0; var max = histories.Count(); foreach (var ah in histories) { i++; Console.WriteLine("Attempting clean of address " + i + " of " + max); var tempHistory = new TempAddressHistory { AktivFra = (Int32)(ah.AktivFra.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, AktivTil = (Int32)(ah.AktivTil.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, ArbejdsAdresse = ah.ArbejdsAdresse, ArbejdsBy = ah.ArbejdsBy, ArbejdsPostNr = ah.ArbejdsPostNr, HjemmeAdresse = ah.HjemmeAdresse, HjemmeBy = ah.HjemmeBy, HjemmeLand = ah.HjemmeLand, HjemmePostNr = ah.HjemmePostNr, MaNr = ah.MaNr, Navn = ah.Navn, HomeIsDirty = false, WorkIsDirty = false, }; var home = new Address(); try { home = new Address { StreetName = SplitAddressOnNumber(ah.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(ah.HjemmeAdresse)[1], ZipCode = ah.HjemmePostNr, Town = ah.HjemmeBy }; coords.GetAddressCoordinates(home); } catch (Exception e) { tempHistory.HomeIsDirty = true; } var work = new Address(); try { work = new Address { StreetName = SplitAddressOnNumber(ah.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(ah.ArbejdsAdresse)[1], ZipCode = ah.ArbejdsPostNr, Town = ah.ArbejdsBy }; coords.GetAddressCoordinates(work); } catch (Exception e) { tempHistory.WorkIsDirty = true; } repo.Insert(tempHistory); } repo.Save(); return(null); }