我有一個 MySQL 資料庫(使用 MySQL 作業臺),有兩個表(ecg_pat_tbl 和 ecg_data_tbl),并將浮點值、日期和時間分別發送到列電壓、日期和時間,并且還同時繪制圖表(電壓對時間),一切進展順利,現在我想檢索電壓和時間值并將它們保存到不同的陣列中,以便我可以使用它們進行分析,我該如何檢索和保存它們?下面的代碼是我用來繪制并保存到資料庫的函式。
data =[]
_condition = False
amount = 0
def graphing():
global _condition, data
if (_condition == True):
try:
identity = identity_var.get() # Getting patient ID
date_time=datetime.datetime.now()
my_time='{}:{}:{}'.format(date_time.hour,date_time.minute,date_time.second)
my_date='{}/{}/{}'.format(date_time.year, date_time.month,date_time.day)
serial_data = _serial.readline()
serial_data.decode()
float_data = float(serial_data[0:4])
query = "INSERT INTO ecg_data_tbl(patient_id, voltage, date, time) VALUES(%s, %s, %s, %s)"
mycursor.execute(query, (identity, float_data, my_date, my_time))
mycursor.execute("commit")
data.append(float_data)
ax.plot(data, color="blue")
canvas.draw_idle()
except ValueError as e:
_condition = False
start_button['state'] = NORMAL
freeze_button['state'] = DISABLED
save_button['state'] = DISABLED
insert_button['state'] = DISABLED
messagebox.showinfo("Connection", "Check connnection of the patient cable")
感謝所有的回應。
uj5u.com熱心網友回復:
如果我錯了,請糾正我,但似乎您唯一的問題是從格式游標的回傳值中解壓縮值:(time_0, volt_0), (time_1, volt_1), .... 代碼應該是這樣的。
query = "SELECT time, voltage FROM ecg_data_tbl WHERE patient_id=?"
result = cursor.execute(query, (identity,)).fetchall()
# (time_0, volt_0), (time_1, volt_1), ...
times, volts = list(zip(*result))
# (time_0, time_1, ...), (volt_0, volt_1, ...)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/344143.html
上一篇:在tkinter樹視圖中合并節點
下一篇:在螢屏底部發送訊息文本欄位
