Handle contactors separately in daily_report
This commit is contained in:
parent
7093d765ec
commit
c5c5b21f47
10 changed files with 427 additions and 242 deletions
|
|
@ -112,7 +112,7 @@ exports.install = function(instance) {
|
|||
priorities["75"] = minutes; // current
|
||||
priorities["79"] = minutes; // energy
|
||||
priorities["87"] = minutes; // aktualny cas
|
||||
//priorities["84"] = minutes;
|
||||
//priorities["84"] = minutes; //accelerometer
|
||||
|
||||
minutes = 10;
|
||||
priorities["74"] = minutes; // voltage
|
||||
|
|
@ -195,14 +195,17 @@ exports.install = function(instance) {
|
|||
customTasksInterval = setInterval(reportEdgeDateTimeAndNumberOfLuminaires, 120_000);
|
||||
setTimeout(reportEdgeDateTimeAndNumberOfLuminaires, 4000);
|
||||
|
||||
//dailyReport related
|
||||
//NOTE: dailyReport related
|
||||
emptyReportToSend();
|
||||
// we handle "contactor" key separately in reportToSend
|
||||
reportToSend["contactor"] = { off: [], on: [] };
|
||||
breakerCounter = Object.keys(relaysData).length - 1; // we get number of lines (breakers) except of line 0
|
||||
rvoPeriod = setInterval(setRvoPeriod, SET_RVO_PERIOD_TIME);
|
||||
setTimeout(setRvoPeriod, 3000);
|
||||
setInterval(setSunCalcResult, SET_SUNCALC_RESULT_TIME);
|
||||
handleDailyReport = setInterval(dailyReportHandler, DAILY_REPORT_HANDLER_TIME);
|
||||
|
||||
//if dawn, we empty "contactor" key in reportToSend
|
||||
setInterval(emptyContactorDataInReport, 60000);
|
||||
|
||||
setCorrectTime = setInterval(setCorrectPlcTimeOnceADay, 60000 * 60); // 1 hour
|
||||
setCorrectPlcTimeOnceADay();
|
||||
|
|
@ -1342,51 +1345,69 @@ exports.install = function(instance) {
|
|||
|
||||
const now = Date.now();
|
||||
|
||||
if (rvo_is_on) {
|
||||
for (const [key, value] of Object.entries(dailyReport)) {
|
||||
|
||||
for (const [key, value] of Object.entries(dailyReport)) {
|
||||
if (["name", "time", "dusk_and_dawn"].includes(key)) continue;
|
||||
|
||||
if (["name", "time", "dusk_and_dawn"].includes(key)) continue;
|
||||
let poleNumber = nodesData[key]["pole_number"];
|
||||
let line = dailyReport[key].line;
|
||||
let nodeType = nodesData[key]["node_type"];
|
||||
let fullNodeName = key // key == nodeNumber
|
||||
|
||||
if (poleNumber && nodeType) {
|
||||
fullNodeName = SETTINGS.rvo_number + "/" + poleNumber + "_" + line + "L_" + key + "_" + nodeType;
|
||||
} else {
|
||||
fullNodeName = key;
|
||||
}
|
||||
|
||||
if (rvo_is_on) {
|
||||
|
||||
if (value.initialTs) {
|
||||
if (value.initialTs + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["night_no_data"], key);
|
||||
console.log('report nedostava ziadne data uz hodinu', key);
|
||||
addToArrayIfUnique(reportToSend["night_no_data"], fullNodeName);
|
||||
console.log('report nedostava ziadne data uz hodinu', fullNodeName);
|
||||
value.initialTs = now;
|
||||
}
|
||||
}
|
||||
if (value.dimmingAndPowerAreZeroTime) {
|
||||
if (value.dimmingAndPowerAreZeroTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["night_dimming=0"], key);
|
||||
console.log("report node dimming je 0", key);
|
||||
value.dimmingAndPowerAreZeroTime = now;
|
||||
if (value.dimmingIsZeroTime) {
|
||||
if (value.dimmingIsZeroTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["night_dimming=0"], fullNodeName);
|
||||
console.log("report node dimming je 0 ale ma svietit", fullNodeName);
|
||||
value.dimmingIsZeroTime = now;
|
||||
}
|
||||
}
|
||||
if (value.powerIsZeroTime) {
|
||||
if (value.powerIsZeroTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["night_power=0"], fullNodeName);
|
||||
console.log("report node power je 0 ale ma svietit", fullNodeName);
|
||||
value.powerIsZeroTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
} else {
|
||||
|
||||
for (const [key, value] of Object.entries(dailyReport)) {
|
||||
|
||||
if (["name", "time", "dusk_and_dawn"].includes(key)) continue;
|
||||
|
||||
let nodeIsOnLine = dailyReport[key].line;
|
||||
let contactorStatus = relaysData[nodeIsOnLine].contactor;
|
||||
let contactorStatus = relaysData[line].contactor;
|
||||
if (contactorStatus === 1) {
|
||||
|
||||
if (value.initialTs) {
|
||||
if (value.initialTs + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["day_24/7_no_data"], key);
|
||||
console.log('node je na 24/7 ale nedostava ziadne data uz hodinu', key);
|
||||
addToArrayIfUnique(reportToSend["day_24/7_no_data"], fullNodeName);
|
||||
console.log('node je na 24/7 ale nedostava ziadne data uz hodinu', fullNodeName);
|
||||
value.initialTs = now;
|
||||
}
|
||||
}
|
||||
if (value.nodeIsOnButShouldBeOffTime) {
|
||||
if (value.nodeIsOnButShouldBeOffTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["day_24/7_dimming>0"], key);
|
||||
console.log("report nema svietit ale svieti viac ako hodinu", key);
|
||||
value.nodeIsOnButShouldBeOffTime = now;
|
||||
if (value.dimmingIsOnButShouldBeOffTime) {
|
||||
if (value.dimmingIsOnButShouldBeOffTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["day_24/7_dimming>0"], fullNodeName);
|
||||
console.log("report dimming je > 0 ale nema svietit", fullNodeName);
|
||||
value.dimmingIsOnButShouldBeOffTime = now;
|
||||
}
|
||||
}
|
||||
if (value.powerIsOnButShouldBeOffTime) {
|
||||
if (value.powerIsOnButShouldBeOffTime + ADD_NODE_TO_REPORT_TIME < now) {
|
||||
addToArrayIfUnique(reportToSend["day_24/7_power>0"], fullNodeName);
|
||||
console.log("report power je > 0 ale nema svietit", fullNodeName);
|
||||
value.powerIsOnButShouldBeOffTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1408,6 +1429,8 @@ exports.install = function(instance) {
|
|||
|
||||
function dailyReportHandler() {
|
||||
|
||||
if (!SETTINGS.daily_report) return;
|
||||
|
||||
// after dawn we empty reportToSend and start to get data for a new day
|
||||
const date = new Date();
|
||||
const hour = date.getHours();
|
||||
|
|
@ -1432,6 +1455,10 @@ exports.install = function(instance) {
|
|||
initialReportStatus = true;
|
||||
|
||||
// ak sa funkcia spusti o hodinu alebo 2 neskor, ako je usvit (moze sa to stat, kedze kazde zapnutie/vypnutie linii odznova spusti casovac.
|
||||
// TODO: usvit bol 7:11, posledna "reportHandler" bola 6:55. Spustila sa podmienka5. Dalsi "reportHandler mal byt 7:55, ale 7:41 sa vypli linie (teda "reportHandler" sa pusti az o hodinu 8:41),
|
||||
// ale kedze uzivatel zapol linie o 8:30, posunulo sa "reportHandlovanie" na 9:30. Kedze v tento moment sa reportToSend vymazava (podmienka 3),
|
||||
// tak zapnutie linii pouzivatelom o 8:30 sa do reportu nikdy nedostane
|
||||
// preco nevymazavam reportToSend hned po usvite ??? (asi preto ze sa moze stat ze rvo ma stale zapnute linie a stane sa ze do reportu na dalsi den sa dostanu nody, ktore tam nemaju co robit!!!
|
||||
} else if (hour === sunCalcResult.dawn_hours + 1 || hour === sunCalcResult.dawn_hours + 2) {
|
||||
if (!initialReportStatus) {
|
||||
emptyReportToSend();
|
||||
|
|
@ -1453,17 +1480,30 @@ exports.install = function(instance) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
//We empty reportToSend object, but we want to keep contactor data for a current day
|
||||
function emptyReportToSend() {
|
||||
emptyJsObject(reportToSend);
|
||||
reportToSend["contactor"] = { off: [], on: [] };
|
||||
Object.keys(reportToSend).forEach(key => { if (key !== "contactor") delete jsObject[key] });
|
||||
reportToSend["night_no_data"] = [];
|
||||
reportToSend["night_dimming=0"] = [];
|
||||
reportToSend["night_power=0"] = [];
|
||||
reportToSend["day_24/7_no_data"] = [];
|
||||
reportToSend["day_24/7_dimming>0"] = [];
|
||||
//console.log(`je ${sunCalcResult.dawn_hours}:${sunCalcResult.dawn_minutes}, resetuje sa reportToSend: `, reportToSend);
|
||||
reportToSend["day_24/7_power>0"] = [];
|
||||
console.log(`resetuje sa reportToSend`);
|
||||
}
|
||||
|
||||
|
||||
// to have proper contactor data in report for a current day, we empty it when dawn is reached:
|
||||
function emptyContactorDataInReport() {
|
||||
const d = new Date();
|
||||
if (sunCalcResult.dawn_hours === d.getHours() && sunCalcResult.dawn_minutes === d.getMinutes()) {
|
||||
delete reportToSend.contactor;
|
||||
reportToSend["contactor"] = { off: [], on: [] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//NOTE: ked je initialTs stale rovnaky a zistime ze linie su vypnute (relaysData.line.contactor) - zistim, ci je node na tej linii. Vieme, ze ak je linia vypnuta je to v poriadku lebo nie je na 24/7 linii
|
||||
//ak je na 24/7 linii, reportujeme, ze neprijima data
|
||||
function emptyDailyReport() {
|
||||
|
|
@ -1500,12 +1540,6 @@ exports.install = function(instance) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!rsPort.isOpen) {
|
||||
instance.send(SEND_TO.debug, "!rsPort.isOpen");
|
||||
//await rsPort.open();
|
||||
//console.log("Cmd-mngr: !rsPort.isOpen");
|
||||
}
|
||||
|
||||
let currentTask = tasks[0];
|
||||
|
||||
if (currentTask.debug) {
|
||||
|
|
@ -1560,7 +1594,7 @@ exports.install = function(instance) {
|
|||
date.setDate(date.getDate() + 1);//next day
|
||||
|
||||
let sunCalcResult;
|
||||
if (timePointName) { sunCalcResult = calculateDuskDawn(date, params.line); console.log("typee-rellay: ", sunCalcResult.dawn_time, sunCalcResult.dusk_time); }
|
||||
if (timePointName) sunCalcResult = calculateDuskDawn(date, params.line);
|
||||
|
||||
|
||||
if (timePointName == "dawn") {
|
||||
|
|
@ -1615,6 +1649,7 @@ exports.install = function(instance) {
|
|||
// state_of_braker: disconnected = true?
|
||||
|
||||
if (!rsPort.isOpen) {
|
||||
console.log("Cmd-mngr: rsPort is not opened in runTasks", params);
|
||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1717,36 +1752,70 @@ exports.install = function(instance) {
|
|||
values.status = "OK";
|
||||
nodesData[node].readout = { ...nodesData[node].readout, ...values };
|
||||
|
||||
//TODO: co ak nedostavame odpovede z nodu ? Musime vyreportovat!!
|
||||
//v dailyReport teda musi byt kompletny zoznam nodov a neustale kontrolovat, ci maju data, ak nie report node - neodpoveda
|
||||
if (register === 1 || register === 76) {
|
||||
|
||||
let now = Date.now();
|
||||
if (SETTINGS.daily_report) {
|
||||
//TODO: co ak nedostavame odpovede z nodu ? Musime vyreportovat!!
|
||||
//v dailyReport teda musi byt kompletny zoznam nodov a neustale kontrolovat, ci maju data, ak nie report node - neodpoveda
|
||||
if (register === 1) {
|
||||
|
||||
if (rvo_is_on === true) {
|
||||
let now = Date.now();
|
||||
|
||||
if ("nodeIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].nodeIsOnButShouldBeOffTime;
|
||||
if (rvo_is_on === true) {
|
||||
|
||||
if ("dimmingIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].dimmingIsOnButShouldBeOffTime;
|
||||
|
||||
if (values.dimming > 0) {
|
||||
if ("dimmingIsZeroTime" in dailyReport[node]) delete dailyReport[node].dimmingIsZeroTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if (!("dimmingIsZeroTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], dimmingIsZeroTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
}
|
||||
|
||||
if (values.dimming > 0 || values.power > 0) {
|
||||
if ("dimmingAndPowerAreZeroTime" in dailyReport[node]) delete dailyReport[node].dimmingAndPowerAreZeroTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if (!("dimmingAndPowerAreZeroTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], dimmingAndPowerAreZeroTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
|
||||
if ("dimmingIsZeroTime" in dailyReport[node]) delete dailyReport[node].dimmingIsZeroTime;
|
||||
|
||||
if (values.dimming > 0) {
|
||||
if (!("dimmingIsOnButShouldBeOffTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], dimmingIsOnButShouldBeOffTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if ("dimmingIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].dimmingIsOnButShouldBeOffTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (register === 76) {
|
||||
|
||||
if ("dimmingAndPowerAreZeroTime" in dailyReport[node]) delete dailyReport[node].dimmingAndPowerAreZeroTime;
|
||||
let now = Date.now();
|
||||
|
||||
if (rvo_is_on === true) {
|
||||
|
||||
if ("powerIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].powerIsOnButShouldBeOffTime;
|
||||
|
||||
if (values.power > 1) {
|
||||
if ("powerIsZeroTime" in dailyReport[node]) delete dailyReport[node].powerIsZeroTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if (!("powerIsZeroTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], powerIsZeroTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
}
|
||||
|
||||
if (values.dimming > 0 || values.power > 0) {
|
||||
if (!("nodeIsOnButShouldBeOffTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], nodeIsOnButShouldBeOffTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if ("nodeIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].nodeIsOnButShouldBeOffTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
}
|
||||
|
||||
if ("powerIsZeroTime" in dailyReport[node]) delete dailyReport[node].powerIsZeroTime;
|
||||
|
||||
if (values.power > 1) {
|
||||
if (!("powerIsOnButShouldBeOffTime" in dailyReport[node])) dailyReport[node] = { ...dailyReport[node], powerIsOnButShouldBeOffTime: now, initialTs: now };
|
||||
else dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
} else {
|
||||
if ("powerIsOnButShouldBeOffTime" in dailyReport[node]) delete dailyReport[node].powerIsOnButShouldBeOffTime;
|
||||
dailyReport[node] = { ...dailyReport[node], initialTs: now };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1989,6 +2058,8 @@ exports.install = function(instance) {
|
|||
|
||||
function setRvoPeriod() {
|
||||
|
||||
if (!SETTINGS.daily_report) return;
|
||||
|
||||
const ts = Date.now();
|
||||
|
||||
previous_rvo_is_on_value = rvo_is_on;
|
||||
|
|
@ -2489,11 +2560,11 @@ exports.install = function(instance) {
|
|||
// v relaysData je contactor bud 0 alebo 1, ale z platformy prichadza true, false;
|
||||
if (value == false) {
|
||||
turnLine("off", line, "command received from platform");
|
||||
reportToSend["contactor"]["off"].push({ [line]: Date.now(), maintenance_mode: SETTINGS.maintenance_mode });
|
||||
if (line != 0) reportToSend["contactor"]["off"].push({ [line]: Date.now(), maintenance_mode: SETTINGS.maintenance_mode });
|
||||
}
|
||||
else {
|
||||
turnLine("on", line, "command received from platform");
|
||||
reportToSend["contactor"]["on"].push({ [line]: Date.now(), maintenance_mode: SETTINGS.maintenance_mode });
|
||||
if (line != 0) reportToSend["contactor"]["on"].push({ [line]: Date.now(), maintenance_mode: SETTINGS.maintenance_mode });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue