--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java 2014/05/07 07:39:26 2150 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java 2014/09/11 10:35:55 2202 @@ -2,10 +2,6 @@ import java.io.File; import java.io.FileReader; -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -18,10 +14,16 @@ import dk.daoas.fulddaekning.BoundingBox.BoundingBoxException; public class Lookup { + + static final String CONFIG_FILENAME = "fulddaekning.properties"; + static int max_workers; static boolean verbose; - static Properties conf; + static boolean rename_tables; + static String distributor; + + static SafeProperties conf; static Logger logger = Logger.getLogger( Lookup.class.toString() ); int postnr; @@ -33,19 +35,41 @@ Map workers = new ConcurrentHashMap(); + static Statistik flestDaekkede = new Statistik(); + static Statistik flestIkkeDaekkede = new Statistik(); + + + static class Statistik { + int postnr; + int antalDaekkede = 0; + int antalIkkeDaekkede = 0; + + @Override + public String toString() { + return "postnr=" + postnr + " antalIkkeDaekkede=" + antalIkkeDaekkede + " antalDaekkede=" + antalDaekkede; + } + } + public Lookup(int postnr, Database db) { this.postnr = postnr; this.db = db; } - + public static void saveStatistics(Statistik stat) { + if (stat.antalDaekkede > flestDaekkede.antalDaekkede) { + flestDaekkede = stat; + } + if (stat.antalIkkeDaekkede > flestIkkeDaekkede.antalIkkeDaekkede) { + flestIkkeDaekkede = stat; + } + } public void doLookup() throws BoundingBoxException { logger.info("Starting for postnr=" + postnr); - int queueSize=-1; - + Statistik stat = new Statistik(); + long start1 = System.currentTimeMillis(); long start2 = 0; @@ -62,8 +86,13 @@ logger.info("Henter _ikke_ daekkede adresser i " + postnr); queue = db.hentIkkedaekkedeAdresser(postnr); - queueSize = queue.size(); + stat.postnr = postnr; + stat.antalDaekkede = daekkedeAdresser.size(); + stat.antalIkkeDaekkede = queue.size(); + + saveStatistics(stat); + logger.info("Starter beregning for " + postnr); start2 = System.currentTimeMillis(); @@ -92,10 +121,9 @@ } long now = System.currentTimeMillis(); - logger.info("Antal daekkede:" + daekkedeAdresser.size() ); - logger.info("Antal ikke-daekkede:" + queueSize ); - - logger.info("Done! elapsed=" + (now-start1) + "/" + (now-start2) ); + + logger.info( stat.toString() ); + logger.info("Done! elapsed=" + (now-start1) + "/" + (now-start2) + " postnr=" + postnr); } public void shutdownWorker(int workerid) { @@ -133,23 +161,32 @@ public static void main(String[] args) throws Exception { - File confFile = new File("fulddaekning.properties"); + File confFile = new File( CONFIG_FILENAME ); if (! confFile.exists() ) { - logger.warning("Config file not found"); + logger.warning("Config file not found: " + CONFIG_FILENAME); System.exit(1); } - conf = new Properties(); + conf = new SafeProperties(); conf.load( new FileReader(confFile) ); - max_workers = Integer.parseInt( conf.getProperty("MAX_WORKERS") ); + max_workers = Integer.parseInt( conf.getSafeProperty("MAX_WORKERS") ); logger.info("Starting with MAX_WORKERS:" + max_workers); - verbose = Boolean.parseBoolean( conf.getProperty("VERBOSE") ); + verbose = Boolean.parseBoolean( conf.getSafeProperty("VERBOSE") ); logger.info("Starting with VERBOSE:" + verbose); - Connection conn = getConnection(); - Database db = new Database(conn); + rename_tables = Boolean.parseBoolean( conf.getSafeProperty("RENAMETABLES") ); + logger.info("Starting with RENAMETABLES:" + rename_tables); + + distributor = conf.getSafeProperty("DISTRIBUTOR"); + distributor = distributor.toUpperCase(); + Constants.init(distributor); + + + Database db = new Database(conf); + + @@ -160,41 +197,38 @@ logger.info("Finder postnumre"); List postnumre = db.hentPostnumre(); + // Først validerer vi BBox på alle postnummre, for at undgå fuldt stop midt i beregningen + for(Integer postnr : postnumre) { // + logger.info("Validerer BBox for " + postnr); + BoundingBox bbox = db.getBoundingbox(postnr); + bbox.validateBbox(); + } + + + //pre-check er ok - reset tmp tabel og start søgningen + db.resetResultTable(); + for(Integer postnr : postnumre) { Lookup lookup = new Lookup(postnr, db); lookup.doLookup(); } - long now = System.currentTimeMillis(); + if (rename_tables) { + db.renameResultTables(); + } else { + logger.info( "Rename tables is disabled !!!" ); + } + long now = System.currentTimeMillis(); + + logger.info("Flest Ikke-dækkede, " + flestIkkeDaekkede); + logger.info("Flest Dækkede, " + flestDaekkede); logger.info("Fuld load done : " + (now-start) ); + //Lookup lookup = new Lookup(7400, db); //lookup.doLookup(); } - - public static Connection getConnection() throws SQLException, IOException { - - String db_host = conf.getProperty("DB_HOST"); - String db_user = conf.getProperty("DB_USER"); - String db_pass = conf.getProperty("DB_PASS"); - - - - Connection conn = null; - Properties connectionProps = new Properties(); - connectionProps.put("user", db_user); - connectionProps.put("password", db_pass); - - conn = DriverManager.getConnection( - "jdbc:mysql://" + - db_host + - ":3306/", - connectionProps); - logger.info("Connected to database"); - return conn; - } - }