From 57108455ce4784e270b286f72d7f608b44e57af3 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 26 Mar 2025 14:52:20 +0100 Subject: [PATCH] SQL: Fix date and time save and load format. --- Model/create_table_for_save_as.py | 8 +++--- Model/read_table_for_open.py | 41 +++++++++++++++++-------------- Model/update_table_for_save.py | 11 ++------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Model/create_table_for_save_as.py b/Model/create_table_for_save_as.py index ef12041..3ee9696 100644 --- a/Model/create_table_for_save_as.py +++ b/Model/create_table_for_save_as.py @@ -313,11 +313,9 @@ class CreateTableForSaveAs: VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( - stg.acoustic_data[i], #stg.date[i], stg.hour[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.acoustic_data[i], + stg.date[i].isoformat(), + stg.hour[i].isoformat(), stg.freq[i][j], stg.water_attenuation[i][j], stg.kt_read[j], stg.kt_corrected[j], diff --git a/Model/read_table_for_open.py b/Model/read_table_for_open.py index 0302580..1364332 100644 --- a/Model/read_table_for_open.py +++ b/Model/read_table_for_open.py @@ -26,6 +26,8 @@ import sqlite3 import logging import numpy as np +from datetime import date, time + from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget, QTabWidget import settings as stg @@ -137,7 +139,7 @@ class ReadTableForOpen: stg.hour = [0]*len(stg.acoustic_data) for i in range(len(stg.acoustic_data)): - query1 = f''' + query = f''' SELECT acoustic_data, Date, Hour, frequency, sound_attenuation, kt_read, kt_corrected, NbProfiles, @@ -147,38 +149,38 @@ class ReadTableForOpen: FROM Measure WHERE (acoustic_data = {i}) ''' - data1 = self.execute(query1) + data = self.execute(query) - logger.debug(f"data1 for {i}: {data1}") + logger.debug(f"data for {i}: {data}") - stg.date[i] = data1[0][1] - stg.hour[i] = data1[0][2] + stg.date[i] = date.fromisoformat(data[0][1]) + stg.hour[i] = time.fromisoformat(data[0][2]) stg.freq.append( - np.array([x[3] for x in data1]) + np.array([x[3] for x in data]) ) stg.freq_text.append( - [str(x[3]*1e-6) + 'MHz' for x in data1] + [str(x[3]*1e-6) + 'MHz' for x in data] ) stg.water_attenuation.append( - [x[4] for x in data1] + [x[4] for x in data] ) - stg.kt_read = [x[5] for x in data1] - stg.kt_corrected = [x[6] for x in data1] + stg.kt_read = [x[5] for x in data] + stg.kt_corrected = [x[6] for x in data] - stg.nb_profiles.append([x[7] for x in data1]) - stg.nb_profiles_per_sec.append([x[8] for x in data1]) - stg.nb_cells.append([x[9] for x in data1]) - stg.cell_size.append([x[10] for x in data1]) - stg.pulse_length.append([x[11] for x in data1]) + stg.nb_profiles.append([x[7] for x in data]) + stg.nb_profiles_per_sec.append([x[8] for x in data]) + stg.nb_cells.append([x[9] for x in data]) + stg.cell_size.append([x[10] for x in data]) + stg.pulse_length.append([x[11] for x in data]) stg.nb_pings_per_sec.append( - [x[12] for x in data1] + [x[12] for x in data] ) stg.nb_pings_averaged_per_profile.append( - [x[13] for x in data1] + [x[13] for x in data] ) - stg.gain_rx.append([x[14] for x in data1]) - stg.gain_tx.append([x[15] for x in data1]) + stg.gain_rx.append([x[14] for x in data]) + stg.gain_tx.append([x[15] for x in data]) logger.debug("measure:") logger.debug(f"- stg.acoustic_data: {stg.acoustic_data}") @@ -540,6 +542,7 @@ class ReadTableForOpen: + list(stg.radius_grain_sand) ) + @trace def read_table_table_sediment_data(self): np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64) diff --git a/Model/update_table_for_save.py b/Model/update_table_for_save.py index 336473d..97d887c 100644 --- a/Model/update_table_for_save.py +++ b/Model/update_table_for_save.py @@ -147,15 +147,8 @@ class UpdateTableForSave: ) 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.date[i].isoformat(), + stg.hour[i].isoformat(), stg.freq[i][j], stg.water_attenuation[i][j], stg.kt_read[j],