Fix save method on existing file #16.

dev-brahim
Pierre-Antoine 2025-03-06 14:33:30 +01:00
parent b26d8a2906
commit 17619f15ac
1 changed files with 62 additions and 32 deletions

View File

@ -104,42 +104,72 @@ class UpdateTableForSave:
# Drop Table if exists # Drop Table if exists
cur.execute("DROP TABLE if exists Measure") cur.execute("DROP TABLE if exists Measure")
cur.execute("""CREATE TABLE Measure(ID INTEGER PRIMARY KEY AUTOINCREMENT, cur.execute(
acoustic_data INTEGER, """
Date STRING, CREATE TABLE Measure(
Hour STRING, ID INTEGER PRIMARY KEY AUTOINCREMENT,
frequency FLOAT, acoustic_data INTEGER,
sound_attenuation FLOAT, Date STRING,
kt_read FLOAT, Hour STRING,
kt_corrected FLOAT, frequency FLOAT,
NbProfiles FLOAT, sound_attenuation FLOAT,
NbProfilesPerSeconds FLOAT, kt_read FLOAT,
NbCells FLOAT, kt_corrected FLOAT,
CellSize FLOAT, NbProfiles FLOAT,
PulseLength FLOAT, NbProfilesPerSeconds FLOAT,
NbPingsPerSeconds FLOAT, NbCells FLOAT,
NbPingsAveragedPerProfile FLOAT, CellSize FLOAT,
GainRx FLOAT, PulseLength FLOAT,
GainTx FLOAT NbPingsPerSeconds FLOAT,
) NbPingsAveragedPerProfile FLOAT,
""") GainRx FLOAT,
GainTx FLOAT
)"""
)
# Fill the table Measure # Fill the table Measure
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(''' INSERT into Measure(acoustic_data, Date, Hour, frequency, sound_attenuation, kt_read, kt_corrected, NbProfiles, cur.execute(
NbProfilesPerSeconds, NbCells, CellSize, PulseLength, '''
NbPingsPerSeconds, NbPingsAveragedPerProfile, GainRx, GainTx, INSERT into Measure(
) acoustic_data,
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', Date, Hour,
(stg.acoustic_data[i], stg.freq[i][j], stg.water_attenuation[i][j], stg.kt_read[j], stg.kt_corrected[j], frequency,
stg.nb_profiles[i][j], stg.nb_profiles_per_sec[i][j], stg.nb_cells[i][j], sound_attenuation,
stg.cell_size[i][j], stg.pulse_length[i][j], stg.nb_pings_per_sec[i][j], kt_read, kt_corrected,
stg.nb_pings_averaged_per_profile[i][j], stg.gain_rx[i][j], stg.gain_tx[i][j], NbProfiles, NbProfilesPerSeconds,
str(stg.date[i].year) + str('-') + str(stg.date[i].month) + str('-') + str(stg.date[i].day), NbCells, CellSize,
str(stg.hour[i].hour) + str(':') + str(stg.hour[i].minute) PulseLength,
)) NbPingsPerSeconds,
NbPingsAveragedPerProfile,
GainRx, GainTx
) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(
stg.acoustic_data[i],
(
str(stg.date[i].year) + str('-') +
str(stg.date[i].month) + str('-') +
str(stg.date[i].day)
),
(
str(stg.hour[i].hour) + str(':') +
str(stg.hour[i].minute)
),
stg.freq[i][j],
stg.water_attenuation[i][j],
stg.kt_read[j],
stg.kt_corrected[j],
stg.nb_profiles[i][j],
stg.nb_profiles_per_sec[i][j],
stg.nb_cells[i][j],
stg.cell_size[i][j],
stg.pulse_length[i][j],
stg.nb_pings_per_sec[i][j],
stg.nb_pings_averaged_per_profile[i][j],
stg.gain_rx[i][j], stg.gain_tx[i][j]
)
)
# Commit the transaction after executing INSERT. # Commit the transaction after executing INSERT.
cnx.commit() cnx.commit()