521 lines
16 KiB
QML
521 lines
16 KiB
QML
import QtQuick
|
|
import QtQuick.Layouts
|
|
import QtQuick.Controls
|
|
import QtQuick.Shapes
|
|
import QtQuick.Dialogs
|
|
import "./app.js" as App
|
|
import "./common"
|
|
Rectangle
|
|
{
|
|
id: root
|
|
property var appId: App.appId
|
|
property var plusFile: App.plusFile
|
|
property var g_user: ""
|
|
property var g_product: ""
|
|
property var g_sn: "8441"
|
|
property var appPath: "/"+plusFile+"/"+appId+"/"
|
|
property var firstPath: ""
|
|
property var startDate: new Date()
|
|
property var startTime: startDate.getTime()
|
|
property var endTime: startDate.getTime()
|
|
property var g_PowerStat: []
|
|
property var g_VoltageThreshold: []
|
|
property var g_CurrentThreshold: []
|
|
property var g_settingGrafanaHost: ""
|
|
property var g_settingGrafanaPort: ""
|
|
property var g_settingGrafanaToken: ""
|
|
property var g_settingGrafanaDashboards: ""
|
|
property var g_settingGrafanaDashboardsUrl: ""
|
|
property var curTaskIndex: -1
|
|
property var task1State: "0"
|
|
property var task2State: "0"
|
|
property var task3State: "0"
|
|
property var task4State: "0"
|
|
property var task5State: "0"
|
|
property var task6State: "0"
|
|
|
|
property var task1Active: "1"
|
|
property var task2Active: "1"
|
|
property var task3Active: "1"
|
|
property var task4Active: "1"
|
|
property var task5Active: "1"
|
|
property var task6Active: "1"
|
|
property var reportJson: ({})
|
|
property var a_Digital: []
|
|
property var m_Digital: []
|
|
property var aw_Digital: []
|
|
property var mw_Digital: []
|
|
property var a_seri: []
|
|
property var m_seri: []
|
|
property var isFinish: true
|
|
property var isGsReady: a_seri.length > 0 || m_seri.length > 0
|
|
signal stopBd
|
|
Component.onCompleted: {
|
|
firstPath = common.firstPath()
|
|
g_user = common.getCurrentUser()
|
|
common.initAppScript(appId, "calibrate", "calibrate.py", plusFile)
|
|
setConfigInfo()
|
|
calibrate.startShima(firstPath + appPath)
|
|
}
|
|
onVisibleChanged: {
|
|
if(visible)
|
|
{
|
|
g_user = common.getCurrentUser()
|
|
}
|
|
}
|
|
gradient: Gradient {
|
|
GradientStop { position: 0.0; color: "#ecf3fb" } // 左上角颜色
|
|
GradientStop { position: 1.0; color: "#b7d6fb" } // 右上角颜色
|
|
orientation: Gradient.Horizontal
|
|
}
|
|
|
|
FontLoader {
|
|
id: customFontLoader
|
|
source: "./resource/PingFang SC Medium.ttf" // 字体文件的路径
|
|
}
|
|
Rectangle {
|
|
id: bar
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top
|
|
anchors.topMargin: 24
|
|
anchors.leftMargin: 23
|
|
anchors.rightMargin: 23
|
|
height: 45
|
|
radius: 9
|
|
property var currentIndex: 0
|
|
Row{
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.left: parent.left
|
|
anchors.leftMargin: 52
|
|
spacing: 80
|
|
QxTitleButton {
|
|
text: qsTr("标定")
|
|
isSelected: bar.currentIndex == 0
|
|
textColor: isSelected ? "#007EFF" : "#737373"
|
|
iconSource: isSelected ? "../resource/bd1.png"
|
|
: "../resource/bd0.png"
|
|
onClicked: bar.currentIndex = 0
|
|
}
|
|
// QxTitleButton {
|
|
// text: qsTr("数据可视化")
|
|
// isSelected: bar.currentIndex == 1
|
|
// textColor: isSelected ? "#007EFF" : "#737373"
|
|
// iconSource: isSelected ? "../resource/data1.png"
|
|
// : "../resource/data0.png"
|
|
// onClicked: bar.currentIndex = 1
|
|
// }
|
|
|
|
QxTitleButton {
|
|
text: qsTr("系统设置")
|
|
isSelected: bar.currentIndex == 2
|
|
textColor: isSelected ? "#007EFF" : "#737373"
|
|
iconSource: isSelected ? "../resource/set1.png"
|
|
: "../resource/set0.png"
|
|
onClicked: bar.currentIndex = 2
|
|
}
|
|
}
|
|
|
|
Row
|
|
{
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: 15
|
|
spacing: 13
|
|
Rectangle{
|
|
width: 62
|
|
height: 23
|
|
radius: 4
|
|
color: "#007EFF"
|
|
visible: true
|
|
QxText{
|
|
text:"日志转换"
|
|
font.pixelSize: 14
|
|
anchors.centerIn: parent
|
|
color: "#FFFFFF"
|
|
}
|
|
MouseArea{
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
fileLogDialog.visible = true
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle{
|
|
width: 62
|
|
height: 23
|
|
radius: 4
|
|
color: "#007EFF"
|
|
visible: isGsReady
|
|
QxText{
|
|
text:"公式"
|
|
font.pixelSize: 14
|
|
anchors.centerIn: parent
|
|
color: "#FFFFFF"
|
|
}
|
|
MouseArea{
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
formula.visible = true
|
|
}
|
|
}
|
|
}
|
|
Row{
|
|
spacing: 1
|
|
Image{
|
|
source: "./resource/user.png"
|
|
width: 18
|
|
height: 18
|
|
}
|
|
QxText{
|
|
text: "测试人员: " + g_user
|
|
}
|
|
}
|
|
Item{
|
|
width: 10
|
|
height: 18
|
|
Rectangle{
|
|
width: 1
|
|
height: 11
|
|
color: "#BFBFBF"
|
|
anchors.centerIn: parent
|
|
}
|
|
}
|
|
|
|
Row{
|
|
spacing: 1
|
|
Image{
|
|
source: "./resource/pname.png"
|
|
width: 18
|
|
height: 18
|
|
}
|
|
QxText{
|
|
text:"产品名称: " + g_product
|
|
}
|
|
}
|
|
Item{
|
|
width: 10
|
|
height: 18
|
|
Rectangle{
|
|
width: 1
|
|
height: 11
|
|
color: "#BFBFBF"
|
|
anchors.centerIn: parent
|
|
}
|
|
}
|
|
Row{
|
|
spacing: 1
|
|
Image{
|
|
source: "./resource/sn.png"
|
|
width: 18
|
|
height: 18
|
|
}
|
|
QxText{
|
|
text:"SN: " + g_sn
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
StackLayout {
|
|
id: layout
|
|
anchors.top: bar.bottom
|
|
anchors.bottom: parent.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.leftMargin: 23
|
|
anchors.rightMargin: 23
|
|
anchors.topMargin: 20
|
|
anchors.bottomMargin: 29
|
|
currentIndex: bar.currentIndex
|
|
Calibrate {id: cal}
|
|
DataAnalysis {}
|
|
SettingView{}
|
|
}
|
|
Formula{
|
|
id: formula
|
|
anchors.centerIn: parent
|
|
}
|
|
ListModel{
|
|
id: funcModel
|
|
}
|
|
ListModel{
|
|
id: taskModel
|
|
}
|
|
ListModel{
|
|
id: hmhzModel
|
|
}
|
|
ListModel{
|
|
id: tdModel
|
|
}
|
|
ListModel{
|
|
id: tempAModel
|
|
}
|
|
ListModel{
|
|
id: tempModel
|
|
}
|
|
|
|
FileDialog {
|
|
id: fileADialog
|
|
title: "请选择文件"
|
|
property var selectedIndex: -1
|
|
fileMode: FileDialog.OpenFile
|
|
nameFilters: [ "Xlsx files (*.xlsx)", "All files (*)" ]
|
|
onAccepted: {
|
|
var filePath = selectedFile.toString()
|
|
var path = filePath.replace("file:///","")
|
|
a_Digital = calibrate.readDXlsx(path)
|
|
cal.updateFormula()
|
|
}
|
|
onRejected: {
|
|
console.log("Canceled")
|
|
}
|
|
visible: false
|
|
}
|
|
|
|
property var logPath: ""
|
|
FileDialog {
|
|
id: fileLogDialog
|
|
title: "请选择日志文件"
|
|
property var selectedIndex: -1
|
|
fileMode: FileDialog.OpenFile
|
|
nameFilters: [ "Xlsx files (*.txt)", "All files (*)" ]
|
|
onAccepted: {
|
|
var filePath = selectedFile.toString()
|
|
logPath = filePath.replace("file:///","")
|
|
fileExportDialog.visible = true
|
|
}
|
|
onRejected: {
|
|
console.log("Canceled")
|
|
}
|
|
visible: false
|
|
}
|
|
|
|
FileDialog {
|
|
id: fileExportDialog
|
|
title: "请选择导出位置"
|
|
property var selectedIndex: -1
|
|
fileMode: FileDialog.SaveFile // 修改为 SaveFile 模式
|
|
nameFilters: [ "Csv files (*.csv)", "All files (*)" ]
|
|
defaultSuffix: "csv" // 设置默认文件后缀
|
|
currentFile: "exported_file.csv" // 设置默认文件名
|
|
onAccepted: {
|
|
var filePath = selectedFile.toString()
|
|
var path = filePath.replace("file:///","")
|
|
calibrate.writeALogCsv(logPath, path,["时间", "X轴加表输出", "Y轴加表输出", "Z轴加表输出", "X轴加表温度", "Y轴加表温度", "Z轴加表温度", "X轴磁通门输出", "Y轴磁通门输出", "Z轴磁通门输出", "磁通门温度输出", "a_tempb"])
|
|
|
|
}
|
|
onRejected: {
|
|
console.log("Canceled")
|
|
}
|
|
}
|
|
// Button{
|
|
// z: 100
|
|
// anchors.centerIn: parent
|
|
// width: 100
|
|
// height: 30
|
|
|
|
// onClicked: {
|
|
// initTest()
|
|
// }
|
|
// }
|
|
function initJsonModel(model, jsonFile) {
|
|
var data = get_json(jsonFile);
|
|
if (data) {
|
|
if (data.infos) {
|
|
model.clear();
|
|
for (var i = 0; i < data.infos.length; i++) {
|
|
model.append(data.infos[i]);
|
|
}
|
|
} else {
|
|
console.error("JSON file does not contain 'infos' property");
|
|
}
|
|
} else {
|
|
console.error("Failed to retrieve data from JSON file");
|
|
}
|
|
}
|
|
|
|
|
|
function updateJsonFile(model, jsonFile)
|
|
{
|
|
var data = []
|
|
var plainObject = {};
|
|
for (var i = 0; i < model.count; i++) {
|
|
var obj = model.get(i);
|
|
var plainObject = {};
|
|
for (var key in obj) {
|
|
plainObject[key] = obj[key];
|
|
}
|
|
data.push(plainObject);
|
|
}
|
|
save_json(jsonFile, {"infos":data})
|
|
}
|
|
function getFuncInstance(instructionName)
|
|
{
|
|
var funcInstance = {}
|
|
for(var i = 0; i < funcModel.count; i++)
|
|
{
|
|
if(funcModel.get(i).name == instructionName)
|
|
{
|
|
funcInstance = funcModel.get(i)
|
|
break
|
|
}
|
|
}
|
|
return funcInstance
|
|
}
|
|
|
|
function runNextStep()
|
|
{
|
|
var tempisFinish = true
|
|
var startIndex = curTaskIndex + 1
|
|
for(var i = startIndex; i < taskModel.count; i++)
|
|
{
|
|
if(taskModel.get(i).active == "1" && taskModel.get(i).state == "0")
|
|
{
|
|
tempisFinish = false
|
|
curTaskIndex = i
|
|
return
|
|
}
|
|
}
|
|
isFinish = tempisFinish
|
|
if (isFinish)
|
|
{
|
|
endTime = new Date().getTime()
|
|
var _firstPath = projectManager.getHistoryPath()
|
|
var filename = "REPORT_"+g_sn+ "_" + Qt.formatDateTime(new Date(startTime), "yyyy-MM-dd_hh-mm-ss") + ".xlsx"
|
|
var templateName = "report.xlsx"
|
|
reportJson["startTime"] = timestampToDateString(startTime)
|
|
reportJson["endTime"] = timestampToDateString(endTime)
|
|
reportJson["sn"] = g_sn
|
|
reportJson["user"] = g_user
|
|
console.info(JSON.stringify(reportJson))
|
|
calibrate.exportXlsx(firstPath + appPath + "/template/" + templateName, _firstPath + "/" + filename, reportJson)
|
|
}
|
|
}
|
|
|
|
function timestampToDateString(timestamp) {
|
|
var date = new Date(timestamp);
|
|
return Qt.formatDateTime(date, "yyyy-MM-dd hh:mm:ss");
|
|
}
|
|
|
|
function setConfigInfo()
|
|
{
|
|
var config = common.getConfig();
|
|
var grafanaInfo = config.grafana
|
|
g_settingGrafanaHost = grafanaInfo.host
|
|
g_settingGrafanaPort = grafanaInfo.port
|
|
g_settingGrafanaToken = "Bearer " + grafanaInfo.token
|
|
g_settingGrafanaDashboards = grafanaInfo.dashboards
|
|
}
|
|
|
|
function overwrite_xlsx(templateName, fileName, xlsxData)
|
|
{
|
|
var _firstPath = projectManager.getHistoryPath()
|
|
|
|
calibrate.overWriteXlsx(firstPath + appPath + "/template/" + templateName, _firstPath + "/" + fileName, xlsxData)
|
|
}
|
|
|
|
function save_csv(fileName, csvData)
|
|
{
|
|
var _firstPath = projectManager.getHistoryPath()
|
|
calibrate.writeCsv(_firstPath + "/" + fileName, csvData)
|
|
}
|
|
|
|
function save_json(fileName, jsonObj)
|
|
{
|
|
calibrate.setJson(firstPath + appPath + fileName, jsonObj)
|
|
}
|
|
|
|
function get_json(fileName)
|
|
{
|
|
return calibrate.getJson(firstPath + appPath + fileName)
|
|
}
|
|
|
|
function execute(instructionName, param={})
|
|
{
|
|
var funcInstance = getFuncInstance(instructionName)
|
|
var attr = {
|
|
"deviceId": funcInstance.deviceId,
|
|
"param": JSON.stringify(param),
|
|
"interfaceIndex": funcInstance.interfaceIndex
|
|
}
|
|
taskActuatorManager.startInstruction(funcInstance.instructionId, attr)
|
|
return funcInstance.instructionId
|
|
}
|
|
|
|
function stopExecute(instructionId)
|
|
{
|
|
taskActuatorManager.stopInstruction(instructionId)
|
|
}
|
|
|
|
function executeVirtualTask(taskName, instructionNames)
|
|
{
|
|
var taskInfo = {
|
|
"id": taskName,
|
|
"name": taskName,
|
|
"type": 1,
|
|
}
|
|
var instructions = []
|
|
for(var i = 0; i < instructionNames.length; i++)
|
|
{
|
|
var funcInstance = getFuncInstance(instructionNames[i])
|
|
instructions.push({
|
|
"id": instructionNames[i] + funcInstance.instructionId, // 无意义,避免重复
|
|
"target_id": funcInstance.instructionId,
|
|
"device_id": funcInstance.deviceId,
|
|
"task_id" : "",
|
|
"interface_index": funcInstance.interfaceIndex,
|
|
"target_type": "instruction",
|
|
"delay": 0,
|
|
"loop": 1,
|
|
"target_param": ""
|
|
})
|
|
}
|
|
console.info("instructionNames:",instructionNames, JSON.stringify(instructions))
|
|
taskActuatorManager.startVirtual(taskInfo, instructions)
|
|
return taskInfo.id
|
|
}
|
|
|
|
// 更新Grafana bucket
|
|
function updateGrafana()
|
|
{
|
|
var url = "http://" + g_settingGrafanaHost + ":" + g_settingGrafanaPort
|
|
var data = calibrate.get_dashboard_uid(url,g_settingGrafanaToken,g_settingGrafanaDashboards)
|
|
if(data)
|
|
{
|
|
if (data.length == 1)
|
|
{
|
|
var uid = data[0].uid
|
|
g_settingGrafanaDashboardsUrl = data[0].url
|
|
console.info("g_settingGrafanaDashboardsUrl: " + g_settingGrafanaDashboardsUrl)
|
|
calibrate.update_dashboard_data(uid,url,g_settingGrafanaToken)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 更新Grafana Time
|
|
function updateGrafanaTime(start, stop)
|
|
{
|
|
var url = "http://" + g_settingGrafanaHost + ":" + g_settingGrafanaPort
|
|
var data = calibrate.get_dashboard_uid(url,g_settingGrafanaToken,g_settingGrafanaDashboards)
|
|
if(data)
|
|
{
|
|
if (data.length == 1)
|
|
{
|
|
var uid = data[0].uid
|
|
g_settingGrafanaDashboardsUrl = data[0].url
|
|
calibrate.update_dashboard_time(uid, url,g_settingGrafanaToken,start, stop)
|
|
}
|
|
}
|
|
}
|
|
|
|
function initTest()
|
|
{
|
|
var templateName = "calculation.xlsx"
|
|
calibrate.setHmhzParams(firstPath + appPath + "/template/" + templateName,{"inc": 180, "gtf": 180})
|
|
}
|
|
}
|
|
|
|
|