1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim.
4 # Copyright (C) 2020 Sarah Hoffmann
7 from datetime import datetime
9 log = logging.getLogger()
11 class ProgressLogger(object):
12 """ Tracks and prints progress for the indexing process.
13 `name` is the name of the indexing step being tracked.
14 `total` sets up the total number of items that need processing.
15 `log_interval` denotes the interval in seconds at which progres
19 def __init__(self, name, total, log_interval=1):
21 self.total_places = total
23 self.rank_start_time = datetime.now()
24 self.next_info = 50 if log.isEnabledFor(logging.INFO) else total + 1
27 """ Mark `num` places as processed. Print a log message if the
28 logging is at least info and the log interval has past.
30 self.done_places += num
32 if self.done_places >= self.next_info:
34 done_time = (now - self.rank_start_time).total_seconds()
35 places_per_sec = self.done_places / done_time
36 eta = (self.total_places - self.done_places)/places_per_sec
38 log.info("Done {} in {} @ {:.3f} per second - {} ETA (seconds): {:.2f}"
39 .format(self.done_places, int(done_time),
40 places_per_sec, self.name, eta))
42 self.next_info += int(places_per_sec)
45 """ Print final staticstics about the progress.
47 rank_end_time = datetime.now()
48 diff_seconds = (rank_end_time-self.rank_start_time).total_seconds()
50 log.warning("Done {}/{} in {} @ {:.3f} per second - FINISHED {}\n".format(
51 self.done_places, self.total_places, int(diff_seconds),
52 self.done_places/diff_seconds, self.name))