SQL: Fix date and time save and load format.

This commit is contained in:
parouby committed 2025-03-26 15:27:25 +01:00
1 parent 9c7e621a45
commit 57108455ce
3 files changed
+27 -33

No files matched your search

+3 -5
View File
@@ -313,11 +313,9 @@ class CreateTableForSaveAs:
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
( (
stg.acoustic_data[i], #stg.date[i], stg.hour[i], stg.acoustic_data[i],
str(stg.date[i].year) + str('-') stg.date[i].isoformat(),
+ str(stg.date[i].month) + str('-') stg.hour[i].isoformat(),
+ str(stg.date[i].day),
str(stg.hour[i].hour) + str(':') + str(stg.hour[i].minute),
stg.freq[i][j], stg.freq[i][j],
stg.water_attenuation[i][j], stg.water_attenuation[i][j],
stg.kt_read[j], stg.kt_corrected[j], stg.kt_read[j], stg.kt_corrected[j],
+22 -19
View File
@@ -26,6 +26,8 @@ import sqlite3
import logging import logging
import numpy as np import numpy as np
from datetime import date, time
from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget, QTabWidget from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget, QTabWidget
import settings as stg import settings as stg
@@ -137,7 +139,7 @@ class ReadTableForOpen:
stg.hour = [0]*len(stg.acoustic_data) stg.hour = [0]*len(stg.acoustic_data)
for i in range(len(stg.acoustic_data)): for i in range(len(stg.acoustic_data)):
query1 = f''' query = f'''
SELECT SELECT
acoustic_data, Date, Hour, frequency, acoustic_data, Date, Hour, frequency,
sound_attenuation, kt_read, kt_corrected, NbProfiles, sound_attenuation, kt_read, kt_corrected, NbProfiles,
@@ -147,38 +149,38 @@ class ReadTableForOpen:
FROM Measure FROM Measure
WHERE (acoustic_data = {i}) 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.date[i] = date.fromisoformat(data[0][1])
stg.hour[i] = data1[0][2] stg.hour[i] = time.fromisoformat(data[0][2])
stg.freq.append( stg.freq.append(
np.array([x[3] for x in data1]) np.array([x[3] for x in data])
) )
stg.freq_text.append( 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( 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_read = [x[5] for x in data]
stg.kt_corrected = [x[6] for x in data1] stg.kt_corrected = [x[6] for x in data]
stg.nb_profiles.append([x[7] 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 data1]) stg.nb_profiles_per_sec.append([x[8] for x in data])
stg.nb_cells.append([x[9] for x in data1]) stg.nb_cells.append([x[9] for x in data])
stg.cell_size.append([x[10] for x in data1]) stg.cell_size.append([x[10] for x in data])
stg.pulse_length.append([x[11] for x in data1]) stg.pulse_length.append([x[11] for x in data])
stg.nb_pings_per_sec.append( 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( 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_rx.append([x[14] for x in data])
stg.gain_tx.append([x[15] for x in data1]) stg.gain_tx.append([x[15] for x in data])
logger.debug("measure:") logger.debug("measure:")
logger.debug(f"- stg.acoustic_data: {stg.acoustic_data}") logger.debug(f"- stg.acoustic_data: {stg.acoustic_data}")
@@ -540,6 +542,7 @@ class ReadTableForOpen:
+ list(stg.radius_grain_sand) + list(stg.radius_grain_sand)
) )
@trace
def read_table_table_sediment_data(self): def read_table_table_sediment_data(self):
np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64) np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64)
+2 -9
View File
@@ -147,15 +147,8 @@ class UpdateTableForSave:
) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
( (
stg.acoustic_data[i], stg.acoustic_data[i],
( stg.date[i].isoformat(),
str(stg.date[i].year) + str('-') + stg.hour[i].isoformat(),
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.freq[i][j],
stg.water_attenuation[i][j], stg.water_attenuation[i][j],
stg.kt_read[j], stg.kt_read[j],