/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2153 by torben, Wed May 7 16:07:46 2014 UTC revision 2202 by torben, Thu Sep 11 10:35:55 2014 UTC
# Line 14  import java.util.logging.Logger; Line 14  import java.util.logging.Logger;
14  import dk.daoas.fulddaekning.BoundingBox.BoundingBoxException;  import dk.daoas.fulddaekning.BoundingBox.BoundingBoxException;
15    
16  public class Lookup {  public class Lookup {
17    
18            static final String CONFIG_FILENAME = "fulddaekning.properties";
19    
20          static int max_workers;          static int max_workers;
21          static boolean verbose;          static boolean verbose;
22                    
23          static Properties conf;          static boolean rename_tables;
24            static String distributor;
25            
26            static SafeProperties conf;
27          static Logger logger = Logger.getLogger( Lookup.class.toString() );          static Logger logger = Logger.getLogger( Lookup.class.toString() );
28                    
29          int postnr;          int postnr;
# Line 28  public class Lookup { Line 34  public class Lookup {
34                    
35          Map<Integer, LookupWorker> workers = new ConcurrentHashMap<Integer, LookupWorker>();          Map<Integer, LookupWorker> workers = new ConcurrentHashMap<Integer, LookupWorker>();
36    
         static int flestDaekkedeAntal = 0;  
         static int flestDaekkedePostnr;  
37                    
38          static int flestIkkeDaekkedeAntal = 0;          static Statistik flestDaekkede = new Statistik();
39          static int flestIkkeDaekkedePostnr;          static Statistik flestIkkeDaekkede = new Statistik();
40            
41            
42            static class Statistik {
43                    int postnr;
44                    int antalDaekkede = 0;
45                    int antalIkkeDaekkede = 0;
46                    
47                    @Override
48                    public String toString() {
49                            return "postnr=" + postnr + " antalIkkeDaekkede=" + antalIkkeDaekkede + " antalDaekkede="  + antalDaekkede;
50                    }
51            }
52                    
53                    
54          public Lookup(int postnr, Database db) {          public Lookup(int postnr, Database db) {
# Line 40  public class Lookup { Line 56  public class Lookup {
56                  this.db = db;                  this.db = db;
57          }          }
58                    
59                    public static void saveStatistics(Statistik stat) {
60                    if (stat.antalDaekkede > flestDaekkede.antalDaekkede) {
61                            flestDaekkede = stat;
62                    }
63                    if (stat.antalIkkeDaekkede > flestIkkeDaekkede.antalIkkeDaekkede) {
64                            flestIkkeDaekkede = stat;
65                    }              
66            }
67                    
68          public void doLookup() throws BoundingBoxException {          public void doLookup() throws BoundingBoxException {
69                  logger.info("Starting for postnr=" + postnr);                  logger.info("Starting for postnr=" + postnr);
70                                    
71                  int queueSize=-1;                  Statistik stat = new Statistik();
72                                                    
73                  long start1 = System.currentTimeMillis();                                long start1 = System.currentTimeMillis();              
74                  long start2 = 0;                  long start2 = 0;
75                                    
# Line 63  public class Lookup { Line 86  public class Lookup {
86                                                    
87                          logger.info("Henter _ikke_ daekkede adresser i " + postnr);                          logger.info("Henter _ikke_ daekkede adresser i " + postnr);
88                          queue = db.hentIkkedaekkedeAdresser(postnr);                          queue = db.hentIkkedaekkedeAdresser(postnr);
                         queueSize = queue.size();  
                           
                         if (daekkedeAdresser.size() > flestDaekkedeAntal) {  
                                 flestDaekkedeAntal = daekkedeAdresser.size();  
                                 flestDaekkedePostnr = postnr;  
                         }  
89                                                    
90                          if (queueSize > flestIkkeDaekkedeAntal) {                          stat.postnr = postnr;
91                                  flestIkkeDaekkedeAntal = queueSize;                          stat.antalDaekkede = daekkedeAdresser.size();
92                                  flestIkkeDaekkedePostnr = postnr;                          stat.antalIkkeDaekkede = queue.size();
                         }  
93                                                    
94                            saveStatistics(stat);
95                                                    
96                                                    
97                          logger.info("Starter beregning for " + postnr);                          logger.info("Starter beregning for " + postnr);
98                          start2 = System.currentTimeMillis();                          start2 = System.currentTimeMillis();
# Line 103  public class Lookup { Line 121  public class Lookup {
121                  }                  }
122                  long now = System.currentTimeMillis();                  long now = System.currentTimeMillis();
123                                    
124                  logger.info("Antal daekkede:" + daekkedeAdresser.size() + "  postnr=" + postnr);  
125                  logger.info("Antal ikke-daekkede:" + queueSize + "  postnr=" + postnr);                  logger.info( stat.toString() );
                   
126                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);
127          }          }
128                    
# Line 144  public class Lookup { Line 161  public class Lookup {
161                    
162          public static void main(String[] args) throws Exception {          public static void main(String[] args) throws Exception {
163                                    
164                  File confFile = new File("fulddaekning.properties");                  File confFile = new File( CONFIG_FILENAME );
165                  if (! confFile.exists() ) {                  if (! confFile.exists() ) {
166                          logger.warning("Config file not found");                          logger.warning("Config file not found: " + CONFIG_FILENAME);
167                          System.exit(1);                          System.exit(1);
168                  }                  }
169                                                                    
170                  conf = new Properties();                  conf = new SafeProperties();
171                  conf.load( new FileReader(confFile) );                  conf.load( new FileReader(confFile) );
172                                    
173                  max_workers = Integer.parseInt( conf.getProperty("MAX_WORKERS") );                  max_workers = Integer.parseInt( conf.getSafeProperty("MAX_WORKERS") );
174                  logger.info("Starting with MAX_WORKERS:" + max_workers);                  logger.info("Starting with MAX_WORKERS:" + max_workers);
175                                    
176                  verbose = Boolean.parseBoolean( conf.getProperty("VERBOSE") );                  verbose = Boolean.parseBoolean( conf.getSafeProperty("VERBOSE") );
177                  logger.info("Starting with VERBOSE:" + verbose);                  logger.info("Starting with VERBOSE:" + verbose);
178                                    
179                    rename_tables = Boolean.parseBoolean( conf.getSafeProperty("RENAMETABLES") );
180                    logger.info("Starting with RENAMETABLES:" + rename_tables);
181                    
182                    distributor = conf.getSafeProperty("DISTRIBUTOR");
183                    distributor = distributor.toUpperCase();
184                    Constants.init(distributor);
185    
186                    
187                  Database db = new Database(conf);                  Database db = new Database(conf);
188                                    
189                  db.resetResultTable();                  
190    
191                                    
192                                    
# Line 172  public class Lookup { Line 197  public class Lookup {
197                  logger.info("Finder postnumre");                  logger.info("Finder postnumre");
198                  List<Integer> postnumre = db.hentPostnumre();                  List<Integer> postnumre = db.hentPostnumre();
199                                    
200                    // Først validerer vi BBox på alle postnummre, for at undgå fuldt stop midt i beregningen
201                    for(Integer postnr : postnumre) { //
202                            logger.info("Validerer BBox for " + postnr);
203                            BoundingBox bbox = db.getBoundingbox(postnr);
204                            bbox.validateBbox();
205                    }
206                    
207                    
208                    //pre-check er ok - reset tmp tabel og start søgningen
209                    db.resetResultTable();
210                    
211                  for(Integer postnr : postnumre) {                  for(Integer postnr : postnumre) {
212                          Lookup lookup = new Lookup(postnr, db);                          Lookup lookup = new Lookup(postnr, db);
213                          lookup.doLookup();                                                lookup.doLookup();                      
214                  }                  }
215                                    
216                    if (rename_tables) {
217                            db.renameResultTables();
218                    } else {
219                            logger.info( "Rename tables is disabled !!!" );
220                    }
221                    
222                  long now = System.currentTimeMillis();                  long now = System.currentTimeMillis();
223                                    
224                    logger.info("Flest Ikke-dækkede, " + flestIkkeDaekkede);
225                    logger.info("Flest Dækkede, " + flestDaekkede);
226                  logger.info("Fuld load done : " + (now-start) );                  logger.info("Fuld load done : " + (now-start) );
227                  logger.info("Flest Ikke-dækkede, " + flestIkkeDaekkedePostnr + ": " + flestIkkeDaekkedeAntal);  
                 logger.info("Flest Dækkede, " + flestDaekkedePostnr + ": " + flestDaekkedeAntal);  
228                                    
229                                    
230                  //Lookup lookup = new Lookup(7400, db);                  //Lookup lookup = new Lookup(7400, db);

Legend:
Removed from v.2153  
changed lines
  Added in v.2202

  ViewVC Help
Powered by ViewVC 1.1.20