1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2024 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8     Contains the class which handles statistics for the
 
   9     import of special phrases.
 
  12 LOG = logging.getLogger()
 
  14 class SpecialPhrasesImporterStatistics():
 
  16         Class handling statistics of the import
 
  17         process of special phrases.
 
  19     def __init__(self) -> None:
 
  20         self._intialize_values()
 
  22     def _intialize_values(self) -> None:
 
  24             Set all counts for the global
 
  27         self.tables_created = 0
 
  28         self.tables_deleted = 0
 
  29         self.tables_ignored = 0
 
  32     def notify_one_phrase_invalid(self) -> None:
 
  34             Add +1 to the count of invalid entries
 
  35             fetched from the wiki.
 
  39     def notify_one_table_created(self) -> None:
 
  41             Add +1 to the count of created tables.
 
  43         self.tables_created += 1
 
  45     def notify_one_table_deleted(self) -> None:
 
  47             Add +1 to the count of deleted tables.
 
  49         self.tables_deleted += 1
 
  51     def notify_one_table_ignored(self) -> None:
 
  53             Add +1 to the count of ignored tables.
 
  55         self.tables_ignored += 1
 
  57     def notify_import_done(self) -> None:
 
  59             Print stats for the whole import process
 
  62         LOG.info('====================================================================')
 
  63         LOG.info('Final statistics of the import:')
 
  64         LOG.info('- %s phrases were invalid.', self.invalids)
 
  66             LOG.info('  Those invalid phrases have been skipped.')
 
  67         LOG.info('- %s tables were ignored as they already exist on the database',
 
  69         LOG.info('- %s tables were created', self.tables_created)
 
  70         LOG.info('- %s tables were deleted from the database', self.tables_deleted)
 
  71         if self.tables_deleted > 0:
 
  72             LOG.info('  They were deleted as they are not valid anymore.')
 
  75             LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
 
  78         self._intialize_values()