Skip to content

Commit

Permalink
Improve log messages
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
marioba committed Oct 29, 2021
1 parent 4435d56 commit aef211c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
24 changes: 24 additions & 0 deletions comptages/chart/chart_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

from qgis.PyQt.QtWidgets import QDockWidget, QListWidgetItem, QTabWidget
from qgis.core import QgsMessageLog, Qgis
from comptages.core.utils import get_ui_class, push_warning, push_info
from comptages.ui.resources import *
from comptages.core.tjm import calculate_tjm, get_tjm_data_total, get_tjm_data_by_lane, get_tjm_data_by_direction
Expand Down Expand Up @@ -169,21 +170,41 @@ def current_tab_changed(self, index):
self.chart_selection_changed(0)

def validate_count(self):
QgsMessageLog.logMessage(
'{} - Accept data started'.format(datetime.now()),
'Comptages', Qgis.Info)

tab = self.tabWidget.currentWidget()
self.layers.change_status_of_count_data(
self.count_id, tab.section_id,
self.layers.IMPORT_STATUS_DEFINITIVE)
calculate_tjm(self.count_id)
self.show_next_quarantined_chart()

QgsMessageLog.logMessage(
'{} - Accept data ended'.format(datetime.now()),
'Comptages', Qgis.Info)

def refuse_count(self):
QgsMessageLog.logMessage(
'{} - Reject data started'.format(datetime.now()),
'Comptages', Qgis.Info)

tab = self.tabWidget.currentWidget()
self.layers.delete_count_data(
self.count_id, tab.section_id,
self.layers.IMPORT_STATUS_QUARANTINE)
self.show_next_quarantined_chart()

QgsMessageLog.logMessage(
'{} - Reject data ended'.format(datetime.now()),
'Comptages', Qgis.Info)

def show_next_quarantined_chart(self):
QgsMessageLog.logMessage(
'{} - Generate validation chart started'.format(datetime.now()),
'Comptages', Qgis.Info)

quarantined_counts = self.layers.get_quarantined_counts()
if not quarantined_counts:
self.hide()
Expand All @@ -193,6 +214,9 @@ def show_next_quarantined_chart(self):
self.set_attributes(quarantined_counts[0], True)
self.show()

QgsMessageLog.logMessage(
'{} - Generate validation chart ended'.format(datetime.now()),
'Comptages', Qgis.Info)

TAB_CLASS = get_ui_class('chart_tab.ui')

Expand Down
28 changes: 21 additions & 7 deletions comptages/comptages.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def do_import_files_action(self):
self.import_file(file_path)

def import_file(self, file_path, count_id=None):
QgsMessageLog.logMessage(
'{} - Prepare import file {} started'.format(
datetime.now(), os.path.basename(file_path)),
'Comptages', Qgis.Info)

# Manage binary files
with open(file_path, 'rb') as fd:
Expand Down Expand Up @@ -251,7 +255,13 @@ def import_file(self, file_path, count_id=None):
return

QgsMessageLog.logMessage(
'Importation {}'.format(os.path.basename(file_path)),
'{} - Prepare import file {}'.format(
datetime.now(), os.path.basename(file_path)),
'Comptages', Qgis.Info)

QgsMessageLog.logMessage(
'{} - Import file {} started'.format(
datetime.now(), os.path.basename(file_path)),
'Comptages', Qgis.Info)

file_format = file_header['FORMAT']
Expand All @@ -276,6 +286,10 @@ def task_finished(self):
self.tm.allTasksFinished.disconnect(self.task_finished)
push_info(('Toutes les tâches sont terminées. Consultez le journal '
'pour plus de détails.'))
QgsMessageLog.logMessage(
'{} - All tasks ended'.format(datetime.now()),
'Comptages', Qgis.Info)

self.chart_dock.show_next_quarantined_chart()

def do_validate_imported_files_action(self):
Expand Down Expand Up @@ -346,7 +360,7 @@ def do_filter_action(self):

def do_yearly_report_action(self):
QgsMessageLog.logMessage(
'Generate yearly report action started {}'.format(datetime.now()),
'{} - Generate yearly report action started'.format(datetime.now()),
'Comptages', Qgis.Info)

if self.tm.countActiveTasks() > 0:
Expand Down Expand Up @@ -402,7 +416,7 @@ def do_yearly_report_action(self):
# TODO: check if there are comptages for this section and year

QgsMessageLog.logMessage(
'Generate yearly report action ended {}'.format(datetime.now()),
'{} - Generate yearly report action ended'.format(datetime.now()),
'Comptages', Qgis.Info)

def do_import_ics_action(self):
Expand Down Expand Up @@ -448,7 +462,7 @@ def do_import_single_file_action(self, count_id):

def do_generate_report_action(self, count_id):
QgsMessageLog.logMessage(
'Generate report action started {}'.format(datetime.now()),
'{} - Generate report action started'.format(datetime.now()),
'Comptages', Qgis.Info)

if self.tm.countActiveTasks() > 0:
Expand Down Expand Up @@ -480,7 +494,7 @@ def do_generate_report_action(self, count_id):
.format(self.layers.get_installation_name_of_count(count_id),count_id))

QgsMessageLog.logMessage(
'Generate report action ended {}'.format(datetime.now()),
'{} - Generate report action'.format(datetime.now()),
'Comptages', Qgis.Info)

def do_export_plan_action(self, count_id):
Expand Down Expand Up @@ -515,7 +529,7 @@ def do_export_plan_action(self, count_id):

def do_generate_chart_action(self, count_id):
QgsMessageLog.logMessage(
'Generate chart action started {}'.format(datetime.now()),
'{} - Generate chart action started'.format(datetime.now()),
'Comptages', Qgis.Info)

if self.tm.countActiveTasks() > 0:
Expand All @@ -525,7 +539,7 @@ def do_generate_chart_action(self, count_id):
self.chart_dock.set_attributes(count_id)

QgsMessageLog.logMessage(
'Generate chart action ended {}'.format(datetime.now()),
'{} - Generate chart action ended'.format(datetime.now()),
'Comptages', Qgis.Info)

def enable_actions_if_needed(self):
Expand Down
10 changes: 6 additions & 4 deletions comptages/importer/data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def run(self):
def finished(self, result):
if result:
QgsMessageLog.logMessage(
'Importation terminée {}'.format(self.basename),
'{} - Import file {} ended'.format(
datetime.now(), self.basename),
'Comptages', Qgis.Info)

else:
QgsMessageLog.logMessage(
'Importation terminée avec des erreurs {}: {}'.format(
self.basename, self.exception),
'Comptages', Qgis.Critical)
'{} - Import file {} ended with errors: {}'.format(
datetime.now(), self.basename, self.exception),
'Comptages', Qgis.Info)

self.db.close()
del self.db
Expand Down

0 comments on commit aef211c

Please sign in to comment.