|
|
@ -3002,7 +3002,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
console.log(motorId,"interval created")
|
|
|
|
console.log(motorId,"interval created")
|
|
|
|
console.log(customerId,req.body.from,req.body.from_type.toLowerCase())
|
|
|
|
console.log(customerId,req.body.from,req.body.from_type.toLowerCase())
|
|
|
|
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() });
|
|
|
|
console.log("up",supplierTank)
|
|
|
|
console.log("up",supplierTank)
|
|
|
|
console.log(supplierTank.waterlevel,"parseInt(supplierTank.waterlevel, 10)")
|
|
|
|
console.log(supplierTank.waterlevel,"parseInt(supplierTank.waterlevel, 10)")
|
|
|
|
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;
|
|
|
@ -3094,7 +3094,7 @@ console.log("up",supplierTank)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
$set: {
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
|
|
|
|
"connections.inputConnections.$.start_instance_id": null,
|
|
|
|
"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,
|
|
|
@ -3232,7 +3232,7 @@ console.log("up",supplierTank)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
$set: {
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
|
|
|
|
"connections.inputConnections.$.start_instance_id": null,
|
|
|
|
"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
|
|
|
@ -3302,6 +3302,7 @@ async function stopMotor(motorId, customerId, start_instance_id) {
|
|
|
|
{ $set: {
|
|
|
|
{ $set: {
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.stopTime": currentTime,
|
|
|
|
"connections.inputConnections.$.stopTime": currentTime,
|
|
|
|
|
|
|
|
"connections.inputConnections.$.start_instance_id": null,
|
|
|
|
"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
|
|
|
@ -6213,22 +6214,70 @@ async function processIotData(hw_Id, data) {
|
|
|
|
inputConnection.motor_on_type = "forced_manual";
|
|
|
|
inputConnection.motor_on_type = "forced_manual";
|
|
|
|
inputConnection.startTime = formattedTime;
|
|
|
|
inputConnection.startTime = formattedTime;
|
|
|
|
inputConnection.start_instance_id = startInstanceId;
|
|
|
|
inputConnection.start_instance_id = startInstanceId;
|
|
|
|
|
|
|
|
const newMotorData = new MotorData({
|
|
|
|
|
|
|
|
customerId:motorTank.customerId,
|
|
|
|
|
|
|
|
motor_id: hw_Id,
|
|
|
|
|
|
|
|
start_instance_id: startInstanceId,
|
|
|
|
|
|
|
|
supplierTank: inputConnection.inputConnections,
|
|
|
|
|
|
|
|
receiverTank: motorTank.tankName,
|
|
|
|
|
|
|
|
supplier_type: inputConnection.input_type,
|
|
|
|
|
|
|
|
receiver_type: motorTank.tankLocation,
|
|
|
|
|
|
|
|
startTime: formattedTime,
|
|
|
|
|
|
|
|
receiverInitialwaterlevel: parseInt(inputConnection.water_level, 10)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await newMotorData.save();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (inputConnection.motor_stop_status === "2" && status === 1) {
|
|
|
|
if (inputConnection.motor_stop_status === "2" && status === 1) {
|
|
|
|
|
|
|
|
const motorData = await MotorData.findOne({ customerId:motorTank.customerId, motor_id: hw_Id, start_instance_id: inputConnection.start_instance_id });
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
inputConnection.motor_stop_status = "1";
|
|
|
|
inputConnection.motor_stop_status = "1";
|
|
|
|
inputConnection.motor_on_type = "manual";
|
|
|
|
inputConnection.motor_on_type = "manual";
|
|
|
|
inputConnection.stopTime = currentTime;
|
|
|
|
inputConnection.stopTime = currentTime;
|
|
|
|
|
|
|
|
inputConnection.start_instance_id = null;
|
|
|
|
|
|
|
|
|
|
|
|
const motorId = hw_Id;
|
|
|
|
const motorId = hw_Id;
|
|
|
|
if (motorIntervals[motorId]) {
|
|
|
|
if (motorIntervals[motorId]) {
|
|
|
|
clearInterval(motorIntervals[motorId]);
|
|
|
|
clearInterval(motorIntervals[motorId]);
|
|
|
|
delete motorIntervals[motorId];
|
|
|
|
delete motorIntervals[motorId];
|
|
|
|
console.log("motor interval deleted")
|
|
|
|
console.log("motor interval deleted")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(motorData,"motorData")
|
|
|
|
|
|
|
|
if (motorData) {
|
|
|
|
|
|
|
|
console.log("got into if")
|
|
|
|
|
|
|
|
const receiverTank = await Tank.findOne({ customerId:motorTank.customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() });
|
|
|
|
|
|
|
|
const receiverFinalWaterLevel = parseInt(receiverTank.waterlevel, 10);
|
|
|
|
|
|
|
|
const quantityDelivered = receiverFinalWaterLevel - parseInt(motorData.receiverInitialwaterlevel, 10);
|
|
|
|
|
|
|
|
const water_pumped_till_now = parseInt(receiverTank.total_water_added_from_midnight, 10);
|
|
|
|
|
|
|
|
const totalwaterpumped = quantityDelivered + water_pumped_till_now;
|
|
|
|
|
|
|
|
const start = moment(motorData.startTime, 'DD-MMM-YYYY - HH:mm');
|
|
|
|
|
|
|
|
const stop = moment(currentTime, 'DD-MMM-YYYY - HH:mm');
|
|
|
|
|
|
|
|
const duration = moment.duration(stop.diff(start));
|
|
|
|
|
|
|
|
const runtime = Math.floor(duration.asMinutes()); // runtime in minutes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() },
|
|
|
|
|
|
|
|
{ $set: { total_water_added_from_midnight: totalwaterpumped } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await motorTank.save();
|
|
|
|
await MotorData.updateOne(
|
|
|
|
|
|
|
|
{ customerId, motor_id: motorId, start_instance_id: start_instance_id },
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$set: {
|
|
|
|
|
|
|
|
stopTime: currentTime,
|
|
|
|
|
|
|
|
receiverfinalwaterlevel: receiverFinalWaterLevel.toString(),
|
|
|
|
|
|
|
|
quantity_delivered: quantityDelivered.toString(),
|
|
|
|
|
|
|
|
runtime: runtime.toString()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`✅ Data processed successfully for hw_Id: ${hw_Id}`);
|
|
|
|
console.log(`✅ Data processed successfully for hw_Id: ${hw_Id}`);
|
|
|
|