update fakedata

This commit is contained in:
lb
2023-09-10 21:44:05 +08:00
parent f13e543c0a
commit aba16e68c2
5 changed files with 73 additions and 18 deletions

View File

@@ -9,6 +9,18 @@
"topTemperature": "...℃",
"meltTemperature": "...℃"
},
"energyCost": {
"restHeat": "***kWh",
"water": "+++Km³",
"electricity": "+++kWh",
"gasi": "...m³",
"gasii": "...m³"
},
"runState": {
"lastFireChangeTime": "3分28秒",
"fireChangeTime": "04:00",
"fireDirection": "东火"
},
"fan": [
["8#压延冷却风机", "4373Hz", "正常"],
["7#压延冷却风机", "4772Hz", "正常"],

View File

@@ -3,7 +3,7 @@ import demoData from './demo.json';
import utils from './utils';
const wss = new WebSocketServer({ port: 9800 });
const frequency = 3; // seconds
const frequency = 10; // seconds
wss.on('connection', function (ws, req) {
// console.log("ws", ws);
console.log(
@@ -26,10 +26,12 @@ wss.on('connection', function (ws, req) {
const timer = setInterval(() => {
sendMsg(ws, 'kiln-info'); // 窑炉信息
sendMsg(ws, 'fan');
sendMsg(ws, 'gas');
sendMsg(ws, 'kiln-top');
sendMsg(ws, 'kiln-bottom');
sendMsg(ws, 'run-state'); // 运行状态
sendMsg(ws, 'energy-cost'); // 运行状态
// sendMsg(ws, 'fan');
// sendMsg(ws, 'gas');
// sendMsg(ws, 'kiln-top');
// sendMsg(ws, 'kiln-bottom');
}, frequency * 1000);
ws.on('close', function () {
@@ -38,7 +40,14 @@ wss.on('connection', function (ws, req) {
});
});
type MsgType = 'kiln-info' | 'fan' | 'gas' | 'kiln-top' | 'kiln-bottom';
type MsgType =
| 'kiln-info'
| 'run-state'
| 'energy-cost'
| 'fan'
| 'gas'
| 'kiln-top'
| 'kiln-bottom';
function sendMsg(ws: WebSocket, type: MsgType) {
let data: {
@@ -52,6 +61,16 @@ function sendMsg(ws: WebSocket, type: MsgType) {
);
}
break;
case 'energy-cost':
for (const key in demoData.energyCost) {
data[key] = utils.getRandom(
demoData.energyCost[key as keyof typeof demoData.energyCost],
);
}
break;
case 'run-state':
data = demoData.runState;
break;
case 'fan':
// data = demoData.fan;
break;