明树Git Lab

Commit baf81c20 authored by zfp1's avatar zfp1

update

parent 344a472e
......@@ -202,7 +202,7 @@ async function getJiankong(req, res, next) {
let onlineArr = await deviceModule.getDeviceOnlineMap();
smc.onLineState = onlineArr.includes(smc.deviceNumber) ? "1" : "0";
ws.onLineState = onlineArr.includes(ws.deviceNumber) ? "1" : "0";
traccode.smc = smc;
traccode.smc = handleSMCObjForSuYuan(smc);
traccode.ws = ws;
traccode.onlineArr = onlineArr;
}
......
......@@ -99,7 +99,7 @@ function handleSMCDataForDP(data) {
for (let index = 0; index < data.length; index++) {
let element = data[index];
for (const key in element) {
if(range[key]) {
if (range[key]) {
element[key] = adjustToRange(element[key] || 0, range[key])
}
}
......@@ -111,6 +111,24 @@ function handleSMCDataForDP(data) {
}
}
function handleSMCObjForSuYuan(obj) {
let range = {
soilTemperature: getSeasonTemperature(),
soilMoisture: getSeasonMois(),
nitrogen: [60, 150],
phosphorus: [10, 50],
potassium: [80, 200],
soilPH: [4.5, 6.5],
soilConductivity: [100, 600],
}
for (const key in obj) {
if (range[key]) {
obj[key] = adjustToRange(obj[key] || 0, range[key])
}
}
return obj;
}
function getSeasonTemperature() {
let m = new Date().getMonth() + 1;
if ([5, 6, 7, 8, 9].includes(m)) {
......@@ -137,9 +155,9 @@ function adjustToRange(n, [min, max]) {
if (n >= min && n <= max) {
v = n;
} else {
v = Math.random() * (max - min) + min;
v = Math.random() * (max - min) + min;
}
v = Math.round(v * 100) / 100;
v = Math.round(v * 100) / 100;
return _.isInteger(v) ? parseInt(v) : v;
}
......
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