]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tools/special_phrases/importer_statistics.py
more formatting fixes
[nominatim.git] / nominatim / tools / special_phrases / importer_statistics.py
1 """
2     Contains the class which handles statistics for the
3     import of special phrases.
4 """
5 import logging
6 LOG = logging.getLogger()
7
8 class SpecialPhrasesImporterStatistics():
9     # pylint: disable-msg=too-many-instance-attributes
10     """
11         Class handling statistics of the import
12         process of special phrases.
13     """
14     def __init__(self):
15         self._intialize_values()
16
17     def _intialize_values(self):
18         """
19             Set all counts for the global
20             import to 0.
21         """
22         self.tables_created = 0
23         self.tables_deleted = 0
24         self.tables_ignored = 0
25         self.invalids = 0
26
27     def notify_one_phrase_invalid(self):
28         """
29             Add +1 to the count of invalid entries
30             fetched from the wiki.
31         """
32         self.invalids += 1
33
34     def notify_one_table_created(self):
35         """
36             Add +1 to the count of created tables.
37         """
38         self.tables_created += 1
39
40     def notify_one_table_deleted(self):
41         """
42             Add +1 to the count of deleted tables.
43         """
44         self.tables_deleted += 1
45
46     def notify_one_table_ignored(self):
47         """
48             Add +1 to the count of ignored tables.
49         """
50         self.tables_ignored += 1
51
52     def notify_import_done(self):
53         """
54             Print stats for the whole import process
55             and reset all values.
56         """
57         LOG.info('====================================================================')
58         LOG.info('Final statistics of the import:')
59         LOG.info('- %s phrases were invalid.', self.invalids)
60         if self.invalids > 0:
61             LOG.info('  Those invalid phrases have been skipped.')
62         LOG.info('- %s tables were ignored as they already exist on the database',
63                  self.tables_ignored)
64         LOG.info('- %s tables were created', self.tables_created)
65         LOG.info('- %s tables were deleted from the database', self.tables_deleted)
66         if self.tables_deleted > 0:
67             LOG.info('  They were deleted as they are not valid anymore.')
68
69         if self.invalids > 0:
70             LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
71                         self.invalids)
72
73         self._intialize_values()