[new] log deleted picks in json file

This commit is contained in:
Marcel Paffrath 2019-05-29 15:58:37 +02:00
parent 02a0abffd9
commit 102b7eafe3
3 changed files with 68 additions and 24 deletions

View File

@ -29,6 +29,9 @@ import os
import platform import platform
import sys import sys
import json
from datetime import datetime
matplotlib.use('Qt4Agg') matplotlib.use('Qt4Agg')
matplotlib.rcParams['backend.qt4'] = 'PySide' matplotlib.rcParams['backend.qt4'] = 'PySide'
matplotlib.rcParams['savefig.dpi'] = 300 matplotlib.rcParams['savefig.dpi'] = 300
@ -160,6 +163,9 @@ class MainWindow(QMainWindow):
self.fnames = None self.fnames = None
self._stime = None self._stime = None
# track deleted picks for logging
self.deleted_picks = {}
while True: while True:
try: try:
if settings.value("user/FullName", None) is None: if settings.value("user/FullName", None) is None:
@ -1520,6 +1526,11 @@ class MainWindow(QMainWindow):
if not event.dirty: if not event.dirty:
continue continue
self.get_data().setEvtData(event) self.get_data().setEvtData(event)
# save deleted picks to json file
try:
self.dump_deleted_picks(event.path)
except Exception as e:
print('WARNING! Could not save information on deleted picks {}. Reason: {}'.format(event.path, e))
try: try:
self.saveData(event, event.path, outformats) self.saveData(event, event.path, outformats)
event.dirty = False event.dirty = False
@ -2451,6 +2462,8 @@ class MainWindow(QMainWindow):
self.update_status('picks accepted ({0})'.format(station)) self.update_status('picks accepted ({0})'.format(station))
self.addPicks(station, pickDlg.getPicks(picktype='manual'), type='manual') self.addPicks(station, pickDlg.getPicks(picktype='manual'), type='manual')
self.addPicks(station, pickDlg.getPicks(picktype='auto'), type='auto') self.addPicks(station, pickDlg.getPicks(picktype='auto'), type='auto')
if pickDlg.removed_picks:
self.log_deleted_picks(pickDlg.removed_picks)
self.enableSaveEventAction() self.enableSaveEventAction()
self.comparable = self.checkEvents4comparison() self.comparable = self.checkEvents4comparison()
if True in self.comparable.values(): if True in self.comparable.values():
@ -2733,29 +2746,57 @@ class MainWindow(QMainWindow):
# dictionary consisting of set station only # dictionary consisting of set station only
automanu[type](station=station, pick=picks) automanu[type](station=station, pick=picks)
return rval return rval
# if not stat_picks:
# stat_picks = picks def deletePicks(self, station, deleted_pick, type):
# else: deleted_pick['station'] = station
# msgBox = QMessageBox(self) self.addPicks(station, {}, type=type)
# msgBox.setText("The picks for station {0} have been " self.log_deleted_picks([deleted_pick])
# "changed.".format(station))
# msgBox.setDetailedText("Old picks:\n" def log_deleted_picks(self, deleted_picks, event_path=None):
# "{old_picks}\n\n" ''' Log deleted picks to list self.deleted_picks '''
# "New picks:\n" if not event_path:
# "{new_picks}".format(old_picks=stat_picks, event_path = self.get_current_event_path()
# new_picks=picks)) for deleted_pick in deleted_picks:
# msgBox.setInformativeText("Do you want to save your changes?") deleted_pick = dict(deleted_pick)
# msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Cancel) if not event_path in self.deleted_picks.keys():
# msgBox.setDefaultButton(QMessageBox.Save) self.deleted_picks[event_path] = []
# ret = msgBox.exec_() for key, value in deleted_pick.items():
# if ret == QMessageBox.Save: if type(value) == UTCDateTime:
# stat_picks = picks deleted_pick[key] = str(value)
# rval = True deleted_pick['deletion_logtime'] = str(datetime.now())
# elif ret == QMessageBox.Cancel: self.deleted_picks[event_path].append(deleted_pick)
# pass
# else: def dump_deleted_picks(self, event_path):
# raise Exception('FATAL: Should never occur!') ''' Save deleted picks to json file for event in event_path. Load old file before and merge'''
# MP MP prompt redundant because new picks have to be accepted in the first place closing PickDlg deleted_picks_from_file = self.load_deleted_picks(event_path)
deleted_picks_event = self.deleted_picks[event_path]
for pick in deleted_picks_from_file:
if not pick in deleted_picks_event:
deleted_picks_event.append(pick)
# if there are no picks to save
if not deleted_picks_event:
return
fpath = self.get_deleted_picks_fpath(event_path)
with open(fpath, 'w') as outfile:
json.dump(self.deleted_picks[event_path], outfile)
# clear entry for this event
self.deleted_picks[event_path] = []
def load_deleted_picks(self, event_path):
''' Load a list with deleted picks for event in event_path from file '''
fpath = self.get_deleted_picks_fpath(event_path)
if not os.path.isfile(fpath):
return []
with open(fpath, 'r') as infile:
deleted_picks = json.load(infile)
return deleted_picks
def get_deleted_picks_fpath(self, event_path):
return os.path.join(event_path, 'deleted_picks.json')
def updatePicks(self, type='manual', event=None): def updatePicks(self, type='manual', event=None):
if not event: if not event:

View File

@ -92,7 +92,7 @@ class Array_map(QtGui.QWidget):
raise TypeError('Unknown "picker" {}'.format(picker)) raise TypeError('Unknown "picker" {}'.format(picker))
print(message) print(message)
pyl_mw = self._parent pyl_mw = self._parent
pyl_mw.addPicks(station, {}, type=picker) pyl_mw.deletePicks(station, pick, type=picker)
pyl_mw.setDirty(True) pyl_mw.setDirty(True)
pyl_mw.update_status(message) pyl_mw.update_status(message)
if self.auto_refresh_box.isChecked(): if self.auto_refresh_box.isChecked():

View File

@ -1620,6 +1620,7 @@ class PickDlg(QDialog):
self.arrivalsText = [] self.arrivalsText = []
self.cidpick = [] self.cidpick = []
self.cidpress = None self.cidpress = None
self.removed_picks = []
settings = QSettings() settings = QSettings()
pylot_user = getpass.getuser() pylot_user = getpass.getuser()
self._user = settings.value('user/Login', pylot_user) self._user = settings.value('user/Login', pylot_user)
@ -2804,6 +2805,8 @@ class PickDlg(QDialog):
msg = 'Deleted {} pick for phase {}, station {} at timestamp {} (relative time: {} s)' msg = 'Deleted {} pick for phase {}, station {} at timestamp {} (relative time: {} s)'
print(msg.format(picktype, phase, '{}.{}'.format(self.network, self.station), print(msg.format(picktype, phase, '{}.{}'.format(self.network, self.station),
self.getStartTime() + pick_rel, pick_rel)) self.getStartTime() + pick_rel, pick_rel))
removed_pick['station'] = self.station
self.removed_picks.append(removed_pick)
self.setDirty(True) self.setDirty(True)
def identify_selected_picks(self, x): def identify_selected_picks(self, x):