分析工具添加导出数据和分析结果html文件
This commit is contained in:
@@ -82,3 +82,7 @@
|
||||
2023.10.19
|
||||
分析工具在后台线程中下载检测数据
|
||||
解决特定情况下导出方案文件名日期不对的问题
|
||||
2023.10.20
|
||||
分析工具添加导出数据和分析结果html文件
|
||||
|
||||
|
||||
|
4
analysis/.gitignore
vendored
4
analysis/.gitignore
vendored
@@ -1 +1,3 @@
|
||||
*.json
|
||||
*.json
|
||||
*.zip
|
||||
*.rar
|
@@ -16,6 +16,7 @@ import scheme_data
|
||||
import numpy as np
|
||||
import threading
|
||||
import os
|
||||
import build_html
|
||||
|
||||
|
||||
plt.rcParams['font.sans-serif']=['SimHei']
|
||||
@@ -49,6 +50,7 @@ class QFigure(QObject):
|
||||
self.__ax.grid(visible=True,which="major",axis="y")
|
||||
self.__canvas.draw()
|
||||
def save(self,path:str,perfix:str):
|
||||
path=os.path.join(path,"pic")
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
name=os.path.join(path,perfix+self._title)
|
||||
@@ -103,7 +105,7 @@ class Analysis(QWidget):
|
||||
self.__import_but = QPushButton("导入方案",self)
|
||||
self.__import_but.clicked.connect(self.import_but_clicked)
|
||||
self.__import_but.setGeometry(QRect(0,0,100,27))
|
||||
self.__export_but = QPushButton("导出方案")
|
||||
self.__export_but = QPushButton("导出数据")
|
||||
self.__export_but.clicked.connect(self.export_but_clicked)
|
||||
|
||||
self.__scroll=QScrollArea(self)
|
||||
@@ -138,8 +140,8 @@ class Analysis(QWidget):
|
||||
self.__layout.addRow(figure.canvas(),tplayout.layout())
|
||||
figure.draw(range(len(data)),data,lable="原始值",limit_max=limit_max,limit_min=limit_min)
|
||||
figure.draw(dat_count,y,lable="权重")
|
||||
figure.save(self._save_path,str(self._item_index)+".")
|
||||
self.__items.append((figure,tplayout))
|
||||
# figure.save(self._save_path,str(self._item_index)+".")
|
||||
self.__items.append((figure,tplayout,self._item_index))
|
||||
self._item_index+=1
|
||||
def calc_item_end_slot(self,data:list):
|
||||
print("calc_item end.")
|
||||
@@ -214,11 +216,16 @@ class Analysis(QWidget):
|
||||
print("data recv end.")
|
||||
def export_but_clicked(self):
|
||||
ret_limit=[]
|
||||
ret_values=[]
|
||||
for i,t in zip(self.__items,self.titles):
|
||||
max=i[1].item_value(t+":LimitMax")
|
||||
min=i[1].item_value(t+":LimitMin")
|
||||
ret_limit.append((max,min))
|
||||
self.sch_data.export_scheme(ret_limit)
|
||||
ret_values.append(i[1].values())
|
||||
i[0].save(self._save_path,str(i[2])+".")
|
||||
self.sch_data.export_scheme(self._save_path,ret_limit)
|
||||
self.sch_data.export_check_data(self._save_path)
|
||||
build_html.html_build(self._save_path,self.titles,ret_values)
|
||||
# 运行程序
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
|
66
analysis/build_html.py
Normal file
66
analysis/build_html.py
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
import os
|
||||
|
||||
|
||||
|
||||
|
||||
_HTML_BASE="""
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>检测数据分析</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container" style="width:1300px">
|
||||
<table width="1300px">
|
||||
{items}
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
"""
|
||||
|
||||
_HTML_ITEM="""
|
||||
<tr>
|
||||
<td colspan="2" style="background-color:#FFA500;">
|
||||
<img src="pic/{pic_name}" alt="{pic_name}"></img>
|
||||
</td>
|
||||
<td colspan="2" style="background-color:#FFA500;" width="500px">
|
||||
{params}
|
||||
</td>
|
||||
</tr>
|
||||
"""
|
||||
|
||||
_HTML_PARAM="""
|
||||
<p>{name}:{value}</p>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
def html_build(path:str,pic_names:list,params:list):
|
||||
h_item=""
|
||||
index=0
|
||||
for pic,par in zip(pic_names,params):
|
||||
h_param=""
|
||||
h_param+=_HTML_PARAM.format(name="任务序号",value=index)
|
||||
for i in par:
|
||||
h_param+=_HTML_PARAM.format(name=i[0],value=i[1])
|
||||
pic_name='.'.join([str(index),pic,'png'])
|
||||
h_item+=_HTML_ITEM.format(pic_name=pic_name,params=h_param)
|
||||
index+=1
|
||||
html=_HTML_BASE.format(items=h_item)
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
save_name=os.path.join(path,"home.html")
|
||||
with open(save_name,"w+",encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
|
||||
# if __name__=="__main__":
|
||||
# html_add_item("30.充能时间.png",None)
|
@@ -252,24 +252,53 @@ class sch_data(object):
|
||||
data_list.append(t)
|
||||
db,cur=_connect_sql()
|
||||
if(db!=None):
|
||||
cmd="""SELECT id,create_time,addr,err_code,valuez FROM check_result_detail
|
||||
cmd="""SELECT id,create_time,addr,err_code,run,valuez FROM check_result_detail
|
||||
where create_time > %s and create_time < %s
|
||||
and result_id in (select pk from check_result where plan_id =%s) ;"""
|
||||
cur.execute(cmd,(self.date_start,self.date_end,scheme_id))
|
||||
check_data=cur.fetchall()
|
||||
for row in check_data:
|
||||
if(row[3]==0):
|
||||
s=row[4].split(',')
|
||||
s=row[5].split(',')
|
||||
for i in range(len(s)):
|
||||
data_list[i].append(int(s[i]))
|
||||
self._check_data=check_data
|
||||
self._titles=title
|
||||
return title,data_list,len(check_data)
|
||||
|
||||
def export_scheme(self,ret_limit):
|
||||
def export_check_data(self,path:str):
|
||||
if(self._check_data==None):
|
||||
return
|
||||
if(self._titles==None):
|
||||
return
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
save_name=self.scheme_name.split('/')[-1].split('.')[0]
|
||||
save_name=os.path.join(path,save_name)
|
||||
with open(save_name+".csv","w+") as f:
|
||||
title_list=["时间","错误码","执行结果"]
|
||||
title_list+=self._titles
|
||||
title_list.append('\n')
|
||||
s=','.join(title_list)
|
||||
f.write(s)
|
||||
for row in self._check_data:
|
||||
time=row[1].strftime("%Y-%m-%d %H:%M:%S")
|
||||
err=str(row[3])
|
||||
run="=\""+row[4]+"\""
|
||||
data=row[5]
|
||||
s=','.join([time,err,run,data,'\n'])
|
||||
f.write(s)
|
||||
print("export check data end.")
|
||||
|
||||
|
||||
def export_scheme(self,path:str,ret_limit):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
name=self.scheme_name
|
||||
info=_get_info()
|
||||
date=info[0]
|
||||
id=info[1]
|
||||
save_name=info[2]
|
||||
save_name=name.split('/')[-1].split('.')[0]
|
||||
quest=quest_text("请输入要导出的文件名",save_name)
|
||||
ack,save_name=quest.show()
|
||||
if(ack!=True):
|
||||
@@ -287,11 +316,14 @@ class sch_data(object):
|
||||
json_obj["PlanID"],sid=_reflush_scheme_id(json_obj["PlanID"])
|
||||
# 刷新方案id号之后更新日期
|
||||
date=_get_info()[0]
|
||||
# 保存到指定路径下
|
||||
save_name=os.path.join(path,save_name)
|
||||
save_name=save_name+"_"+date+"{d:02d}".format(d=sid)
|
||||
json_obj["PlanBrief"]=save_name
|
||||
json_str=json.dumps(json_obj, sort_keys=True, indent=4, separators=(',', ': '),ensure_ascii=False)
|
||||
save_f=open(save_name+".json",'+wb')
|
||||
save_f.write(json_str.encode("utf-8"))
|
||||
save_f.close()
|
||||
print("scheme export end.")
|
||||
if __name__ == "__main__":
|
||||
_main()
|
||||
|
52
updata/creat_jqslave_boot.py
Normal file
52
updata/creat_jqslave_boot.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import shutil
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
import prottcp
|
||||
|
||||
BOOT_PATH ="file/JQ_JCXB_V54.bin"
|
||||
APP_PATH ="file/jqcoder_slave_20230912--1.bin"
|
||||
SCHEME_PATH = "file/JQ硬件EX工厂注码090701--2.json"
|
||||
OUT_PATH = "file/coder_jqslave_boot.bin"
|
||||
|
||||
# 创建离线下载器的镜像
|
||||
|
||||
|
||||
# 填充指定个数的byte
|
||||
def arr_byte_copy(byte:int,num:int):
|
||||
t=bytearray()
|
||||
for i in range(num):
|
||||
t.append(byte)
|
||||
return t
|
||||
# int转数组
|
||||
def arr_from_int(num:int):
|
||||
return bytearray([num&0xff,(num>>8)&0xff,(num>>16)&0xff,(num>>24)&0xff])
|
||||
|
||||
|
||||
def creat():
|
||||
boot=BOOT_PATH
|
||||
app=APP_PATH
|
||||
scheme=SCHEME_PATH
|
||||
d=bytearray()
|
||||
with open(boot,"rb") as f:
|
||||
d+=f.read()
|
||||
d+=arr_byte_copy(0xff,0x2400-len(d))
|
||||
with open(app,"rb") as f:
|
||||
d+=f.read()
|
||||
d+=arr_byte_copy(0xff,0xf400-len(d))
|
||||
with open(scheme,"rb") as f:
|
||||
json_obj=json.loads(f.read())
|
||||
d+=prottcp.scheme_to_byte(json_obj)
|
||||
d+=arr_byte_copy(0xff,0xfc00-len(d))
|
||||
d+=arr_from_int(0x669955aa)
|
||||
with open(OUT_PATH,"wb+") as f:
|
||||
f.write(d)
|
||||
print(OUT_PATH+" create boot file success.")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
creat()
|
||||
|
||||
|
Reference in New Issue
Block a user