]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tools/special_phrases/importer_statistics.py
520c77d66592347b1a92e950ee5f09e7cdc167ed
[nominatim.git] / nominatim / tools / special_phrases / importer_statistics.py
1 """
2     Contain the class which handle 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         self.global_phrases_added = 0
28         self.global_phrases_ignored = 0
29         self.global_phrases_deleted = 0
30
31     def _set_lang_values_to_0(self):
32         """
33             Set all counts for the current
34             lang to 0.
35         """
36         self.lang_phrases_invalid = 0
37         self.lang_phrases_added = 0
38         self.lang_phrases_ignored = 0
39
40     def notify_one_phrase_invalid(self):
41         """
42             Add +1 to the count of invalid entries
43             fetched from the wiki.
44         """
45         self.lang_phrases_invalid += 1
46         self.global_phrases_invalid += 1
47
48     def notify_one_phrase_added(self):
49         """
50             Add +1 to the count of entries
51             added to the db.
52         """
53         self.lang_phrases_added += 1
54         self.global_phrases_added += 1
55
56     def notify_one_phrase_ignored(self):
57         """
58             Add +1 to the count of ignored
59             entries as it was already in the db.
60         """
61         self.lang_phrases_ignored += 1
62         self.global_phrases_ignored += 1
63
64     def notify_one_phrase_deleted(self):
65         """
66             Add +1 to the count of phrases deleted
67             from the database.
68         """
69         self.global_phrases_deleted += 1
70
71     def notify_one_table_created(self):
72         """
73             Add +1 to the count of created tables.
74         """
75         self.tables_created += 1
76
77     def notify_one_table_deleted(self):
78         """
79             Add +1 to the count of deleted tables.
80         """
81         self.tables_deleted += 1
82
83     def notify_one_table_ignored(self):
84         """
85             Add +1 to the count of ignored tables.
86         """
87         self.tables_ignored += 1
88
89
90     def notify_import_done(self):
91         """
92             Print stats for the whole import process
93             and reset all values.
94         """
95         LOG.warning('====================================================================')
96         LOG.warning('Final statistics of the import:')
97         LOG.warning('- %s phrases were invalid.', self.global_phrases_invalid)
98         if self.global_phrases_invalid > 0:
99             LOG.warning('  Those invalid phrases have been skipped.')
100         LOG.warning('- %s phrases were ignored as they are already in the database',
101                     self.global_phrases_ignored)
102         LOG.warning('- %s phrases were added to the database', self.global_phrases_added)
103         LOG.warning('- %s phrases were deleted from the database', self.global_phrases_deleted)
104         if self.global_phrases_deleted > 0:
105             LOG.warning('  They were deleted as they are not valid anymore.')
106         LOG.warning('- %s tables were ignored as they already exist on the database',
107                     self.tables_ignored)
108         LOG.warning('- %s tables were created', self.tables_created)
109         LOG.warning('- %s tables were deleted from the database', self.tables_deleted)
110         if self.tables_deleted > 0:
111             LOG.warning('  They were deleted as they are not valid anymore.')
112
113         self._set_global_values_to_0()
114
115     def notify_current_lang_done(self, lang):
116         """
117             Print stats for the current lang
118             and then reset lang values.
119         """
120         LOG.warning('====================================================================')
121         LOG.warning('Statistics for the import of %s:', lang)
122         LOG.warning('- %s phrases were invalid.', self.lang_phrases_invalid)
123         if self.lang_phrases_invalid > 0:
124             LOG.warning('  Those invalid phrases have been skipped.')
125         LOG.warning('- %s phrases were ignored as they are already in the database',
126                     self.lang_phrases_ignored)
127         LOG.warning('- %s phrases were added to the database', self.lang_phrases_added)
128         LOG.warning('====================================================================')
129
130         self._set_lang_values_to_0()