simplified conditions, switch from "parts" to "format" with named fields

This commit is contained in:
john30
2016-03-20 13:36:28 +01:00
parent adcf3e0d33
commit 4d55204db4
7 changed files with 101 additions and 85 deletions
+38 -34
View File
@@ -134,7 +134,7 @@ jsPlumb.ready(function() {
} }
} }
if (anchor.hasOwnProperty('connectWith') && needConnections) { if (anchor.hasOwnProperty('connectWith') && needConnections) {
needConnections.push(new Array(anchUUID).concat(anchor.connectWith)); // to-circuit, to-endpoint[, item-circuit, item-name[, item-parts]] needConnections.push(new Array(anchUUID).concat(anchor.connectWith)); // to-circuit, to-endpoint[, item-circuit, item-name[, item-format]]
} }
var endp = instance.addEndpoint(divId, endpoint, { var endp = instance.addEndpoint(divId, endpoint, {
anchor: anchor.anchor, uuid: anchUUID, anchor: anchor.anchor, uuid: anchUUID,
@@ -205,8 +205,8 @@ jsPlumb.ready(function() {
var heat = false, water = false; var heat = false, water = false;
var switchActions = { var switchActions = {
broadcasthwStatus: function(fields){ /*"broadcast/hwcStatus": function(fields){
console.log("action broadcasthwStatus:"+fields); console.log("action broadcast/hwcStatus:"+fields);
if (!fields) return; if (!fields) return;
var val = fields[0].value; var val = fields[0].value;
if (val=='on') { if (val=='on') {
@@ -227,11 +227,11 @@ jsPlumb.ready(function() {
} }
} }
}, },
bcStatus: function(fields) { "ehp/HwcHcValve": function(fields) {
console.log("action bcStatus:"+fields); console.log("action ehp/HwcHcValve:"+fields);
if (!fields) return; if (!fields) return;
var val = fields[3].value; var val = fields['onoff'].value;
if (val=='03 2c 00 00') { // heat if (val=='off') { // heat
heat = true; heat = true;
ehpFlow.addType("hot"); ehpFlow.addType("hot");
hwcFlow.removeType("hot"); hwcFlow.removeType("hot");
@@ -248,21 +248,21 @@ jsPlumb.ready(function() {
hwcReturn.removeType("cold"); hwcReturn.removeType("cold");
} }
} }
} }*/
}; };
var buildText = function(parts, fields) { var buildText = function(format, fields) {
var ret = ''; var ret = '';
if (parts) { if (format) {
parts = parts.split(' '); format = format.split(' ');
for (var i=0; i<parts.length; i++) { for (var i=0; i<format.length; i++) {
if (ret.length>0) ret += ',&nbsp;'; if (ret.length>0) ret += ',&nbsp;';
if (isNaN(parts[i])) { if (format[i][0]!='$') {
if (parts[i]=='\\n') if (format[i]=='\\n')
ret += "<br>"; ret += "<br>";
else else
ret += parts[i]; ret += format[i];
} else if (fields && fields.hasOwnProperty(parts[i])){ } else if (fields && fields.hasOwnProperty(format[i].substring(1))){
var field = fields[parts[i]]; var field = fields[format[i].substring(1)];
ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?'; ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?';
if (field.unit) { if (field.unit) {
ret += '&nbsp;'+field.unit; ret += '&nbsp;'+field.unit;
@@ -272,7 +272,7 @@ jsPlumb.ready(function() {
} }
} }
} else if (fields) { } else if (fields) {
for (var i=0; i<fields.length; i++) { for (var i in fields) {
if (ret.length>0) ret += ',&nbsp;'; if (ret.length>0) ret += ',&nbsp;';
var field = fields[i]; var field = fields[i];
ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?'; ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?';
@@ -298,20 +298,24 @@ jsPlumb.ready(function() {
return ret?ret[0]:null; return ret?ret[0]:null;
}; };
var checkCondition = function(condition, allMessages) { var checkCondition = function(condition, allMessages) {
for (var k=0; k<condition.length; k++) { // "and" loop for (var k=0; k+2<condition.length; k+=3) { // "and" loop
var cond = condition[k];
var found = false; var found = false;
for (var i=0; i+2<cond.length; i+=3) { // "or" loop var fields = allMessages[condition[k]][condition[k+1]].fields;
var fields = allMessages[cond[i]][cond[i+1]].fields; var cond = condition[k+2];
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value') || !isNaN(cond[i+2]) && isNaN(fields[0].value)) { if (!fields || !fields[0] || !fields[0].hasOwnProperty('value') || !isNaN(Array.isArray(cond) ? cond[0] : cond) && isNaN(fields[0].value)) {
fields = getFields(cond[i], cond[i+1], true, false, true); fields = getFields(condition[k], condition[k+1], true, false, true);
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value')) continue; if (!fields || !fields[0] || !fields[0].hasOwnProperty('value')) return false;
} }
if (fields[0].value==cond[i+2]) { if (Array.isArray(cond)) {
for (var i=0; i<cond.length; i++) { // "or" loop
if (fields[0].value==cond[i]) {
found = true; found = true;
break; break;
} }
} }
} else if (fields[0].value==cond) {
found = true;
}
if (!found) return; if (!found) return;
} }
return true; return true;
@@ -360,12 +364,12 @@ jsPlumb.ready(function() {
var ichild = document.createElement("div"); var ichild = document.createElement("div");
ichild.className = "circuitLabel"; ichild.className = "circuitLabel";
ichild.setAttribute('data-id', circuit+'/'+mname); ichild.setAttribute('data-id', circuit+'/'+mname);
if (item.hasOwnProperty('parts')) { if (item.hasOwnProperty('format')) {
ichild.setAttribute('data-parts', item.parts); ichild.setAttribute('data-format', item.format);
} }
ichild.style.left = Math.floor((item.leftc?item.leftc:item.left)*width)+'px'; ichild.style.left = Math.floor((item.leftc?item.leftc:item.left)*width)+'px';
ichild.style.top = Math.floor((item.topc?item.topc:item.top)*height)+'px'; ichild.style.top = Math.floor((item.topc?item.topc:item.top)*height)+'px';
ichild.innerHTML = buildText(item.parts, message?message.fields:null); ichild.innerHTML = buildText(item.format, message?message.fields:null);
child.appendChild(ichild); child.appendChild(ichild);
if (item.leftc) { if (item.leftc) {
ichild.style.left = Math.floor(item.leftc*width-ichild.clientWidth/2)+'px'; ichild.style.left = Math.floor(item.leftc*width-ichild.clientWidth/2)+'px';
@@ -414,7 +418,7 @@ jsPlumb.ready(function() {
var first = true; var first = true;
for (var i=0; i<needConnections.length; i++) { for (var i=0; i<needConnections.length; i++) {
var data = needConnections[i]; var data = needConnections[i];
// fromuuid, to-circuit|null, to-endpoint[, item-circuit, item-name[, item-parts]] // fromuuid, to-circuit|null, to-endpoint[, item-circuit, item-name[, item-format]]
var src = data[0], dst; var src = data[0], dst;
if (data[1]==null) { if (data[1]==null) {
if (first) { if (first) {
@@ -473,7 +477,7 @@ jsPlumb.ready(function() {
if (fields) { if (fields) {
var elems = $$('div[data-id="'+needUris[i]+'"]'); var elems = $$('div[data-id="'+needUris[i]+'"]');
each(elems, function(elem) { each(elems, function(elem) {
elem.innerHTML = buildText(elem.getAttribute('data-parts'), fields); elem.innerHTML = buildText(elem.getAttribute('data-format'), fields);
}); });
} }
} }
@@ -516,10 +520,10 @@ jsPlumb.ready(function() {
var fields = message.fields; var fields = message.fields;
var key = cname+'/'+mname; var key = cname+'/'+mname;
var needed = false; var needed = false;
/*if (switchActions.hasOwnProperty(key)) { if (switchActions.hasOwnProperty(key)) {
switchActions[key](fields); switchActions[key](fields);
needed = true; needed = true;
}*/ }
var elems = $$('div[data-id="'+key+'"]'); var elems = $$('div[data-id="'+key+'"]');
if (elems.length>0) { if (elems.length>0) {
needed = true; needed = true;
@@ -528,7 +532,7 @@ jsPlumb.ready(function() {
continue; continue;
} }
each(elems, function(elem) { each(elems, function(elem) {
elem.innerHTML = buildText(elem.getAttribute('data-parts'), fields); elem.innerHTML = buildText(elem.getAttribute('data-format'), fields);
}); });
} }
} }
+2 -2
View File
@@ -4,7 +4,7 @@
"image": "dcf.svg", "image": "dcf.svg",
"image-pos": [10, 10], "image-pos": [10, 10],
"items": [ "items": [
{"name": "datetime", "parts": "0", "top": 0, "left": 1}, {"name": "datetime", "format": "$outsidetemp", "top": 0, "left": 1},
{"name": "datetime", "parts": "2 1", "top": 0.45, "left": 1} {"name": "datetime", "format": "$date $time", "top": 0.45, "left": 1}
] ]
} }
+48 -36
View File
@@ -8,23 +8,31 @@
"title": "Quelle", "title": "Quelle",
"bounds": [-130,108,80,100], "bounds": [-130,108,80,100],
"endpoints": [ "endpoints": [
{"name": "Flow", "anchor": [0.25, 0, 0, -1], "label": "Source", "connectWith": ["ehp", "SourceInput", "ehp", "SourceTempInput", "0"]}, {"name": "Flow", "anchor": [0.25, 0, 0, -1], "label": "Source",
{"name": "Return", "anchor": [0.75, 0, 0, -1], "target": true, "label": "Source", "connectWith": ["ehp", "SourceOutput", "ehp", "SourceTempOutput", "0"]} "connectWith": ["ehp", "SourceInput", "ehp", "SourceTempInput", "0"]
},
{"name": "Return", "anchor": [0.75, 0, 0, -1], "target": true, "label": "Source",
"connectWith": ["ehp", "SourceOutput", "ehp", "SourceTempOutput", "0"]
}
] ]
}, },
{ {
"name": "valve", "name": "valve",
"condition": [["ehp", "HydraulicScheme", 4, "ehp", "HydraulicScheme", 3]], "condition": ["ehp", "HydraulicScheme", [3, 4]],
"title": "Valve", "title": "Valve",
"bounds": [200,16,25,31], "bounds": [200,16,25,31],
"image": "valve.svg", "image": "valve.svg",
"endpoints": [ "endpoints": [
{"name": "Flow", "anchor": "Top", "target": true, "connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]}, {"name": "Flow", "anchor": "Top", "target": true,
{"name": "HwcFlow", "anchor": "Right", "connectWith": ["storage", "HwcInput"], "update": "connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]}
}, },
{"name": "HcFlow", "anchor": "Left", "connectWith": ["storage", "HcInput", "ehp", "HcFlowTemp", "0"], "update": {"name": "HwcFlow", "anchor": "Right",
{"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]} "connectWith": ["storage", "HwcInput"],
"update": {"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]}
},
{"name": "HcFlow", "anchor": "Left",
"connectWith": ["storage", "HcInput", "ehp", "HcFlowTemp", "0"],
"update": {"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]}
} }
], ],
"items": [ "items": [
@@ -33,7 +41,7 @@
}, },
{ {
"name": "storage", "name": "storage",
"condition": [["ehp", "HydraulicScheme", 4]], "condition": ["ehp", "HydraulicScheme", 4],
"title": "Speicher", "title": "Speicher",
"bounds": [390,-48,134,334], "bounds": [390,-48,134,334],
"image": "storage.svg", "image": "storage.svg",
@@ -48,14 +56,14 @@
{"name": "HcOutput", "anchor": [0, 0.67, -1, 0]} {"name": "HcOutput", "anchor": [0, 0.67, -1, 0]}
], ],
"items": [ "items": [
{"circuit": "ehp", "name": "HwcTemp", "parts": "0", "topc": 0.12, "left": 0.04}, {"circuit": "ehp", "name": "HwcTemp", "format": "$temp", "topc": 0.12, "left": 0.04},
{"circuit": "ehp", "name": "StorageTempTop", "parts": "0", "topc": 0.48, "left": 0.04}, {"circuit": "ehp", "name": "StorageTempTop", "format": "$temp", "topc": 0.48, "left": 0.04},
{"circuit": "ehp", "name": "StorageTempBottom", "parts": "0", "topc": 0.62, "left": 0.04} {"circuit": "ehp", "name": "StorageTempBottom", "format": "$temp", "topc": 0.62, "left": 0.04}
] ]
}, },
{ {
"name": "storage", "name": "storage",
"condition": [["ehp", "HydraulicScheme", 3]], "condition": ["ehp", "HydraulicScheme", 3],
"title": "Wasserspeicher", "title": "Wasserspeicher",
"bounds": [390,47,134,239], "bounds": [390,47,134,239],
"image": "buffer.svg", "image": "buffer.svg",
@@ -66,60 +74,64 @@
{"name": "HwcOutput", "anchor": [0, 0.85, -1, 0]} {"name": "HwcOutput", "anchor": [0, 0.85, -1, 0]}
], ],
"items": [ "items": [
{"circuit": "ehp", "name": "HwcTemp", "parts": "0", "topc": 0.12, "left": 0.04} {"circuit": "ehp", "name": "HwcTemp", "format": "$temp", "topc": 0.12, "left": 0.04}
] ]
}, },
{ {
"name": "storage", "name": "storage",
"condition": [["ehp", "HydraulicScheme", 2]], "condition": ["ehp", "HydraulicScheme", 2],
"title": "Pufferspeicher", "title": "Pufferspeicher",
"bounds": [390,47,134,239], "bounds": [390,47,134,239],
"image": "buffer.svg", "image": "buffer.svg",
"endpoints": [ "endpoints": [
{"name": "HcFlow", "anchor": [1, 0.15, 1, 0]}, {"name": "HcFlow", "anchor": [1, 0.15, 1, 0]},
{"name": "HcInput", "anchor": [0, 0.15, -1, 0], "target": true, "connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]}, {"name": "HcInput", "anchor": [0, 0.15, -1, 0], "target": true,
"connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]
},
{"name": "HcReturn", "anchor": [1, 0.85, 1, 0], "target": true, "distance": [0,0,0.7]}, {"name": "HcReturn", "anchor": [1, 0.85, 1, 0], "target": true, "distance": [0,0,0.7]},
{"name": "HcOutput", "anchor": [0, 0.85, -1, 0]} {"name": "HcOutput", "anchor": [0, 0.85, -1, 0]}
], ],
"items": [ "items": [
{"circuit": "ehp", "name": "StorageTempTop", "parts": "0", "topc": 0.15, "left": 0.04}, {"circuit": "ehp", "name": "StorageTempTop", "format": "$temp", "topc": 0.15, "left": 0.04},
{"circuit": "ehp", "name": "StorageTempBottom", "parts": "0", "topc": 0.85, "left": 0.04} {"circuit": "ehp", "name": "StorageTempBottom", "format": "$temp", "topc": 0.85, "left": 0.04}
] ]
} }
], ],
"endpoints": [ "endpoints": [
{"name": "SourceOutput", "anchor": [0.12, 0, 0, -1], "label": "Source", "update": {"name": "SourceOutput", "anchor": [0.12, 0, 0, -1], "label": "Source", "update":
{"type": ["cold", "off"], "condition": [["ehp", "Source", "on"]]} {"type": ["cold", "off"], "condition": ["ehp", "Source", "on"]}
}, },
{"name": "SourceInput", "anchor": [0.22, 0, 0, -1], "target": true, "label": "Source", "distance": [0,60], "update": {"name": "SourceInput", "anchor": [0.22, 0, 0, -1], "target": true, "label": "Source", "distance": [0,60], "update":
{"type": ["hot", "off"], "condition": [["ehp", "Source", "on"]]} {"type": ["hot", "off"], "condition": ["ehp", "Source", "on"]}
}, },
{"name": "HwcReturn", "anchor": [0.53, 0, 0, -1], "target": true, "distance": [0,80,0.3], "connectWith": ["storage", "HwcOutput"], "update": {"name": "HwcReturn", "anchor": [0.53, 0, 0, -1], "target": true, "distance": [0,80,0.3],
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]} "connectWith": ["storage", "HwcOutput"],
"update": {"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]}
}, },
{"name": "HcReturn", "anchor": [0.78, 0, 0, -1], "target": true, "distance": [0,60,0.42], "connectWith": ["storage", "HcOutput", "ehp", "HcReturnTemp", "0"], "update": {"name": "HcReturn", "anchor": [0.78, 0, 0, -1], "target": true, "distance": [0,60,0.42],
{"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]} "connectWith": ["storage", "HcOutput", "ehp", "HcReturnTemp", "0"],
"update": {"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]}
}, },
{"name": "HcFlow", "anchor": [0.88, 0, 0, -1], "priority": 1, "update": {"name": "HcFlow", "anchor": [0.88, 0, 0, -1], "priority": 1,
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"]]} "update": {"type": ["hot", "off"], "condition": ["ehp", "Hc1Pump", "on"]}
} }
], ],
"items": [ "items": [
{"name": "SourcePress", "parts": "0", "topc": 0.2, "left": 0.01}, {"name": "SourcePress", "format": "$press", "topc": 0.2, "left": 0.01},
{"name": "Source", "topc": 0.53, "leftc": 0.12}, {"name": "Source", "topc": 0.53, "leftc": 0.12},
{"name": "HcPress", "parts": "0", "topc": 0.2, "left": 0.5}, {"name": "HcPress", "format": "$press", "topc": 0.2, "left": 0.5},
{"name": "HwcHcValve", "topc": 0.4, "leftc": 0.65}, {"name": "HwcHcValve", "topc": 0.4, "leftc": 0.65},
{"name": "Hc1Pump", "topc": 0.53, "leftc": 0.665}, {"name": "Hc1Pump", "topc": 0.53, "leftc": 0.665},
{"name": "Backup", "topc": 0.54, "leftc": 0.9}, {"name": "Backup", "topc": 0.54, "leftc": 0.9},
{"name": "TempOutput", "parts": "0", "left": 0.2, "topc": 0.68}, {"name": "TempOutput", "format": "$temp", "left": 0.2, "topc": 0.68},
{"name": "CompPressHigh", "parts": "0", "left": 0.6, "topc": 0.68}, {"name": "CompPressHigh", "format": "$press", "left": 0.6, "topc": 0.68},
{"name": "ActualEnvironmentPower", "parts": "0", "leftc": 0.12, "topc": 0.81}, {"name": "ActualEnvironmentPower", "leftc": 0.12, "topc": 0.81},
{"name": "Comp", "leftc": 0.5, "topc": 0.81}, {"name": "Comp", "leftc": 0.5, "topc": 0.81},
{"name": "HeatPumpStatus", "left": 1, "topc": 0.81}, {"name": "HeatPumpStatus", "left": 1, "topc": 0.81},
{"name": "TempInput", "parts": "0", "left": 0.2, "topc": 0.94}, {"name": "TempInput", "format": "$temp", "left": 0.2, "topc": 0.94},
{"name": "CondensorTemp", "parts": "0", "left": 0.65, "topc": 0.81}, {"name": "CondensorTemp", "format": "$temp", "left": 0.65, "topc": 0.81},
{"name": "CompPressLow", "parts": "0", "left": 0.6, "topc": 0.94}, {"name": "CompPressLow", "format": "$press", "left": 0.6, "topc": 0.94},
{"name": "YieldEnvironmentEnergy", "parts": "0", "left": 0, "top": 1}, {"name": "YieldEnvironmentEnergy", "left": 0, "top": 1},
{"name": "PowerCut", "parts": "cut: 0", "left": 0.5, "top": 1} {"name": "PowerCut", "format": "cut: $yesno", "left": 0.5, "top": 1}
] ]
} }
+1 -1
View File
@@ -9,6 +9,6 @@
"items": [ "items": [
{"name": "OperatingMode", "topc": 0.2, "left": 0.6}, {"name": "OperatingMode", "topc": 0.2, "left": 0.6},
{"circuit": "ehp", "name": "CirPump", "topc": 0.8, "leftc": 0.85}, {"circuit": "ehp", "name": "CirPump", "topc": 0.8, "leftc": 0.85},
{"circuit": "cp", "name": "Mode", "parts": "1 0", "top": 1, "left": 0.6} {"circuit": "cc", "name": "Mode", "format": "$1 $0", "top": 1, "left": 0.6}
] ]
} }
+3 -3
View File
@@ -9,11 +9,11 @@
{"name":"HcReturn", "anchor": [1, 0.96, 1, 0]} {"name":"HcReturn", "anchor": [1, 0.96, 1, 0]}
], ],
"items": [ "items": [
{"name": "Status", "parts": "2", "top": 0.04, "left": 0.04}, {"name": "Status", "format": "$2", "top": 0.04, "left": 0.04},
{"circuit": "uih", "name": "HcName4", "top": 0.25, "leftc": 0.5}, {"circuit": "uih", "name": "HcName4", "top": 0.25, "leftc": 0.5},
{"name": "Mode", "parts": "1 0", "topc": 0.4, "leftc": 0.5}, {"name": "Mode", "format": "$1 $0", "topc": 0.4, "leftc": 0.5},
{"name": "HcPumpPort", "topc": 0.56, "leftc": 0.22}, {"name": "HcPumpPort", "topc": 0.56, "leftc": 0.22},
{"name": "MixerDutyCycle", "topc": 0.73, "leftc": 0.24}, {"name": "MixerDutyCycle", "topc": 0.73, "leftc": 0.24},
{"name": "Status", "parts": "1 0", "topc": 0.9, "leftc": 0.4} {"name": "Status", "format": "$1 $0", "topc": 0.9, "leftc": 0.4}
] ]
} }
+1 -1
View File
@@ -5,6 +5,6 @@
"image-pos": [10,0], "image-pos": [10,0],
"items": [ "items": [
{"circuit": "uih", "name": "HcName4", "top": 0.1, "leftc": 0.5}, {"circuit": "uih", "name": "HcName4", "top": 0.1, "leftc": 0.5},
{"name": "RoomTemp", "parts": "0", "top": 1, "left": 0} {"name": "RoomTemp", "format": "$temp", "top": 1, "left": 0}
] ]
} }
+1 -1
View File
@@ -5,6 +5,6 @@
"image-pos": [10,0], "image-pos": [10,0],
"items": [ "items": [
{"circuit": "uih", "name": "HcName2", "top": 0.1, "leftc": 0.5}, {"circuit": "uih", "name": "HcName2", "top": 0.1, "leftc": 0.5},
{"name": "RoomTemp", "parts": "0", "top": 1, "left": 0} {"name": "RoomTemp", "format": "$temp", "top": 1, "left": 0}
] ]
} }