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

Annotation of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/LookupMain.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2241 - (hide annotations) (download)
Wed Dec 10 09:50:33 2014 UTC (9 years, 5 months ago) by torben
File size: 4721 byte(s)
Move main() to it's own class
1 torben 2241 package dk.daoas.fulddaekning;
2    
3     import java.io.File;
4     import java.io.FileReader;
5     import java.util.List;
6     import java.util.logging.FileHandler;
7     import java.util.logging.Logger;
8     import java.util.logging.SimpleFormatter;
9    
10     public class LookupMain {
11    
12    
13     static final String CONFIG_FILENAME = "fulddaekning.properties";
14    
15     static boolean rename_tables;
16     static SafeProperties conf;
17    
18     static int max_workers;
19     static boolean verbose;
20    
21     static String distributor;
22    
23     final static Logger logger = Logger.getLogger( LookupMain.class.toString() );
24    
25    
26     static Statistik flestDaekkede = new Statistik();
27     static Statistik flestIkkeDaekkede = new Statistik();
28     static Statistik mestBrugteTid = new Statistik();
29     static Statistik stoersteDataset = new Statistik();
30    
31     static Adresse[] alleDaekkedeAdresser;
32    
33    
34     public static void main(String[] args) throws Exception {
35    
36     //Setup j.u.l Logger
37     Logger root = Logger.getLogger("");
38     FileHandler fhandler = new FileHandler("fulddaekning.log"); // Ingen max størrelse, ingen rotation og ingen append
39     fhandler.setFormatter( new SimpleFormatter() );
40     root.addHandler( fhandler );
41    
42    
43    
44    
45     File confFile = new File( CONFIG_FILENAME );
46     if (! confFile.exists() ) {
47     logger.warning("Config file not found: " + CONFIG_FILENAME);
48     System.exit(1);
49     }
50    
51     conf = new SafeProperties();
52     conf.load( new FileReader(confFile) );
53    
54     max_workers = Integer.parseInt( conf.getSafeProperty("MAX_WORKERS") );
55     logger.info("Starting with MAX_WORKERS:" + max_workers);
56    
57     verbose = Boolean.parseBoolean( conf.getSafeProperty("VERBOSE") );
58     logger.info("Starting with VERBOSE:" + verbose);
59    
60     rename_tables = Boolean.parseBoolean( conf.getSafeProperty("RENAMETABLES") );
61     logger.info("Starting with RENAMETABLES:" + rename_tables);
62    
63     distributor = conf.getSafeProperty("DISTRIBUTOR");
64     distributor = distributor.toUpperCase();
65     logger.info("Starting for DISTRIBUTOR:" + distributor);
66    
67     Constants.init(distributor);
68     Constants consts = Constants.getInstance();
69    
70     Database db = new Database(conf);
71    
72    
73    
74    
75     boolean testRun= false;
76    
77    
78     long start = System.currentTimeMillis();
79    
80     if (testRun == false) {
81    
82     logger.info("Finder postnumre");
83     List<String> postnumre = db.hentPostnumre();
84    
85     // Først validerer vi BBox på alle postnummre, for at undgå fuldt stop midt i beregningen
86     for(String postnr : postnumre) { //
87     logger.info("Validerer BBox for " + postnr);
88     BoundingBox bbox = db.getBoundingbox(postnr);
89     bbox.validateBbox();
90     }
91    
92     if (consts.doExtendedLookup()) {
93     logger.info("Henter alle daekkede adresser");
94     alleDaekkedeAdresser = db.hentAlleDaekkedeAdresser();
95     logger.info( "AlleDaekkedeAdresser.length=" + alleDaekkedeAdresser.length);
96     }
97    
98    
99     //pre-check er ok - reset tmp tabel og start søgningen
100     db.resetResultTable();
101    
102     for(String postnr : postnumre) {
103     Lookup lookup = new Lookup(postnr, db);
104     lookup.doLookup();
105     }
106    
107     if (rename_tables) {
108     db.renameResultTables();
109     } else {
110     logger.info( "Rename tables is disabled !!!" );
111     }
112    
113    
114    
115     } else {
116     /// Test
117     db.resetResultTable();
118    
119     if (consts.doExtendedLookup()) {
120     alleDaekkedeAdresser = db.hentAlleDaekkedeAdresser();
121     logger.info( "AlleDaekkedeAdresser.length=" + alleDaekkedeAdresser.length);
122     }
123    
124     Lookup lookup = new Lookup("458x", db);
125     lookup.doLookup();
126     }
127    
128     long now = System.currentTimeMillis();
129     long elapsed = now - start ;
130    
131     logger.info("Mest brugte tid: " + mestBrugteTid);
132     logger.info("Flest Ikke-dækkede, " + flestIkkeDaekkede);
133     logger.info("Flest Dækkede, " + flestDaekkede);
134     logger.info("Største Dataset, " + stoersteDataset);
135     logger.info("Fuld load done : " + formatMilliSeconds(elapsed) );
136     }
137    
138    
139     public static void saveStatistics(Statistik stat) {
140     if (stat.antalDaekkede > flestDaekkede.antalDaekkede) {
141     flestDaekkede = stat;
142     }
143     if (stat.antalIkkeDaekkede > flestIkkeDaekkede.antalIkkeDaekkede) {
144     flestIkkeDaekkede = stat;
145     }
146    
147     if (stat.totalDataset > mestBrugteTid.totalDataset) {
148     stoersteDataset = stat;
149     }
150    
151     if (stat.forbrugtTid > mestBrugteTid.forbrugtTid) {
152     mestBrugteTid = stat;
153     }
154     }
155    
156     static String formatMilliSeconds(long milliseconds) {
157     int mseconds = (int) milliseconds % 1000;
158     int seconds = (int) (milliseconds / 1000) % 60 ;
159     int minutes = (int) ((milliseconds / (1000*60)) % 60);
160     int hours = (int) ((milliseconds / (1000*60*60)) % 24);
161    
162     return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, mseconds);
163     }
164     }

  ViewVC Help
Powered by ViewVC 1.1.20