Skip to content
Snippets Groups Projects
Commit 0648d67d authored by David Bailey's avatar David Bailey
Browse files

feat(uqds): filter out uQDS results with unset version number

parent 78bafa5b
No related branches found
No related tags found
1 merge request!1Initial Release Merge
Pipeline #6076346 failed
import json
from smoothwaretb.database.testbench_db_handler import TestbenchDBHandler
from smoothwaretb.database.testbench_db_handler import pgretry
import json
class UqdsDBHandler(TestbenchDBHandler):
def __init__(self, pg):
......@@ -14,7 +14,7 @@ class UqdsDBHandler(TestbenchDBHandler):
@pgretry
def _DROP_SCHEMA(self):
raise RuntimeError("DiSABLED FUNCTION - please don't call me!")
raise RuntimeError("DISABLED FUNCTION - please don't call me!")
#super()._DROP_SCHEMA()
......@@ -57,6 +57,7 @@ class UqdsDBHandler(TestbenchDBHandler):
channel_pga_setting INTEGER NOT NULL DEFAULT 1,
result_failing BOOLEAN NOT NULL DEFAULT FALSE,
result_type TEXT NOT NULL DEFAULT 'test',
result_version INTEGER DEFAULT NULL,
result_data JSONB COMPRESSION PGLZ DEFAULT NULL,
result_completed_time TIMESTAMPTZ DEFAULT NULL
)
......@@ -86,6 +87,7 @@ class UqdsDBHandler(TestbenchDBHandler):
SELECT min(result_completed_time) AS earliest_result,
max(uqds_channel_result_id) AS uqds_channel_result_id
FROM uqds_channel_results
WHERE result_version IS NOT NULL
GROUP BY uqds_channel_sql_id, result_type, channel_pga_setting
)
SELECT *, result_data IS NOT NULL as result_present
......@@ -110,19 +112,42 @@ class UqdsDBHandler(TestbenchDBHandler):
@pgretry
def setup_channels(self, batch, channel_list, channel_types):
"""Set channels up with database IDs.
Details:
This function *must* be called before the test collection/test
sweeps are started. It will attempt to either create or fetch
the channel identifications from the database.
These IDs are saved locally in the channel_ids array, and are
used during later testbench acquisition events to properly
associate measurement results with channels.
Parameters:
batch : Text, name of the batch or group of channels.
channel_list : list of text, IDs of the channels (usually "0241" or similar)
channel_types : list of text, types of the channels (usually "normal")
Todo:
Split batch up into production_batch and channel_design.
We might want to both track differences between production runs
as well as channel designs, which can't be done here yet.
"""
with self.pg:
with self.pg.cursor() as cursor:
cursor.execute("SELECT uqds_channel_batch_id FROM uqds_channel_batches WHERE batch_key = %s",
cursor.execute("SELECT uqds_channel_batch_id FROM uqds_channel_batches "
"WHERE batch_key = %s",
[batch])
if cursor.rowcount == 0:
cursor.execute \
("INSERT INTO uqds_channel_batches (batch_key) VALUES (%s) RETURNING uqds_channel_batch_id",
("INSERT INTO uqds_channel_batches (batch_key)"
"VALUES (%s) RETURNING uqds_channel_batch_id",
[batch])
self.batch_id = cursor.fetchall()[0][0]
self.channel_ids = []
for i in range(len(channel_list)):
for i in enumerate(channel_list):
channel = channel_list[i]
cursor.execute("SELECT uqds_channel_sql_id "
"FROM uqds_channels "
......@@ -135,18 +160,19 @@ class UqdsDBHandler(TestbenchDBHandler):
RETURNING uqds_channel_sql_id
""", [str(channel), self.batch_id, channel_types[i]])
else:
print(f"Channel ID {channel} already exists in DB - are you re-testing a channel?")
print(f"Channel ID {channel} already exists in DB"
" - are you re-testing a channel?")
self.channel_ids.append(cursor.fetchall()[0][0])
@pgretry
def save_channel_results(self, event_data):
def _save_channel_results(self, event_data):
sweep = event_data['test_sweep']
channel_results = sweep.result_data
with self.pg:
with self.pg.cursor() as cursor:
for i in range(len(channel_results.channels)):
for i in enumerate(channel_results.channels):
channel = channel_results.channels[i]
result_id = self.channel_result_ids[i]
......@@ -161,14 +187,14 @@ class UqdsDBHandler(TestbenchDBHandler):
cursor.execute("REFRESH MATERIALIZED VIEW uqds_channel_results_latest")
@pgretry
def channel_sweep_start(self, event_data):
def _channel_sweep_start(self, event_data):
sweep = event_data['test_sweep']
with self.pg:
with self.pg.cursor() as cursor:
self.channel_result_ids = []
for i in range(len(self.channel_ids)):
for i in enumerate(self.channel_ids):
channel_id = self.channel_ids[i]
cursor.execute("""
......@@ -184,7 +210,7 @@ class UqdsDBHandler(TestbenchDBHandler):
self.channel_result_ids.append(cursor.fetchall()[0][0])
@pgretry
def testbench_sweep_update(self, event_data):
def _testbench_sweep_update(self, event_data):
acquisition_data = event_data['acquisition']
......@@ -198,12 +224,12 @@ class UqdsDBHandler(TestbenchDBHandler):
event_data['acquisition'] = acquisition_data
super().testbench_sweep_update(event_data)
super()._testbench_sweep_update(event_data)
with self.pg:
with self.pg.cursor() as cursor:
for ch_index in range(len(uqds_channels)):
ch = uqds_channels[ch_index]
for ch_index in enumerate(uqds_channels):
ch = uqds_channels[ch_index] # pylint: disable=invalid-name
cursor.execute("""
INSERT INTO uqds_channel_acquisitions (
uqds_channel_acquisition_id,
......@@ -218,9 +244,9 @@ class UqdsDBHandler(TestbenchDBHandler):
def handle_testbench_event(self, event_data):
super().handle_testbench_event(event_data)
et = event_data['type']
et = event_data['type'] # pylint: disable=invalid-name
if et == 'test_sweep_complete':
self.save_channel_results(event_data)
self._save_channel_results(event_data)
elif et == 'test_sweep_start':
self.channel_sweep_start(event_data)
self._channel_sweep_start(event_data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment