Commit 98e737d6 by 吴斌

update:分析结果显示

parent c0665cb0
......@@ -22,6 +22,7 @@
</div>
<div class="flex">
<div class="w-full"></div>
<el-button @click="changeData">数据变化</el-button>
<el-button @click="importData">导入</el-button>
<el-button type="primary" @click="exportData">导出</el-button>
</div>
......@@ -159,7 +160,7 @@ function initDiagram() {
GO(go.TextBlock, {margin: 4, text: "", editable: true, alignment: go.Spot.Top},
new go.Binding("text", "press"),
new go.Binding("stroke", "",
function(data,_node) { return data.press>10?"red":"green"}
function(data,_node) { return data.press>50?"red":"green"}
),
new go.Binding('angle', "angle", v=>-v),
),
......@@ -326,16 +327,24 @@ function analyseData(){
function changeData(){
let model = myDiagram.model
setInterval(()=>{
let nodeDataArray = myDiagram.model.nodeDataArray
nodeDataArray.forEach((item:any)=>{
if (item.picture_category === "ammonia"){
model.set(item, "press", Math.floor(Math.random()*100))
model.set(item, "thick", Math.random().toFixed(2)),
let nodeDataArray = myDiagram.model.nodeDataArray
nodeDataArray.forEach((item:any)=>{
if (item.picture_category === "ammonia"){
model.set(item, "press", Math.floor(Math.random()*100))
model.set(item, "thick", Math.random().toFixed(2)),
model.set(item, "temperature", Math.floor(Math.random()*10))
}
})
},5000)
}
})
// setInterval(()=>{
// let nodeDataArray = myDiagram.model.nodeDataArray
// nodeDataArray.forEach((item:any)=>{
// if (item.picture_category === "ammonia"){
// model.set(item, "press", Math.floor(Math.random()*100))
// model.set(item, "thick", Math.random().toFixed(2)),
// model.set(item, "temperature", Math.floor(Math.random()*10))
// }
// })
// },5000)
}
onMounted(() => {
......
<template>
<div>
<div class="text-center" v-show="paths.length === 0">暂无分析数据</div>
<div v-show="paths.length > 0">
<div>线路结果</div>
<div v-show="paths.length === 0">暂无分析数据</div>
<div v-show="paths.length > 0" >
<div class="mb-2 mt-0 text-xl font-medium leading-tight text-primary">线路结果</div>
<el-scrollbar max-height="200px">
<el-collapse>
<el-collapse-item class="m-2" v-for="(value, key) in pathNodesMap" :title="'线路' + key ">
......@@ -14,14 +14,16 @@
</el-form>
<div class="flex justify-center">
<el-checkbox @change="highlightPath(key)" v-model="value.highlight">高亮</el-checkbox>
<el-button type="primary">确定</el-button>
<el-button type="primary" @click="computeData(pathNodesMap, analyzeResult)" class="ml-4">确定</el-button>
</div>
</el-collapse-item>
</el-collapse>
</el-scrollbar>
<div>分析结果</div>
<div class="w-full h-26 bg-red-200">
<div class="w-full h-32 bg-red-200">
<div class="mb-2 mt-0 text-xl font-medium leading-tight text-primary">分析结果</div>
<div v-for="(value, key) in analyzeResult" class="flex">
<div>{{nodeMap[key].data.name}}: {{value}}</div>
</div>
</div>
</div>
</div>
......@@ -30,7 +32,7 @@
<script setup lang="ts">
import {ref, watch} from "vue";
import { highlightLink, cancelHighlightLink } from "../../kit/GOJSKit";
import {highlightLink, cancelHighlightLink, computeData} from "../../kit/GOJSKit";
const props = defineProps({
paths: {
......@@ -47,6 +49,7 @@ const props = defineProps({
})
let pathNodesMap = ref<Record<string, any>>({})
let analyzeResult = ref<any>({})
watch(()=>props.paths, (newValue) => {
newValue.forEach((path:any) => {
......@@ -57,9 +60,10 @@ watch(()=>props.paths, (newValue) => {
pathNodeName.push(props.nodeMap[node].data.name)
})
pathNodesMap.value[newValue.indexOf(path)+1] = {
'nodeKeys':path, 'nodesName': pathNodeName, "nodes": pathNode, 'highlight': false, 'weight': 1
'nodeKeys':path, 'nodesName': pathNodeName, "nodes": pathNode, 'highlight': false, 'weight': 1/props.paths.length
}
})
computeData(pathNodesMap.value, analyzeResult)
});
function highlightPath(pathIndex:string){
......@@ -72,8 +76,5 @@ function highlightPath(pathIndex:string){
}
}
function computeData(){
}
</script>
\ No newline at end of file
import { log } from 'console';
import go from 'gojs';
export var GO = go.GraphObject.make;
......@@ -167,4 +166,52 @@ export function cancelHighlightLink(myDiagram:any){
linkDataArray.forEach((item:any)=>{
model.set(item, "color", "black")
})
}
\ No newline at end of file
}
/**
* 这里只以计算压力数据为例。
*/
export function computeData(pathNodesMap:any, analyzeResult:any){
let nodesDataMap:Record<any, any> = {}
let offset = 0.1
console.log("compute", pathNodesMap);
for (let key in pathNodesMap){
let path = pathNodesMap[key]
console.log(path.nodeKeys)
for (let node of path.nodes){
if (node.data.key in nodesDataMap){
let currentNodeIndex = path.nodes.indexOf(node)
if (currentNodeIndex == 0){
continue
}
let lastNode = path.nodes[currentNodeIndex-1]
nodesDataMap[node.data.key]['predict'] += lastNode.data.press * path.weight
console.log("predict", nodesDataMap[node.data.key]['predict'], lastNode.data.press, path.weight);
}
else{
nodesDataMap[node.data.key] = {'predict': 0, 'real': node.data.press}
let currentNodeIndex = path.nodes.indexOf(node)
if (currentNodeIndex == 0){
nodesDataMap[node.data.key]['predict'] = node.data.press
continue
}
let lastNode = path.nodes[currentNodeIndex-1]
nodesDataMap[node.data.key]['predict'] += lastNode.data.press * path.weight
}
}
}
analyzeResult.value = {}
for (let key in nodesDataMap){
let value = nodesDataMap[key]
if(value['predict'] < value['real']*(1-offset)){
analyzeResult.value[key] = "压力过高"
}
else if(value['predict'] > value['real']*(1+offset)){
analyzeResult.value[key] = "压力过低"
}
else{
analyzeResult.value[key] = "压力正常"
}
}
return nodesDataMap
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment