SQL: Some refactoring.

dev-brahim
Pierre-Antoine 2025-03-10 17:12:45 +01:00
parent f5eb9a18c6
commit 87098ff152
1 changed files with 154 additions and 135 deletions

View File

@ -38,7 +38,8 @@ class CreateTableForSaveAs:
def __init__(self): def __init__(self):
self.create_AcousticFile = """CREATE TABLE AcousticFile( self.create_AcousticFile = """
CREATE TABLE AcousticFile(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER, acoustic_data INTEGER,
acoustic_file STRING, acoustic_file STRING,
@ -51,7 +52,8 @@ class CreateTableForSaveAs:
) )
""" """
self.create_Measure = """ CREATE TABLE Measure( self.create_Measure = """
CREATE TABLE Measure(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER, acoustic_data INTEGER,
Date DATE, Date DATE,
@ -72,32 +74,44 @@ class CreateTableForSaveAs:
) )
""" """
self.create_BSRawData = '''CREATE TABLE BSRawData( self.create_BSRawData = """
CREATE TABLE BSRawData(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER, acoustic_data INTEGER,
time BLOB, depth BLOB, BS_raw_data BLOB, time BLOB, depth BLOB, BS_raw_data BLOB,
time_reshape BLOB, depth_reshape BLOB, BS_raw_data_reshape BLOB, time_reshape BLOB, depth_reshape BLOB, BS_raw_data_reshape BLOB,
time_cross_section BLOB, depth_cross_section BLOB, BS_cross_section BLOB, BS_stream_bed BLOB, time_cross_section BLOB, depth_cross_section BLOB,
BS_cross_section BLOB, BS_stream_bed BLO B,
depth_bottom, val_bottom, ind_bottom, depth_bottom, val_bottom, ind_bottom,
time_noise BLOB, depth_noise BLOB, BS_noise_raw_data BLOB, time_noise BLOB, depth_noise BLOB, BS_noise_raw_data BLOB,
SNR_raw_data BLOB, SNR_cross_section BLOB, SNR_stream_bed BLOB, SNR_raw_data BLOB, SNR_cross_section BLOB, SNR_stream_bed BLOB,
BS_raw_data_pre_process_SNR BLOB, BS_raw_data_pre_process_average BLOB, BS_raw_data_pre_process_SNR BLOB,
BS_cross_section_pre_process_SNR BLOB, BS_cross_section_pre_process_average BLOB, BS_raw_data_pre_process_average BLOB,
BS_stream_bed_pre_process_SNR BLOB, BS_stream_bed_pre_process_average BLOB, BS_cross_section_pre_process_SNR BLOB,
BS_cross_section_pre_process_average BLOB,
BS_stream_bed_pre_process_SNR BLOB,
BS_stream_bed_pre_process_average BLOB,
BS_mean BLOB BS_mean BLOB
)''' )
"""
self.create_Settings = '''CREATE TABLE Settings( self.create_Settings = """
CREATE TABLE Settings(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER, acoustic_data INTEGER,
temperature FLOAT, temperature FLOAT,
tmin_index FLOAT, tmin_value FLOAT, tmax_index FLOAT, tmax_value FLOAT, tmin_index FLOAT, tmin_value FLOAT,
rmin_index FLOAT, rmin_value FLOAT, rmax_index FLOAT, rmax_value FLOAT, tmax_index FLOAT, tmax_value FLOAT,
freq_bottom_detection_index FLOAT, freq_bottom_detection_value STRING, rmin_index FLOAT, rmin_value FLOAT,
rmax_index FLOAT, rmax_value FLOAT,
freq_bottom_detection_index FLOAT,
freq_bottom_detection_value STRING,
SNR_filter_value FLOAT, Nb_cells_to_average_BS_signal FLOAT SNR_filter_value FLOAT, Nb_cells_to_average_BS_signal FLOAT
)''' )
"""
self.create_SedimentsFile = """CREATE TABLE SedimentsFile( self.create_SedimentsFile = """
CREATE TABLE SedimentsFile(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
path_fine STRING, path_fine STRING,
filename_fine STRING, filename_fine STRING,
@ -115,7 +129,8 @@ class CreateTableForSaveAs:
) )
""" """
self.create_SedimentsData = """CREATE TABLE SedimentsData( self.create_SedimentsData = """
CREATE TABLE SedimentsData(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
sample_fine_name STRING, sample_fine_name STRING,
sample_fine_index INTEGER, sample_fine_index INTEGER,
@ -140,7 +155,8 @@ class CreateTableForSaveAs:
) )
""" """
self.create_Calibration = """CREATE TABLE Calibration( self.create_Calibration = """
CREATE TABLE Calibration(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
path_calibration_file STRING, path_calibration_file STRING,
filename_calibration_file STRING, filename_calibration_file STRING,
@ -154,16 +170,19 @@ class CreateTableForSaveAs:
FCB BLOB, FCB BLOB,
depth_real BLOB, depth_real BLOB,
lin_reg BLOB lin_reg BLOB
)""" )
"""
self.create_Inversion = """CREATE TABLE Inversion( self.create_Inversion = """
CREATE TABLE Inversion(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
J_cross_section_freq1 BLOB, J_cross_section_freq1 BLOB,
J_cross_section_freq2 BLOB, J_cross_section_freq2 BLOB,
VBI_cross_section BLOB, VBI_cross_section BLOB,
SSC_fine BLOB, SSC_fine BLOB,
SSC_sand BLOB SSC_sand BLOB
)""" )
"""
self.open_file_dialog() self.open_file_dialog()
@ -240,7 +259,7 @@ class CreateTableForSaveAs:
logger.debug(f"stg.path_BS_raw_data: {stg.path_BS_raw_data[i]}") logger.debug(f"stg.path_BS_raw_data: {stg.path_BS_raw_data[i]}")
cur.execute( cur.execute(
''' """
INSERT into AcousticFile( INSERT into AcousticFile(
acoustic_data, acoustic_data,
acoustic_file, acoustic_file,
@ -251,7 +270,7 @@ class CreateTableForSaveAs:
noise_value, noise_value,
data_preprocessed) data_preprocessed)
VALUES(?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.acoustic_data[i], stg.acoustic_data[i],
stg.filename_BS_raw_data[i].split('.')[0], stg.filename_BS_raw_data[i].split('.')[0],
@ -282,7 +301,7 @@ class CreateTableForSaveAs:
for i in stg.acoustic_data: for i in stg.acoustic_data:
for j in range(stg.freq[i].shape[0]): for j in range(stg.freq[i].shape[0]):
cur.execute( cur.execute(
''' """
INSERT into Measure( INSERT into Measure(
acoustic_data, acoustic_data,
Date, Hour, Date, Hour,
@ -297,7 +316,7 @@ class CreateTableForSaveAs:
GainRx, GainTx GainRx, GainTx
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.acoustic_data[i], #stg.date[i], stg.hour[i], stg.acoustic_data[i], #stg.date[i], stg.hour[i],
str(stg.date[i].year) + str('-') str(stg.date[i].year) + str('-')
@ -331,7 +350,7 @@ class CreateTableForSaveAs:
for i in stg.acoustic_data: for i in stg.acoustic_data:
cur.execute( cur.execute(
''' """
INSERT into BSRawData( INSERT into BSRawData(
acoustic_data, acoustic_data,
time, depth, time, depth,
@ -351,7 +370,7 @@ class CreateTableForSaveAs:
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.acoustic_data[i], stg.time[i].tobytes(), stg.acoustic_data[i], stg.time[i].tobytes(),
stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(), stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(),
@ -399,7 +418,7 @@ class CreateTableForSaveAs:
for i in stg.acoustic_data: for i in stg.acoustic_data:
cur.execute( cur.execute(
''' """
INSERT into Settings( INSERT into Settings(
acoustic_data, temperature, acoustic_data, temperature,
tmin_index, tmin_value, tmax_index, tmax_value, tmin_index, tmin_value, tmax_index, tmax_value,
@ -408,7 +427,7 @@ class CreateTableForSaveAs:
SNR_filter_value, Nb_cells_to_average_BS_signal SNR_filter_value, Nb_cells_to_average_BS_signal
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.acoustic_data[i], stg.temperature, stg.acoustic_data[i], stg.temperature,
stg.tmin[i][0], stg.tmin[i][1], stg.tmin[i][0], stg.tmin[i][1],
@ -435,7 +454,7 @@ class CreateTableForSaveAs:
if stg.path_fine != "" and path_sand != "": if stg.path_fine != "" and path_sand != "":
cur.execute( cur.execute(
''' """
INSERT into SedimentsFile( INSERT into SedimentsFile(
path_fine, filename_fine, radius_grain_fine, path_fine, filename_fine, radius_grain_fine,
path_sand, filename_sand, radius_grain_sand, path_sand, filename_sand, radius_grain_sand,
@ -445,7 +464,7 @@ class CreateTableForSaveAs:
Ctot_sand_column_label, D50_sand_column_label Ctot_sand_column_label, D50_sand_column_label
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.path_fine, stg.filename_fine, stg.path_fine, stg.filename_fine,
stg.radius_grain_fine.tobytes(), stg.radius_grain_fine.tobytes(),
@ -472,7 +491,7 @@ class CreateTableForSaveAs:
for f in range(len(stg.sample_fine)): for f in range(len(stg.sample_fine)):
cur.execute( cur.execute(
''' """
INSERT into SedimentsData( INSERT into SedimentsData(
sample_fine_name, sample_fine_index, sample_fine_name, sample_fine_index,
distance_from_bank_fine, distance_from_bank_fine,
@ -487,7 +506,7 @@ class CreateTableForSaveAs:
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.sample_fine[f][0] , stg.sample_fine[f][1], stg.sample_fine[f][0] , stg.sample_fine[f][1],
stg.distance_from_bank_fine[f], stg.depth_fine[f], stg.distance_from_bank_fine[f], stg.depth_fine[f],
@ -517,7 +536,7 @@ class CreateTableForSaveAs:
if len(stg.range_lin_interp) != 0: if len(stg.range_lin_interp) != 0:
cur.execute( cur.execute(
''' """
INSERT into Calibration( INSERT into Calibration(
path_calibration_file, filename_calibration_file, path_calibration_file, filename_calibration_file,
range_lin_interp, M_profile_fine, range_lin_interp, M_profile_fine,
@ -525,7 +544,7 @@ class CreateTableForSaveAs:
FCB, depth_real, lin_reg FCB, depth_real, lin_reg
) )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', """,
( (
stg.path_calibration_file, stg.filename_calibration_file, stg.path_calibration_file, stg.filename_calibration_file,
stg.range_lin_interp.tobytes(), stg.range_lin_interp.tobytes(),
@ -552,13 +571,13 @@ class CreateTableForSaveAs:
for i in range(len(stg.SSC_fine)): for i in range(len(stg.SSC_fine)):
cur.execute( cur.execute(
''' """
INSERT into Inversion( INSERT into Inversion(
J_cross_section_freq1, J_cross_section_freq2, J_cross_section_freq1, J_cross_section_freq2,
VBI_cross_section, SSC_fine, SSC_sand VBI_cross_section, SSC_fine, SSC_sand
) )
VALUES(?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?)
''', """,
( (
stg.J_cross_section[i][0].tobytes(), stg.J_cross_section[i][0].tobytes(),
stg.J_cross_section[i][1].tobytes(), stg.J_cross_section[i][1].tobytes(),