X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/abb3d56b2053beb8b582c6ed7f5a3b918b4fae08..d9639a98671786f74b2be7588f4af2405ea08a68:/nominatim/tools/special_phrases/importer_statistics.py diff --git a/nominatim/tools/special_phrases/importer_statistics.py b/nominatim/tools/special_phrases/importer_statistics.py index 46965c4b..0bb118c8 100644 --- a/nominatim/tools/special_phrases/importer_statistics.py +++ b/nominatim/tools/special_phrases/importer_statistics.py @@ -1,3 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ Contains the class which handles statistics for the import of special phrases. @@ -6,16 +12,14 @@ import logging LOG = logging.getLogger() class SpecialPhrasesImporterStatistics(): - # pylint: disable-msg=too-many-instance-attributes """ Class handling statistics of the import process of special phrases. """ - def __init__(self): - self._set_lang_values_to_0() - self._set_global_values_to_0() + def __init__(self) -> None: + self._intialize_values() - def _set_global_values_to_0(self): + def _intialize_values(self) -> None: """ Set all counts for the global import to 0. @@ -23,86 +27,43 @@ class SpecialPhrasesImporterStatistics(): self.tables_created = 0 self.tables_deleted = 0 self.tables_ignored = 0 - self.global_phrases_invalid = 0 - self.global_phrases_added = 0 - self.global_phrases_ignored = 0 - self.global_phrases_deleted = 0 + self.invalids = 0 - def _set_lang_values_to_0(self): - """ - Set all counts for the current - lang to 0. - """ - self.lang_phrases_invalid = 0 - self.lang_phrases_added = 0 - self.lang_phrases_ignored = 0 - - def notify_one_phrase_invalid(self): + def notify_one_phrase_invalid(self) -> None: """ Add +1 to the count of invalid entries fetched from the wiki. """ - self.lang_phrases_invalid += 1 - self.global_phrases_invalid += 1 - - def notify_one_phrase_added(self): - """ - Add +1 to the count of entries - added to the db. - """ - self.lang_phrases_added += 1 - self.global_phrases_added += 1 - - def notify_one_phrase_ignored(self): - """ - Add +1 to the count of ignored - entries as it was already in the db. - """ - self.lang_phrases_ignored += 1 - self.global_phrases_ignored += 1 - - def notify_one_phrase_deleted(self): - """ - Add +1 to the count of phrases deleted - from the database. - """ - self.global_phrases_deleted += 1 + self.invalids += 1 - def notify_one_table_created(self): + def notify_one_table_created(self) -> None: """ Add +1 to the count of created tables. """ self.tables_created += 1 - def notify_one_table_deleted(self): + def notify_one_table_deleted(self) -> None: """ Add +1 to the count of deleted tables. """ self.tables_deleted += 1 - def notify_one_table_ignored(self): + def notify_one_table_ignored(self) -> None: """ Add +1 to the count of ignored tables. """ self.tables_ignored += 1 - - def notify_import_done(self): + def notify_import_done(self) -> None: """ Print stats for the whole import process and reset all values. """ LOG.info('====================================================================') LOG.info('Final statistics of the import:') - LOG.info('- %s phrases were invalid.', self.global_phrases_invalid) - if self.global_phrases_invalid > 0: + LOG.info('- %s phrases were invalid.', self.invalids) + if self.invalids > 0: LOG.info(' Those invalid phrases have been skipped.') - LOG.info('- %s phrases were ignored as they are already in the database', - self.global_phrases_ignored) - LOG.info('- %s phrases were added to the database', self.global_phrases_added) - LOG.info('- %s phrases were deleted from the database', self.global_phrases_deleted) - if self.global_phrases_deleted > 0: - LOG.info(' They were deleted as they are not valid anymore.') LOG.info('- %s tables were ignored as they already exist on the database', self.tables_ignored) LOG.info('- %s tables were created', self.tables_created) @@ -110,29 +71,8 @@ class SpecialPhrasesImporterStatistics(): if self.tables_deleted > 0: LOG.info(' They were deleted as they are not valid anymore.') - if self.global_phrases_invalid > 0: + if self.invalids > 0: LOG.warning('%s phrases were invalid and have been skipped during the whole process.', - self.global_phrases_invalid) - - self._set_global_values_to_0() - - def notify_current_lang_done(self, lang): - """ - Print stats for the current lang - and then reset lang values. - """ - LOG.info('====================================================================') - LOG.info('Statistics for the import of %s:', lang) - LOG.info('- %s phrases were invalid.', self.lang_phrases_invalid) - if self.lang_phrases_invalid > 0: - LOG.info(' Those invalid phrases have been skipped.') - LOG.info('- %s phrases were ignored as they are already in the database', - self.lang_phrases_ignored) - LOG.info('- %s phrases were added to the database', self.lang_phrases_added) - LOG.info('====================================================================') - - if self.lang_phrases_invalid > 0: - LOG.warning('%s phrases were invalid and have been skipped for the import of lang %s.', - self.lang_phrases_invalid, lang) + self.invalids) - self._set_lang_values_to_0() + self._intialize_values()