|
|
|
@ -2036,8 +2036,7 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
"connections.inputConnections.$.stopTime": req.body.stopTime,
|
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
|
|
"connections.inputConnections.$.manual_threshold_percentage": null,
|
|
|
|
|
"connections.inputConnections.$.stop_threshold_time": null
|
|
|
|
|
"connections.inputConnections.$.manual_threshold_percentage": null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
@ -2104,7 +2103,6 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
// Update the tank connections with start time and threshold time
|
|
|
|
|
for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) {
|
|
|
|
|
this.publishMotorStopStatus(motorId, motorStopStatus);
|
|
|
|
|
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
|
|
|
|
|
for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) {
|
|
|
|
|
const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId);
|
|
|
|
|
if (index !== -1) {
|
|
|
|
@ -2115,36 +2113,28 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
[`connections.inputConnections.${index}.manual_threshold_time`]: req.body.manual_threshold_time,
|
|
|
|
|
[`connections.inputConnections.${index}.threshold_type`]: "time",
|
|
|
|
|
[`connections.inputConnections.${index}.startTime`]: req.body.startTime,
|
|
|
|
|
[`connections.inputConnections.${index}.start_instance_id`]: start_instance_id ,
|
|
|
|
|
[`connections.inputConnections.${index}.stop_threshold_time`]: thresholdTime,
|
|
|
|
|
[`connections.inputConnections.${index}.start_instance_id`]: start_instance_id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
|
|
|
|
|
console.log(thresholdTime,"at start")
|
|
|
|
|
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
|
|
|
|
|
const intervalId = setInterval(async () => {
|
|
|
|
|
const supplierTank = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
|
|
|
|
|
const currentWaterLevel = parseInt(supplierTank.waterlevel, 10);
|
|
|
|
|
const currentWaterPercentage = (currentWaterLevel / parseInt(supplierTank.capacity.replace(/,/g, ''), 10)) * 100;
|
|
|
|
|
const receiverTank1 = await Tank.findOne({ customerId, tankName: req.body.to, tankLocation: req.body.to_type.toLowerCase() });
|
|
|
|
|
const stop_threshold_time = receiverTank1.connections.inputConnections[stop_threshold_time]
|
|
|
|
|
if (moment().isSameOrAfter(stop_threshold_time) || currentWaterPercentage <= lowWaterThreshold) {
|
|
|
|
|
console.log(thresholdTime,"thresholdtime")
|
|
|
|
|
console.log(new Date(),"new time")
|
|
|
|
|
console.log(currentWaterPercentage,"currentWaterPercentage")
|
|
|
|
|
console.log(lowWaterThreshold,"lowWaterThreshold")
|
|
|
|
|
|
|
|
|
|
if (new Date() >= thresholdTime || currentWaterPercentage <= lowWaterThreshold) {
|
|
|
|
|
console.log("motor stopping because it entered this condition")
|
|
|
|
|
await Tank.updateOne(
|
|
|
|
|
{ customerId, "connections.inputConnections.motor_id": motorId },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
|
|
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
|
"connections.inputConnections.$.stop_threshold_time": null,
|
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
|
|
"connections.inputConnections.$.manual_threshold_percentage": null
|
|
|
|
|
}
|
|
|
|
|