package dk.daoas.naermestepshop; import geocode.GeoPoint; import geocode.kdtree.KDTree; import java.io.File; import java.io.FileReader; import java.util.List; import java.util.Properties; import java.util.logging.Logger; public class PshopMain { static Logger logger = Logger.getLogger(PshopMain.class.getName()); static final String CONFIG_FILENAME = "naermestepshop.properties"; public static void main(String[] args) throws Exception { File confFile = new File( CONFIG_FILENAME ); if (! confFile.exists() ) { logger.warning("Config file not found: " + CONFIG_FILENAME); System.exit(1); } Properties props = new Properties(); props.load( new FileReader(confFile) ); Database db = new Database(props); List dao = (List) db.getShops("DAO"); List swip = (List) db.getShops("SWIP"); List gls = (List) db.getShops("GLS"); KDTree daoTree = new KDTree(dao); KDTree swipTree = new KDTree(swip); KDTree glsTree = new KDTree(gls); logger.info("Start fetching addr"); List adresser = db.getAdresser(); db.resetResultTable();//Nulstil resultat tabellen inden vi starter beregningen logger.info("Start calculating"); for (Adresse addr : adresser) { ShopResult daoResult = new ShopResult(); daoResult.shop = (Shop) daoTree.findNearest(addr); daoResult.distance = GeoPointHelper.beregnAfstand(addr, daoResult.shop); ShopResult swipResult = new ShopResult(); swipResult.shop = (Shop) swipTree.findNearest(addr); swipResult.distance = GeoPointHelper.beregnAfstand(addr, swipResult.shop); ShopResult glsResult = new ShopResult(); glsResult.shop = (Shop) glsTree.findNearest(addr); glsResult.distance = GeoPointHelper.beregnAfstand(addr, glsResult.shop); if ( Double.isNaN(daoResult.distance) || Double.isNaN(swipResult.distance) || Double.isNaN(glsResult.distance)) { System.out.println("Addr " + addr); System.out.println("DAO " + daoResult); System.out.println("Swip " + swipResult); System.out.println("GLS " + glsResult); } db.gemResultat(addr, daoResult, swipResult, glsResult); } db.saveBatch(); logger.info("done"); } /* @Deprecated public static GeoPoint bruteforceSearch(GeoPoint needle, List haystack) { GeoPoint nearest = null; double bestDistance = 999999.999; for (GeoPoint current : haystack) { double distance = GeoPointHelper.beregnAfstand(current, needle); if (distance < bestDistance) { nearest = current; bestDistance = distance; } } return nearest; } /*Shop nearest2 = (Shop) bruteforceSearch(addr, dao); if (nearest1.ktonr != nearest2.ktonr) { System.out.println("Mistmatch " + addr + " " + nearest1 + " / " + nearest2); } GeoPoint reference = new GeoPoint(55.8727, 9.88129); final int MAX = 10000; TimingHelper t1 = new TimingHelper(); for (int i = 0; i