Skip to content
Snippets Groups Projects
Commit 10b21a4b authored by Kien Le's avatar Kien Le
Browse files

Merge branch 'bug-some_mass_pos_channels_not_recognized' into 'develop'

Fix problems plotting mass-position data

See merge request !311
parents 591a2788 5b31fd6a
No related branches found
No related tags found
Loading
Pipeline #3960 passed with stage
in 7 minutes and 39 seconds
No preview for this file type
...@@ -23,7 +23,8 @@ def get_chan_plot_info(org_chan_id: str, data_type: str, ...@@ -23,7 +23,8 @@ def get_chan_plot_info(org_chan_id: str, data_type: str,
+ Key 'label' keeps label to be displayed in the plotting + Key 'label' keeps label to be displayed in the plotting
""" """
chan = org_chan_id chan = org_chan_id
chan = convert_actual_channel_to_db_channel_w_question_mark(chan) chan = convert_actual_channel_to_db_channel_w_question_mark(chan,
data_type)
if len(org_chan_id) == 3 and org_chan_id.startswith('DS'): if len(org_chan_id) == 3 and org_chan_id.startswith('DS'):
chan = 'SEISMIC' chan = 'SEISMIC'
...@@ -88,7 +89,8 @@ def get_convert_factor(chan_id: str, data_type: str) -> float: ...@@ -88,7 +89,8 @@ def get_convert_factor(chan_id: str, data_type: str) -> float:
:param data_type: type of data in data set :param data_type: type of data in data set
:return: converting factor :return: converting factor
""" """
chan_id = convert_actual_channel_to_db_channel_w_question_mark(chan_id) chan_id = convert_actual_channel_to_db_channel_w_question_mark(chan_id,
data_type)
sql = f"SELECT convertFactor FROM Channels WHERE channel='{chan_id}' " \ sql = f"SELECT convertFactor FROM Channels WHERE channel='{chan_id}' " \
f"AND dataType='{data_type}'" f"AND dataType='{data_type}'"
ret = execute_db(sql) ret = execute_db(sql)
...@@ -98,12 +100,15 @@ def get_convert_factor(chan_id: str, data_type: str) -> float: ...@@ -98,12 +100,15 @@ def get_convert_factor(chan_id: str, data_type: str) -> float:
return None return None
def convert_actual_channel_to_db_channel_w_question_mark(chan_id: str) -> str: def convert_actual_channel_to_db_channel_w_question_mark(
chan_id: str, data_type: str) -> str:
""" """
The digit in channel end with a digit is represented with the question The digit in channel end with a digit is represented with the question
mark '?' in DB. This function change the real channel name to DB mark '?' in DB. This function change the real channel name to DB
channel name with '?'. channel name with '?'.
:param chan_id: real channel name :param chan_id: real channel name
:param data_type: the data type of the channel, used for handling masspos
data of Q330 data
:return chan_id: channel name with '?' at the end if available :return chan_id: channel name with '?' at the end if available
""" """
sql = "SELECT * FROM Channels WHERE channel like '%?'" sql = "SELECT * FROM Channels WHERE channel like '%?'"
...@@ -113,6 +118,13 @@ def convert_actual_channel_to_db_channel_w_question_mark(chan_id: str) -> str: ...@@ -113,6 +118,13 @@ def convert_actual_channel_to_db_channel_w_question_mark(chan_id: str) -> str:
if chan_id[-1].isdigit(): if chan_id[-1].isdigit():
# to prevent the case prefix similar to prefix of channel w/o ? # to prevent the case prefix similar to prefix of channel w/o ?
chan_id = chan_id[:-1] + '?' chan_id = chan_id[:-1] + '?'
# Mass-position channels for Q330 data can sometimes end with a letter.
elif data_type == 'Q330':
mass_pos_letter_suffixes = ['Z', 'N', 'E', 'U', 'V', 'W']
if (chan_id.startswith('VM') and
chan_id[-1] in mass_pos_letter_suffixes):
chan_id = 'VM?'
return chan_id return chan_id
......
No preview for this file type
...@@ -12,7 +12,7 @@ from sohstationviewer.database.extract_data import get_convert_factor ...@@ -12,7 +12,7 @@ from sohstationviewer.database.extract_data import get_convert_factor
mass_pos_volt_ranges = {"regular": [0.5, 2.0, 4.0, 7.0], mass_pos_volt_ranges = {"regular": [0.5, 2.0, 4.0, 7.0],
"trillium": [0.5, 1.8, 2.4, 3.5]} "trillium": [0.5, 1.8, 2.4, 3.5]}
mass_pos_color_pallets = {"B": ["C", "G", "Y", "R", "M"], mass_pos_color_pallets = {"B": ["C", "G", "Y", "R", "M"],
"W": ["B", "B", "B", "B", "B"]} "W": ["C", "G", "Y", "R", "M"]}
def get_masspos_value_colors( def get_masspos_value_colors(
......
...@@ -241,13 +241,22 @@ class TestGetColorRanges(BaseTestCase): ...@@ -241,13 +241,22 @@ class TestGetColorRanges(BaseTestCase):
class TestConvertActualChannelToDBChannelWQuestionMark(BaseTestCase): class TestConvertActualChannelToDBChannelWQuestionMark(BaseTestCase):
def test_question_channel(self): def test_question_channel(self):
ret = convert_actual_channel_to_db_channel_w_question_mark('VM1') ret = convert_actual_channel_to_db_channel_w_question_mark('VM1', '')
self.assertEqual(ret, 'VM?') self.assertEqual(ret, 'VM?')
def test_non_question_channel(self): def test_non_question_channel(self):
ret = convert_actual_channel_to_db_channel_w_question_mark('VCO') ret = convert_actual_channel_to_db_channel_w_question_mark('VCO', '')
self.assertEqual(ret, 'VCO') self.assertEqual(ret, 'VCO')
def test_q330_letter_masspos_channel(self):
for suffix in ['Z', 'N', 'E', 'U', 'V', 'W']:
channel = 'VM' + suffix
with self.subTest(f'Test {channel}'):
ret = convert_actual_channel_to_db_channel_w_question_mark(
channel, 'Q330'
)
self.assertEqual(ret, 'VM?')
class TestGetConvertFactor(BaseTestCase): class TestGetConvertFactor(BaseTestCase):
def test_question_channel(self): def test_question_channel(self):
......
...@@ -23,9 +23,9 @@ class TestGetMassposValue(BaseTestCase): ...@@ -23,9 +23,9 @@ class TestGetMassposValue(BaseTestCase):
""" """
expected_input_output_pairs = { expected_input_output_pairs = {
('regular', 'B'): '0.5:C|2.0:G|4.0:Y|7.0:R|7.0:+M', ('regular', 'B'): '0.5:C|2.0:G|4.0:Y|7.0:R|7.0:+M',
('regular', 'W'): '0.5:B|2.0:B|4.0:B|7.0:B|7.0:+B', ('regular', 'W'): '0.5:C|2.0:G|4.0:Y|7.0:R|7.0:+M',
('trillium', 'B'): '0.5:C|1.8:G|2.4:Y|3.5:R|3.5:+M', ('trillium', 'B'): '0.5:C|1.8:G|2.4:Y|3.5:R|3.5:+M',
('trillium', 'W'): '0.5:B|1.8:B|2.4:B|3.5:B|3.5:+B', ('trillium', 'W'): '0.5:C|1.8:G|2.4:Y|3.5:R|3.5:+M',
} }
test_names = ( test_names = (
'test_regular_B', 'test_regular_B',
...@@ -52,11 +52,11 @@ class TestGetMassposValue(BaseTestCase): ...@@ -52,11 +52,11 @@ class TestGetMassposValue(BaseTestCase):
('regular', 'B'): ('regular', 'B'):
[(0.5, 'C'), (2.0, 'G'), (4.0, 'Y'), (7.0, 'R'), (7.0, 'M')], [(0.5, 'C'), (2.0, 'G'), (4.0, 'Y'), (7.0, 'R'), (7.0, 'M')],
('regular', 'W'): ('regular', 'W'):
[(0.5, 'B'), (2.0, 'B'), (4.0, 'B'), (7.0, 'B'), (7.0, 'B')], [(0.5, 'C'), (2.0, 'G'), (4.0, 'Y'), (7.0, 'R'), (7.0, 'M')],
('trillium', 'B'): ('trillium', 'B'):
[(0.5, 'C'), (1.8, 'G'), (2.4, 'Y'), (3.5, 'R'), (3.5, 'M')], [(0.5, 'C'), (1.8, 'G'), (2.4, 'Y'), (3.5, 'R'), (3.5, 'M')],
('trillium', 'W'): ('trillium', 'W'):
[(0.5, 'B'), (1.8, 'B'), (2.4, 'B'), (3.5, 'B'), (3.5, 'B')], [(0.5, 'C'), (1.8, 'G'), (2.4, 'Y'), (3.5, 'R'), (3.5, 'M')],
} }
test_names = ( test_names = (
'test_regular_B', 'test_regular_B',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment