2 Contains the class which handles statistics for the
3 import of special phrases.
6 LOG = logging.getLogger()
8 class SpecialPhrasesImporterStatistics():
9 # pylint: disable-msg=too-many-instance-attributes
11 Class handling statistics of the import
12 process of special phrases.
15 self._set_lang_values_to_0()
16 self._set_global_values_to_0()
18 def _set_global_values_to_0(self):
20 Set all counts for the global
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
31 def _set_lang_values_to_0(self):
33 Set all counts for the current
36 self.lang_phrases_invalid = 0
37 self.lang_phrases_added = 0
38 self.lang_phrases_ignored = 0
40 def notify_one_phrase_invalid(self):
42 Add +1 to the count of invalid entries
43 fetched from the wiki.
45 self.lang_phrases_invalid += 1
46 self.global_phrases_invalid += 1
48 def notify_one_phrase_added(self):
50 Add +1 to the count of entries
53 self.lang_phrases_added += 1
54 self.global_phrases_added += 1
56 def notify_one_phrase_ignored(self):
58 Add +1 to the count of ignored
59 entries as it was already in the db.
61 self.lang_phrases_ignored += 1
62 self.global_phrases_ignored += 1
64 def notify_one_phrase_deleted(self):
66 Add +1 to the count of phrases deleted
69 self.global_phrases_deleted += 1
71 def notify_one_table_created(self):
73 Add +1 to the count of created tables.
75 self.tables_created += 1
77 def notify_one_table_deleted(self):
79 Add +1 to the count of deleted tables.
81 self.tables_deleted += 1
83 def notify_one_table_ignored(self):
85 Add +1 to the count of ignored tables.
87 self.tables_ignored += 1
90 def notify_import_done(self):
92 Print stats for the whole import process
95 LOG.info('====================================================================')
96 LOG.info('Final statistics of the import:')
97 LOG.info('- %s phrases were invalid.', self.global_phrases_invalid)
98 if self.global_phrases_invalid > 0:
99 LOG.info(' Those invalid phrases have been skipped.')
100 LOG.info('- %s phrases were ignored as they are already in the database',
101 self.global_phrases_ignored)
102 LOG.info('- %s phrases were added to the database', self.global_phrases_added)
103 LOG.info('- %s phrases were deleted from the database', self.global_phrases_deleted)
104 if self.global_phrases_deleted > 0:
105 LOG.info(' They were deleted as they are not valid anymore.')
106 LOG.info('- %s tables were ignored as they already exist on the database',
108 LOG.info('- %s tables were created', self.tables_created)
109 LOG.info('- %s tables were deleted from the database', self.tables_deleted)
110 if self.tables_deleted > 0:
111 LOG.info(' They were deleted as they are not valid anymore.')
113 if self.global_phrases_invalid > 0:
114 LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
115 self.global_phrases_invalid)
117 self._set_global_values_to_0()
119 def notify_current_lang_done(self, lang):
121 Print stats for the current lang
122 and then reset lang values.
124 LOG.info('====================================================================')
125 LOG.info('Statistics for the import of %s:', lang)
126 LOG.info('- %s phrases were invalid.', self.lang_phrases_invalid)
127 if self.lang_phrases_invalid > 0:
128 LOG.info(' Those invalid phrases have been skipped.')
129 LOG.info('- %s phrases were ignored as they are already in the database',
130 self.lang_phrases_ignored)
131 LOG.info('- %s phrases were added to the database', self.lang_phrases_added)
132 LOG.info('====================================================================')
134 if self.lang_phrases_invalid > 0:
135 LOG.warning('%s phrases were invalid and have been skipped for the import of lang %s.',
136 self.lang_phrases_invalid, lang)
138 self._set_lang_values_to_0()