]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tools/special_phrases/importer_statistics.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / tools / special_phrases / importer_statistics.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8     Contains the class which handles statistics for the
9     import of special phrases.
10 """
11 import logging
12 LOG = logging.getLogger()
13
14 class SpecialPhrasesImporterStatistics():
15     """
16         Class handling statistics of the import
17         process of special phrases.
18     """
19     def __init__(self) -> None:
20         self._intialize_values()
21
22     def _intialize_values(self) -> None:
23         """
24             Set all counts for the global
25             import to 0.
26         """
27         self.tables_created = 0
28         self.tables_deleted = 0
29         self.tables_ignored = 0
30         self.invalids = 0
31
32     def notify_one_phrase_invalid(self) -> None:
33         """
34             Add +1 to the count of invalid entries
35             fetched from the wiki.
36         """
37         self.invalids += 1
38
39     def notify_one_table_created(self) -> None:
40         """
41             Add +1 to the count of created tables.
42         """
43         self.tables_created += 1
44
45     def notify_one_table_deleted(self) -> None:
46         """
47             Add +1 to the count of deleted tables.
48         """
49         self.tables_deleted += 1
50
51     def notify_one_table_ignored(self) -> None:
52         """
53             Add +1 to the count of ignored tables.
54         """
55         self.tables_ignored += 1
56
57     def notify_import_done(self) -> None:
58         """
59             Print stats for the whole import process
60             and reset all values.
61         """
62         LOG.info('====================================================================')
63         LOG.info('Final statistics of the import:')
64         LOG.info('- %s phrases were invalid.', self.invalids)
65         if self.invalids > 0:
66             LOG.info('  Those invalid phrases have been skipped.')
67         LOG.info('- %s tables were ignored as they already exist on the database',
68                  self.tables_ignored)
69         LOG.info('- %s tables were created', self.tables_created)
70         LOG.info('- %s tables were deleted from the database', self.tables_deleted)
71         if self.tables_deleted > 0:
72             LOG.info('  They were deleted as they are not valid anymore.')
73
74         if self.invalids > 0:
75             LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
76                         self.invalids)
77
78         self._intialize_values()