mirror of
https://github.com/xiaozhou233/RiverWaterQualityMonitoring.git
synced 2026-12-05 13:05:53 +08:00
优化获取数据逻辑,修改为获取最新100条数据并使用deque提高性能
This commit is contained in:
1 parent
3714df7495
commit
1059400b7e
1 file changed
+5
-4
+5
-4
@@ -1,5 +1,6 @@
|
||||
import csv
|
||||
import os
|
||||
from collections import deque
|
||||
|
||||
###
|
||||
DATA_FILE = "database.csv"
|
||||
@@ -22,9 +23,9 @@ def insert_data(time, ph, tds, turbidity):
|
||||
|
||||
writer.writerow([time, ph, tds, turbidity])
|
||||
|
||||
# 获取所有数据
|
||||
def get_data():
|
||||
data = []
|
||||
# 获取最新100条数据
|
||||
def get_data(limit=100):
|
||||
data = deque(maxlen=limit)
|
||||
|
||||
try:
|
||||
with open(DATA_FILE, "r", newline="", encoding="utf-8") as file:
|
||||
@@ -45,7 +46,7 @@ def get_data():
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
|
||||
return data
|
||||
return list(data)
|
||||
|
||||
# 获取最新数据
|
||||
def get_last_data():
|
||||
|
||||
Reference in new issue
Block a user