Skip to content

Commit

Permalink
added maximum failed attempts in server mode
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Apr 10, 2022
1 parent bd70505 commit b9c5c4a
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 69 deletions.
2 changes: 1 addition & 1 deletion hyo2/soundspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed"
__version__ = '2022.1.0'
__version__ = '2022.2.0'
__copyright__ = 'Copyright 2022 University of New Hampshire, Center for Coastal and Ocean Mapping'

lib_info = LibInfo()
Expand Down
49 changes: 17 additions & 32 deletions hyo2/soundspeed/base/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class Setup:

@classmethod
def are_updates_required(cls, db_path):
logger.debug("check if version updates are required for %s" % db_path)
# logger.debug("check if version updates are required for %s" % db_path)
db = SetupDb(os.path.dirname(db_path))
if db.setup_version == 1:
# logger.debug(db.setup_version)
if db.setup_version < 5:
return True
return False

Expand All @@ -25,11 +26,7 @@ def apply_required_updates(cls, db_path):
logger.debug("applying version updates %s" % db_path)
db = SetupDb(os.path.dirname(db_path))
if db.setup_version == 1:
success = db.update_from_v1_to_v2()
if success:
return True
if db.setup_version == 2:
success = db.update_from_v1_to_v2()
success = db.update_from_v1_to_v5()
if success:
return True
return False
Expand Down Expand Up @@ -99,6 +96,7 @@ def __init__(self, release_folder, use_setup_name=None):
self.server_source = None
self.server_apply_surface_sound_speed = None
self.server_auto_export_on_send = None
self.server_max_failed_attempts = None

# current settings
self.current_project = None
Expand Down Expand Up @@ -139,7 +137,7 @@ def load_from_db(self, db_path: Optional[str] = None):
release_folder, _ = os.path.split(db_path)
db = SetupDb(release_folder)

if db.setup_version > 4:
if db.setup_version > 5:
raise RuntimeError("unsupported setup version: %s" % db.setup_version)

self.setup_version = db.setup_version
Expand All @@ -149,25 +147,16 @@ def load_from_db(self, db_path: Optional[str] = None):
# input
self.use_woa09 = db.use_woa09
self.use_woa13 = db.use_woa13
if db.setup_version == 1:
self.use_woa18 = False
else:
self.use_woa18 = db.use_woa18
self.use_woa18 = db.use_woa18
self.use_rtofs = db.use_rtofs
if db.setup_version == 1:
self.use_gomofs = False
else:
self.use_gomofs = db.use_gomofs
self.use_gomofs = db.use_gomofs
self.ssp_extension_source = Dicts.atlases[db.ssp_extension_source]
self.ssp_salinity_source = Dicts.atlases[db.ssp_salinity_source]
self.ssp_temp_sal_source = Dicts.atlases[db.ssp_temp_sal_source]
self.ssp_up_or_down = Dicts.ssp_directions[db.ssp_up_or_down]
self.rx_max_wait_time = db.rx_max_wait_time
self.use_sis4 = db.use_sis4
if db.setup_version == 1:
self.use_sis5 = False
else:
self.use_sis5 = db.use_sis5
self.use_sis5 = db.use_sis5
self.use_sippican = db.use_sippican
self.use_mvp = db.use_mvp

Expand Down Expand Up @@ -206,17 +195,15 @@ def load_from_db(self, db_path: Optional[str] = None):
# server
self.server_source = db.server_source
self.server_apply_surface_sound_speed = db.server_apply_surface_sound_speed
self.server_max_failed_attempts = db.server_max_failed_attempts

# current settings
self.current_project = db.current_project
self.custom_projects_folder = db.custom_projects_folder
self.custom_outputs_folder = db.custom_outputs_folder
self.custom_woa09_folder = db.custom_woa09_folder
self.custom_woa13_folder = db.custom_woa13_folder
if db.setup_version == 1:
self.custom_woa18_folder = ""
else:
self.custom_woa18_folder = db.custom_woa18_folder
self.custom_woa18_folder = db.custom_woa18_folder
self.noaa_tools = db.noaa_tools
self.default_institution = db.default_institution
self.default_survey = db.default_survey
Expand Down Expand Up @@ -244,20 +231,17 @@ def save_to_db(self):
# input
db.use_woa09 = self.use_woa09
db.use_woa13 = self.use_woa13
if db.setup_version > 1:
db.use_woa18 = self.use_woa18
db.use_woa18 = self.use_woa18
db.use_rtofs = self.use_rtofs
if db.setup_version > 1:
db.use_gomofs = self.use_gomofs
db.use_gomofs = self.use_gomofs
db.ssp_extension_source = Helper.first_match(Dicts.atlases, self.ssp_extension_source)
db.ssp_salinity_source = Helper.first_match(Dicts.atlases, self.ssp_salinity_source)
db.ssp_temp_sal_source = Helper.first_match(Dicts.atlases, self.ssp_temp_sal_source)
db.ssp_up_or_down = Helper.first_match(Dicts.ssp_directions, self.ssp_up_or_down)

db.rx_max_wait_time = self.rx_max_wait_time
db.use_sis4 = self.use_sis4
if db.setup_version > 1:
db.use_sis5 = self.use_sis5
db.use_sis5 = self.use_sis5
db.use_sippican = self.use_sippican
db.use_mvp = self.use_mvp

Expand Down Expand Up @@ -297,15 +281,15 @@ def save_to_db(self):
# server
db.server_source = self.server_source
db.server_apply_surface_sound_speed = self.server_apply_surface_sound_speed
db.server_max_failed_attempts = self.server_max_failed_attempts

# current settings
db.current_project = self.current_project
db.custom_projects_folder = self.custom_projects_folder
db.custom_outputs_folder = self.custom_outputs_folder
db.custom_woa09_folder = self.custom_woa09_folder
db.custom_woa13_folder = self.custom_woa13_folder
if db.setup_version > 1:
db.custom_woa18_folder = self.custom_woa18_folder
db.custom_woa18_folder = self.custom_woa18_folder
db.noaa_tools = self.noaa_tools
db.default_institution = self.default_institution
db.default_survey = self.default_survey
Expand Down Expand Up @@ -357,6 +341,7 @@ def __repr__(self):
msg += " <server_source: %s>\n" % self.server_source
msg += " <server_apply_surface_sound_speed: %s>\n" % self.server_apply_surface_sound_speed
msg += " <server_auto_export_on_send: %s>\n" % self.server_auto_export_on_send
msg += " <server_max_failed_attempts: %s>\n" % self.server_max_failed_attempts
msg += " <current settings>\n"
msg += " <current_project: %s>\n" % self.current_project
msg += " <projects folder: %s>\n" % self.custom_projects_folder
Expand Down
17 changes: 13 additions & 4 deletions hyo2/soundspeed/base/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from hyo2.soundspeed.base.basedb import BaseDb
from hyo2.soundspeed.base.setup_sql import CREATE_SETTINGS, CREATE_SETTINGS_VIEW, CREATE_CLIENT_LIST, \
RENAME_SETTINGS, RENAME_CLIENT_LIST, DROP_OLD_SETTINGS, DROP_OLD_CLIENT_LIST, DROP_SETTINGS_VIEW, \
V1_V2_COPY_SETTINGS, V1_V2_COPY_CLIENT_LIST
V1_V5_COPY_SETTINGS, V1_V5_COPY_CLIENT_LIST

logger = logging.getLogger(__name__)

Expand All @@ -21,7 +21,7 @@ def __init__(self, data_folder, db_file="setup.db", use_setup_name=None):
self._check_default_setup()
self.use_setup_name = use_setup_name

def update_from_v1_to_v2(self):
def update_from_v1_to_v5(self):
if not self.conn:
logger.error("Missing db connection")
return False
Expand All @@ -39,8 +39,8 @@ def update_from_v1_to_v2(self):
self.conn.execute(CREATE_SETTINGS_VIEW)

with self.conn:
self.conn.execute(V1_V2_COPY_SETTINGS)
self.conn.execute(V1_V2_COPY_CLIENT_LIST)
self.conn.execute(V1_V5_COPY_SETTINGS)
self.conn.execute(V1_V5_COPY_CLIENT_LIST)
self.conn.execute(DROP_OLD_SETTINGS)
self.conn.execute(DROP_OLD_CLIENT_LIST)

Expand Down Expand Up @@ -651,6 +651,15 @@ def server_apply_surface_sound_speed(self):
def server_apply_surface_sound_speed(self, value):
self._setter_bool("server_apply_surface_sound_speed", value)

# --- server_max_failed_attempts
@property
def server_max_failed_attempts(self):
return self._getter_int("server_max_failed_attempts")

@server_max_failed_attempts.setter
def server_max_failed_attempts(self, value):
self._setter_int("server_max_failed_attempts", value)

# --- current_project
@property
def current_project(self):
Expand Down
7 changes: 4 additions & 3 deletions hyo2/soundspeed/base/setup_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
CREATE_SETTINGS = """-- noinspection SqlResolveForFile
CREATE TABLE IF NOT EXISTS general(
id integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
setup_version integer NOT NULL DEFAULT 4,
setup_version integer NOT NULL DEFAULT 5,
setup_name text NOT NULL UNIQUE DEFAULT "default",
setup_status text NOT NULL DEFAULT "inactive",
/* input */
Expand Down Expand Up @@ -106,6 +106,7 @@
/* server */
server_source text NOT NULL DEFAULT "WOA09",
server_apply_surface_sound_speed integer NOT NULL DEFAULT 1,
server_max_failed_attempts integer NOT NULL DEFAULT 60,
/* current settings */
current_project text NOT NULL DEFAULT "default",
Expand Down Expand Up @@ -168,7 +169,7 @@

# COPY V1 -> V2

V1_V2_COPY_SETTINGS = """-- noinspection SqlResolveForFile
V1_V5_COPY_SETTINGS = """-- noinspection SqlResolveForFile
INSERT INTO general
(id, setup_name, setup_status, use_woa09, use_woa13, use_rtofs,
ssp_extension_source, ssp_salinity_source, ssp_temp_sal_source, ssp_up_or_down, rx_max_wait_time,
Expand Down Expand Up @@ -254,7 +255,7 @@
FROM general_old
"""

V1_V2_COPY_CLIENT_LIST = """-- noinspection SqlResolveForFile
V1_V5_COPY_CLIENT_LIST = """-- noinspection SqlResolveForFile
INSERT INTO client_list (id, setup_id, name, ip, port, protocol)
SELECT
id, setup_id, name, ip, port, protocol
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeed/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, prj: Optional['hyo2.soundspeed.soundspeed.SoundSpeedLibrary']
self.last_lon_idx = None # type: Optional[int]

self.cur_invalid_source_idx = 0
self.max_invalid_source_idx = 60
self.max_invalid_source_idx = self.prj.setup.server_max_failed_attempts

self.settings_errors = list()
self.runtime_errors = list()
Expand Down
6 changes: 3 additions & 3 deletions hyo2/soundspeed/soundspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ def list_other_setups(cls) -> list:
if not os.path.exists(setup_path):
continue

# if exists, attempt to load the setup
# if exists, check if updated required and validity
try:
Setup(release_folder=release_path)
updates_required = Setup.are_updates_required(db_path=setup_path)
logger.debug("found setup: %s [requires updates: %s]" % (setup_path, updates_required))
except Exception as e:
logger.debug("skipping %s: %s" % (release_path, e))
continue

logger.debug("found setup: %s" % setup_path)
old_setups.append(setup_path)

return old_setups
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Manager"
__version__ = "2022.1.0"
__version__ = "2022.2.0"
__copyright__ = "Copyright 2022 University of New Hampshire, Center for Coastal and Ocean Mapping"

app_info = AppInfo()
Expand Down
4 changes: 3 additions & 1 deletion hyo2/soundspeedmanager/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def qt_custom_handler(error_type: QtCore.QtMsgType, error_context: QtCore.QMessa

QtCore.qInstallMessageHandler(qt_custom_handler)

app = None


def gui():
"""Create the application and show the Sound Speed Manager gui"""
from hyo2.soundspeedmanager.mainwin import MainWin

global app
app = QtWidgets.QApplication([])
app.setStyleSheet(AppStyle.load_stylesheet())

Expand Down
File renamed without changes
17 changes: 0 additions & 17 deletions hyo2/soundspeedmanager/widgets/dataplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,23 +584,6 @@ def redraw(self):
"""Redraw the canvases, update the locators"""

with rc_context(self.rc_context):
for a in self.c.figure.get_axes():

xaxis = getattr(a, 'xaxis', None)
yaxis = getattr(a, 'yaxis', None)
locators = []

if xaxis is not None:
locators.append(xaxis.get_major_locator())
locators.append(xaxis.get_minor_locator())

if yaxis is not None:
locators.append(yaxis.get_major_locator())
locators.append(yaxis.get_minor_locator())

for loc in locators:
loc.refresh()

self.c.draw_idle()

def update_validity_indices(self):
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedsettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Settings"
__version__ = '2022.1.0'
__version__ = '2022.2.0'
__copyright__ = 'Copyright 2022 University of New Hampshire, Center for Coastal and Ocean Mapping'

app_info = AppInfo()
Expand Down
37 changes: 35 additions & 2 deletions hyo2/soundspeedsettings/widgets/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from PySide2 import QtCore, QtWidgets
from PySide2 import QtCore, QtGui, QtWidgets

from hyo2.soundspeedsettings.widgets.widget import AbstractWidget
from hyo2.soundspeed.profile.dicts import Dicts
Expand Down Expand Up @@ -150,6 +150,27 @@ def __init__(self, main_win, db):
vbox.addWidget(self.server_apply_surface_sound_speed)
vbox.addStretch()

# - server_max_failed_attempts
hbox = QtWidgets.QHBoxLayout()
self.right_layout.addLayout(hbox)
# -- label
vbox = QtWidgets.QVBoxLayout()
hbox.addLayout(vbox)
vbox.addStretch()
label = QtWidgets.QLabel("Maximum failed attempts:")
label.setFixedWidth(lbl_width)
vbox.addWidget(label)
vbox.addStretch()
# -- value
vbox = QtWidgets.QVBoxLayout()
hbox.addLayout(vbox)
vbox.addStretch()
self.server_max_failed_attempts = QtWidgets.QLineEdit()
validator = QtGui.QIntValidator(1, 9999)
self.server_max_failed_attempts.setValidator(validator)
vbox.addWidget(self.server_max_failed_attempts)
vbox.addStretch()

self.right_layout.addStretch()

self.main_layout.addStretch()
Expand All @@ -168,6 +189,8 @@ def __init__(self, main_win, db):
self.server_source.currentIndexChanged.connect(self.apply_server_source)
# noinspection PyUnresolvedReferences
self.server_apply_surface_sound_speed.currentIndexChanged.connect(self.apply_server_apply_surface_sound_speed)
# noinspection PyUnresolvedReferences
self.server_max_failed_attempts.textChanged.connect(self.apply_server_max_failed_attempts)

def new_client(self):
logger.debug("new setup")
Expand Down Expand Up @@ -283,11 +306,18 @@ def apply_server_source(self):
self.main_win.reload_settings()

def apply_server_apply_surface_sound_speed(self):
# logger.debug("apply apply surface sound speed")
# logger.debug("apply surface sound speed")
self.db.server_apply_surface_sound_speed = self.server_apply_surface_sound_speed.currentText() == "True"
self.setup_changed()
self.main_win.reload_settings()

def apply_server_max_failed_attempts(self):
# logger.debug("apply server max failed attempts")
logger.debug(self.server_max_failed_attempts.text())
self.db.server_max_failed_attempts = int(self.server_max_failed_attempts.text())
self.setup_changed()
self.main_win.reload_settings()

def setup_changed(self):
"""Refresh the setup list"""
# logger.debug("refresh clients")
Expand All @@ -312,6 +342,9 @@ def setup_changed(self):
else:
self.server_apply_surface_sound_speed.setCurrentIndex(1) # False

# server_max_failed_attempts
self.server_max_failed_attempts.setText("%d" % self.db.server_max_failed_attempts)

# prepare the table
self.client_list.clear()
self.client_list.setColumnCount(4)
Expand Down
2 changes: 1 addition & 1 deletion hyo2/ssm_sis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


name = "SSM-SIS"
__version__ = '1.0.2'
__version__ = '1.1.0'

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
Expand Down
Loading

0 comments on commit b9c5c4a

Please sign in to comment.