# coding=utf-8
import sys
import time
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit, QMainWindow, QTextBrowser
from tinydb import TinyDB, where
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.paths = "" # ==> 默认文本内容
self.path = None
self.setWindowTitle('文件拖入V1.2') # ==> 窗口标题
self.resize(500, 400) # ==> 定义窗口大小
self.textBrowser = QTextBrowser()
self.setCentralWidget(self.textBrowser) # ==> 定义窗口主题内容为textBrowser
self.setAcceptDrops(True) # ==> 设置窗口支持拖动(必须设置)
# 鼠标拖入事件
def dragEnterEvent(self, event):
self.setWindowTitle('dragEnterEvent')
file = event.mimeData().urls()[0].toLocalFile() # ==> 获取文件路径
if file not in self.paths: # ==> 去重显示
self.path = file
self.textBrowser.clear()
self.paths = "选择了文件:" + file
self.textBrowser.setText(self.paths)
# 鼠标放开函数事件
event.accept()
self.unpack()
def unpack(self):
db = TinyDB(self.path)
save_db = db.table("data")
data = save_db.all()
self.textBrowser.append("该文件有%s条数据" % len(data))
# last_time = 0
# count_time_out = 0
for v in range(4):
vv = v + 1
vs = save_db.search(where("radar_id") == vv)
last_number = 0
count_lose = 0
for i in vs:
# struct_time = time.strptime(time_str, '%Y-%m-%d %H:%M:%S')
if 0 < i["frame_number"] < 65535 and 0 < last_number < 65535:
if i["frame_number"] - last_number == 1:
pass
else:
count_lose += 1
last_number = i["frame_number"]
self.textBrowser.append("设备%i丢了《%s》条数据(总数据量%s条)\n" % (vv, count_lose, len(vs)))
# times = i["time"].split('.')
# struct_time = time.strptime("2023-05-30 " + times[0], '%Y-%m-%d %H:%M:%S')
# timestamp = time.mktime(struct_time) + int(times[1]) / 1000000
# if last_time > 0:
# cz = timestamp - last_time
# if cz > 0.15:
# self.textBrowser.append("%s数据超时%s \n" % (i, cz))
# count_time_out += 1
# last_time = timestamp
#
# self.textBrowser.append("丢了《%s》条数据\n" % count_lose)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())
版权说明
本文地址:http://www.liuyangdeboke.cn/?post=58
未标注转载均为本站远程,转载请注明文章出处:
发表评论