]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tools/special_phrases/importer_statistics.py
Merge pull request #2305 from lonvia/tokenizer
[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._set_lang_values_to_0()
16         self._set_global_values_to_0()
17
18     def _set_global_values_to_0(self):
19         """
20             Set all counts for the global
21             import to 0.
22         """
23         self.tables_created = 0
24         self.tables_deleted = 0
25         self.tables_ignored = 0
26         self.global_phrases_invalid = 0
27
28     def _set_lang_values_to_0(self):
29         """
30             Set all counts for the current
31             lang to 0.
32         """
33         self.lang_phrases_invalid = 0
34
35     def notify_one_phrase_invalid(self):
36         """
37             Add +1 to the count of invalid entries
38             fetched from the wiki.
39         """
40         self.lang_phrases_invalid += 1
41         self.global_phrases_invalid += 1
42
43     def notify_one_table_created(self):
44         """
45             Add +1 to the count of created tables.
46         """
47         self.tables_created += 1
48
49     def notify_one_table_deleted(self):
50         """
51             Add +1 to the count of deleted tables.
52         """
53         self.tables_deleted += 1
54
55     def notify_one_table_ignored(self):
56         """
57             Add +1 to the count of ignored tables.
58         """
59         self.tables_ignored += 1
60
61
62     def notify_import_done(self):
63         """
64             Print stats for the whole import process
65             and reset all values.
66         """
67         LOG.info('====================================================================')
68         LOG.info('Final statistics of the import:')
69         LOG.info('- %s phrases were invalid.', self.global_phrases_invalid)
70         if self.global_phrases_invalid > 0:
71             LOG.info('  Those invalid phrases have been skipped.')
72         LOG.info('- %s tables were ignored as they already exist on the database',
73                  self.tables_ignored)
74         LOG.info('- %s tables were created', self.tables_created)
75         LOG.info('- %s tables were deleted from the database', self.tables_deleted)
76         if self.tables_deleted > 0:
77             LOG.info('  They were deleted as they are not valid anymore.')
78
79         if self.global_phrases_invalid > 0:
80             LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
81                         self.global_phrases_invalid)
82
83         self._set_global_values_to_0()
84
85     def notify_current_lang_done(self, lang):
86         """
87             Print stats for the current lang
88             and then reset lang values.
89         """
90         LOG.info('====================================================================')
91         LOG.info('Statistics for the import of %s:', lang)
92         LOG.info('- %s phrases were invalid.', self.lang_phrases_invalid)
93         if self.lang_phrases_invalid > 0:
94             LOG.info('  Those invalid phrases have been skipped.')
95         LOG.info('====================================================================')
96
97         if self.lang_phrases_invalid > 0:
98             LOG.warning('%s phrases were invalid and have been skipped for the import of lang %s.',
99                         self.lang_phrases_invalid, lang)
100
101         self._set_lang_values_to_0()