1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim.
4 # Copyright (C) 2020 Sarah Hoffmann
6 Helpers for progress logging.
9 from datetime import datetime
11 LOG = logging.getLogger()
16 """ Tracks and prints progress for the indexing process.
17 `name` is the name of the indexing step being tracked.
18 `total` sets up the total number of items that need processing.
19 `log_interval` denotes the interval in seconds at which progres
23 def __init__(self, name, total, log_interval=1):
25 self.total_places = total
27 self.rank_start_time = datetime.now()
28 self.log_interval = log_interval
29 self.next_info = INITIAL_PROGRESS if LOG.isEnabledFor(logging.WARNING) else total + 1
32 """ Mark `num` places as processed. Print a log message if the
33 logging is at least info and the log interval has passed.
35 self.done_places += num
37 if self.done_places < self.next_info:
41 done_time = (now - self.rank_start_time).total_seconds()
44 self.next_info = self.done_places + INITIAL_PROGRESS
47 places_per_sec = self.done_places / done_time
48 eta = (self.total_places - self.done_places) / places_per_sec
50 LOG.warning("Done %d in %d @ %.3f per second - %s ETA (seconds): %.2f",
51 self.done_places, int(done_time),
52 places_per_sec, self.name, eta)
54 self.next_info += int(places_per_sec) * self.log_interval
57 """ Print final statistics about the progress.
59 rank_end_time = datetime.now()
60 diff_seconds = (rank_end_time-self.rank_start_time).total_seconds()
62 LOG.warning("Done %d/%d in %d @ %.3f per second - FINISHED %s\n",
63 self.done_places, self.total_places, int(diff_seconds),
64 self.done_places/diff_seconds, self.name)