]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/indexer/progress.py
avoid division by zero in progress meter
[nominatim.git] / nominatim / indexer / progress.py
index 99120673faa67680216ac5fc48d6c8f93da62d03..177e67b812aef0ea05116928c214ed5434f5a622 100644 (file)
@@ -26,7 +26,7 @@ class ProgressLogger:
         self.done_places = 0
         self.rank_start_time = datetime.now()
         self.log_interval = log_interval
-        self.next_info = INITIAL_PROGRESS if LOG.isEnabledFor(logging.INFO) else total + 1
+        self.next_info = INITIAL_PROGRESS if LOG.isEnabledFor(logging.WARNING) else total + 1
 
     def add(self, num=1):
         """ Mark `num` places as processed. Print a log message if the
@@ -47,9 +47,9 @@ class ProgressLogger:
         places_per_sec = self.done_places / done_time
         eta = (self.total_places - self.done_places) / places_per_sec
 
-        LOG.info("Done %d in %d @ %.3f per second - %s ETA (seconds): %.2f",
-                 self.done_places, int(done_time),
-                 places_per_sec, self.name, eta)
+        LOG.warning("Done %d in %d @ %.3f per second - %s ETA (seconds): %.2f",
+                    self.done_places, int(done_time),
+                    places_per_sec, self.name, eta)
 
         self.next_info += int(places_per_sec) * self.log_interval
 
@@ -57,8 +57,14 @@ class ProgressLogger:
         """ Print final statistics about the progress.
         """
         rank_end_time = datetime.now()
-        diff_seconds = (rank_end_time-self.rank_start_time).total_seconds()
+
+        if rank_end_time == self.rank_start_time:
+            diff_seconds = 0
+            places_per_sec = self.done_places
+        else:
+            diff_seconds = (rank_end_time - self.rank_start_time).total_seconds()
+            places_per_sec = self.done_places/diff_seconds
 
         LOG.warning("Done %d/%d in %d @ %.3f per second - FINISHED %s\n",
                     self.done_places, self.total_places, int(diff_seconds),
-                    self.done_places/diff_seconds, self.name)
+                    places_per_sec, self.name)