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()
 
  15 class SpecialPhrasesImporterStatistics():
 
  17         Class handling statistics of the import
 
  18         process of special phrases.
 
  20     def __init__(self) -> None:
 
  21         self._intialize_values()
 
  23     def _intialize_values(self) -> None:
 
  25             Set all counts for the global
 
  28         self.tables_created = 0
 
  29         self.tables_deleted = 0
 
  30         self.tables_ignored = 0
 
  33     def notify_one_phrase_invalid(self) -> None:
 
  35             Add +1 to the count of invalid entries
 
  36             fetched from the wiki.
 
  40     def notify_one_table_created(self) -> None:
 
  42             Add +1 to the count of created tables.
 
  44         self.tables_created += 1
 
  46     def notify_one_table_deleted(self) -> None:
 
  48             Add +1 to the count of deleted tables.
 
  50         self.tables_deleted += 1
 
  52     def notify_one_table_ignored(self) -> None:
 
  54             Add +1 to the count of ignored tables.
 
  56         self.tables_ignored += 1
 
  58     def notify_import_done(self) -> None:
 
  60             Print stats for the whole import process
 
  63         LOG.info('====================================================================')
 
  64         LOG.info('Final statistics of the import:')
 
  65         LOG.info('- %s phrases were invalid.', self.invalids)
 
  67             LOG.info('  Those invalid phrases have been skipped.')
 
  68         LOG.info('- %s tables were ignored as they already exist on the database',
 
  70         LOG.info('- %s tables were created', self.tables_created)
 
  71         LOG.info('- %s tables were deleted from the database', self.tables_deleted)
 
  72         if self.tables_deleted > 0:
 
  73             LOG.info('  They were deleted as they are not valid anymore.')
 
  76             LOG.warning('%s phrases were invalid and have been skipped during the whole process.',
 
  79         self._intialize_values()