changes for testing

master
Varun 10 months ago
parent e99089a0a4
commit 756138fa97

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

@ -70,6 +70,7 @@ const tanksSchema = new mongoose.Schema({
water_level: { type: String, default: null }, water_level: { type: String, default: null },
manual_threshold_percentage: { type: String, default: "90" }, manual_threshold_percentage: { type: String, default: "90" },
manual_threshold_time: { type: String, default: null }, manual_threshold_time: { type: String, default: null },
stop_threshold_time: { type: String, default: null },
threshold_type: { type: String, default: "percentage" }, threshold_type: { type: String, default: "percentage" },
startTime: { type: String, default: null }, startTime: { type: String, default: null },
start_instance_id: { type: String, default: null }, start_instance_id: { type: String, default: null },

Loading…
Cancel
Save