simplified conditions, switch from "parts" to "format" with named fields
This commit is contained in:
+41
-37
@@ -134,7 +134,7 @@ jsPlumb.ready(function() {
|
||||
}
|
||||
}
|
||||
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, {
|
||||
anchor: anchor.anchor, uuid: anchUUID,
|
||||
@@ -205,8 +205,8 @@ jsPlumb.ready(function() {
|
||||
|
||||
var heat = false, water = false;
|
||||
var switchActions = {
|
||||
broadcasthwStatus: function(fields){
|
||||
console.log("action broadcasthwStatus:"+fields);
|
||||
/*"broadcast/hwcStatus": function(fields){
|
||||
console.log("action broadcast/hwcStatus:"+fields);
|
||||
if (!fields) return;
|
||||
var val = fields[0].value;
|
||||
if (val=='on') {
|
||||
@@ -227,11 +227,11 @@ jsPlumb.ready(function() {
|
||||
}
|
||||
}
|
||||
},
|
||||
bcStatus: function(fields) {
|
||||
console.log("action bcStatus:"+fields);
|
||||
"ehp/HwcHcValve": function(fields) {
|
||||
console.log("action ehp/HwcHcValve:"+fields);
|
||||
if (!fields) return;
|
||||
var val = fields[3].value;
|
||||
if (val=='03 2c 00 00') { // heat
|
||||
var val = fields['onoff'].value;
|
||||
if (val=='off') { // heat
|
||||
heat = true;
|
||||
ehpFlow.addType("hot");
|
||||
hwcFlow.removeType("hot");
|
||||
@@ -248,21 +248,21 @@ jsPlumb.ready(function() {
|
||||
hwcReturn.removeType("cold");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
};
|
||||
var buildText = function(parts, fields) {
|
||||
var buildText = function(format, fields) {
|
||||
var ret = '';
|
||||
if (parts) {
|
||||
parts = parts.split(' ');
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
if (format) {
|
||||
format = format.split(' ');
|
||||
for (var i=0; i<format.length; i++) {
|
||||
if (ret.length>0) ret += ', ';
|
||||
if (isNaN(parts[i])) {
|
||||
if (parts[i]=='\\n')
|
||||
if (format[i][0]!='$') {
|
||||
if (format[i]=='\\n')
|
||||
ret += "<br>";
|
||||
else
|
||||
ret += parts[i];
|
||||
} else if (fields && fields.hasOwnProperty(parts[i])){
|
||||
var field = fields[parts[i]];
|
||||
ret += format[i];
|
||||
} else if (fields && fields.hasOwnProperty(format[i].substring(1))){
|
||||
var field = fields[format[i].substring(1)];
|
||||
ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?';
|
||||
if (field.unit) {
|
||||
ret += ' '+field.unit;
|
||||
@@ -272,7 +272,7 @@ jsPlumb.ready(function() {
|
||||
}
|
||||
}
|
||||
} else if (fields) {
|
||||
for (var i=0; i<fields.length; i++) {
|
||||
for (var i in fields) {
|
||||
if (ret.length>0) ret += ', ';
|
||||
var field = fields[i];
|
||||
ret += field.hasOwnProperty('value')&&field.value!=null?field.value:'?';
|
||||
@@ -298,19 +298,23 @@ jsPlumb.ready(function() {
|
||||
return ret?ret[0]:null;
|
||||
};
|
||||
var checkCondition = function(condition, allMessages) {
|
||||
for (var k=0; k<condition.length; k++) { // "and" loop
|
||||
var cond = condition[k];
|
||||
for (var k=0; k+2<condition.length; k+=3) { // "and" loop
|
||||
var found = false;
|
||||
for (var i=0; i+2<cond.length; i+=3) { // "or" loop
|
||||
var fields = allMessages[cond[i]][cond[i+1]].fields;
|
||||
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value') || !isNaN(cond[i+2]) && isNaN(fields[0].value)) {
|
||||
fields = getFields(cond[i], cond[i+1], true, false, true);
|
||||
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value')) continue;
|
||||
}
|
||||
if (fields[0].value==cond[i+2]) {
|
||||
found = true;
|
||||
break;
|
||||
var fields = allMessages[condition[k]][condition[k+1]].fields;
|
||||
var cond = condition[k+2];
|
||||
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value') || !isNaN(Array.isArray(cond) ? cond[0] : cond) && isNaN(fields[0].value)) {
|
||||
fields = getFields(condition[k], condition[k+1], true, false, true);
|
||||
if (!fields || !fields[0] || !fields[0].hasOwnProperty('value')) return false;
|
||||
}
|
||||
if (Array.isArray(cond)) {
|
||||
for (var i=0; i<cond.length; i++) { // "or" loop
|
||||
if (fields[0].value==cond[i]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (fields[0].value==cond) {
|
||||
found = true;
|
||||
}
|
||||
if (!found) return;
|
||||
}
|
||||
@@ -360,12 +364,12 @@ jsPlumb.ready(function() {
|
||||
var ichild = document.createElement("div");
|
||||
ichild.className = "circuitLabel";
|
||||
ichild.setAttribute('data-id', circuit+'/'+mname);
|
||||
if (item.hasOwnProperty('parts')) {
|
||||
ichild.setAttribute('data-parts', item.parts);
|
||||
if (item.hasOwnProperty('format')) {
|
||||
ichild.setAttribute('data-format', item.format);
|
||||
}
|
||||
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.innerHTML = buildText(item.parts, message?message.fields:null);
|
||||
ichild.innerHTML = buildText(item.format, message?message.fields:null);
|
||||
child.appendChild(ichild);
|
||||
if (item.leftc) {
|
||||
ichild.style.left = Math.floor(item.leftc*width-ichild.clientWidth/2)+'px';
|
||||
@@ -414,7 +418,7 @@ jsPlumb.ready(function() {
|
||||
var first = true;
|
||||
for (var i=0; i<needConnections.length; 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;
|
||||
if (data[1]==null) {
|
||||
if (first) {
|
||||
@@ -473,7 +477,7 @@ jsPlumb.ready(function() {
|
||||
if (fields) {
|
||||
var elems = $$('div[data-id="'+needUris[i]+'"]');
|
||||
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 key = cname+'/'+mname;
|
||||
var needed = false;
|
||||
/*if (switchActions.hasOwnProperty(key)) {
|
||||
if (switchActions.hasOwnProperty(key)) {
|
||||
switchActions[key](fields);
|
||||
needed = true;
|
||||
}*/
|
||||
}
|
||||
var elems = $$('div[data-id="'+key+'"]');
|
||||
if (elems.length>0) {
|
||||
needed = true;
|
||||
@@ -528,7 +532,7 @@ jsPlumb.ready(function() {
|
||||
continue;
|
||||
}
|
||||
each(elems, function(elem) {
|
||||
elem.innerHTML = buildText(elem.getAttribute('data-parts'), fields);
|
||||
elem.innerHTML = buildText(elem.getAttribute('data-format'), fields);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
{
|
||||
"title": "DCF",
|
||||
"bounds": [10,0,54,48],
|
||||
"image": "dcf.svg",
|
||||
"image-pos": [10, 10],
|
||||
"items": [
|
||||
{"name": "datetime", "parts": "0", "top": 0, "left": 1},
|
||||
{"name": "datetime", "parts": "2 1", "top": 0.45, "left": 1}
|
||||
{"name": "datetime", "format": "$outsidetemp", "top": 0, "left": 1},
|
||||
{"name": "datetime", "format": "$date $time", "top": 0.45, "left": 1}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+48
-36
@@ -8,23 +8,31 @@
|
||||
"title": "Quelle",
|
||||
"bounds": [-130,108,80,100],
|
||||
"endpoints": [
|
||||
{"name": "Flow", "anchor": [0.25, 0, 0, -1], "label": "Source", "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": "Flow", "anchor": [0.25, 0, 0, -1], "label": "Source",
|
||||
"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",
|
||||
"condition": [["ehp", "HydraulicScheme", 4, "ehp", "HydraulicScheme", 3]],
|
||||
"condition": ["ehp", "HydraulicScheme", [3, 4]],
|
||||
"title": "Valve",
|
||||
"bounds": [200,16,25,31],
|
||||
"image": "valve.svg",
|
||||
"endpoints": [
|
||||
{"name": "Flow", "anchor": "Top", "target": true, "connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]},
|
||||
{"name": "HwcFlow", "anchor": "Right", "connectWith": ["storage", "HwcInput"], "update":
|
||||
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]}
|
||||
{"name": "Flow", "anchor": "Top", "target": true,
|
||||
"connectWith": ["ehp", "HcFlow", "ehp", "FlowTemp", "0"]
|
||||
},
|
||||
{"name": "HcFlow", "anchor": "Left", "connectWith": ["storage", "HcInput", "ehp", "HcFlowTemp", "0"], "update":
|
||||
{"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]}
|
||||
{"name": "HwcFlow", "anchor": "Right",
|
||||
"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": [
|
||||
@@ -33,7 +41,7 @@
|
||||
},
|
||||
{
|
||||
"name": "storage",
|
||||
"condition": [["ehp", "HydraulicScheme", 4]],
|
||||
"condition": ["ehp", "HydraulicScheme", 4],
|
||||
"title": "Speicher",
|
||||
"bounds": [390,-48,134,334],
|
||||
"image": "storage.svg",
|
||||
@@ -48,14 +56,14 @@
|
||||
{"name": "HcOutput", "anchor": [0, 0.67, -1, 0]}
|
||||
],
|
||||
"items": [
|
||||
{"circuit": "ehp", "name": "HwcTemp", "parts": "0", "topc": 0.12, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempTop", "parts": "0", "topc": 0.48, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempBottom", "parts": "0", "topc": 0.62, "left": 0.04}
|
||||
{"circuit": "ehp", "name": "HwcTemp", "format": "$temp", "topc": 0.12, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempTop", "format": "$temp", "topc": 0.48, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempBottom", "format": "$temp", "topc": 0.62, "left": 0.04}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "storage",
|
||||
"condition": [["ehp", "HydraulicScheme", 3]],
|
||||
"condition": ["ehp", "HydraulicScheme", 3],
|
||||
"title": "Wasserspeicher",
|
||||
"bounds": [390,47,134,239],
|
||||
"image": "buffer.svg",
|
||||
@@ -66,60 +74,64 @@
|
||||
{"name": "HwcOutput", "anchor": [0, 0.85, -1, 0]}
|
||||
],
|
||||
"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",
|
||||
"condition": [["ehp", "HydraulicScheme", 2]],
|
||||
"condition": ["ehp", "HydraulicScheme", 2],
|
||||
"title": "Pufferspeicher",
|
||||
"bounds": [390,47,134,239],
|
||||
"image": "buffer.svg",
|
||||
"endpoints": [
|
||||
{"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": "HcOutput", "anchor": [0, 0.85, -1, 0]}
|
||||
],
|
||||
"items": [
|
||||
{"circuit": "ehp", "name": "StorageTempTop", "parts": "0", "topc": 0.15, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempBottom", "parts": "0", "topc": 0.85, "left": 0.04}
|
||||
{"circuit": "ehp", "name": "StorageTempTop", "format": "$temp", "topc": 0.15, "left": 0.04},
|
||||
{"circuit": "ehp", "name": "StorageTempBottom", "format": "$temp", "topc": 0.85, "left": 0.04}
|
||||
]
|
||||
}
|
||||
],
|
||||
"endpoints": [
|
||||
{"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":
|
||||
{"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":
|
||||
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "on"]]}
|
||||
{"name": "HwcReturn", "anchor": [0.53, 0, 0, -1], "target": true, "distance": [0,80,0.3],
|
||||
"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":
|
||||
{"type": ["cold", "off"], "condition": [["ehp", "Hc1Pump", "on"], ["ehp", "HwcHcValve", "off"]]}
|
||||
{"name": "HcReturn", "anchor": [0.78, 0, 0, -1], "target": true, "distance": [0,60,0.42],
|
||||
"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":
|
||||
{"type": ["hot", "off"], "condition": [["ehp", "Hc1Pump", "on"]]}
|
||||
{"name": "HcFlow", "anchor": [0.88, 0, 0, -1], "priority": 1,
|
||||
"update": {"type": ["hot", "off"], "condition": ["ehp", "Hc1Pump", "on"]}
|
||||
}
|
||||
],
|
||||
"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": "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": "Hc1Pump", "topc": 0.53, "leftc": 0.665},
|
||||
{"name": "Backup", "topc": 0.54, "leftc": 0.9},
|
||||
{"name": "TempOutput", "parts": "0", "left": 0.2, "topc": 0.68},
|
||||
{"name": "CompPressHigh", "parts": "0", "left": 0.6, "topc": 0.68},
|
||||
{"name": "ActualEnvironmentPower", "parts": "0", "leftc": 0.12, "topc": 0.81},
|
||||
{"name": "TempOutput", "format": "$temp", "left": 0.2, "topc": 0.68},
|
||||
{"name": "CompPressHigh", "format": "$press", "left": 0.6, "topc": 0.68},
|
||||
{"name": "ActualEnvironmentPower", "leftc": 0.12, "topc": 0.81},
|
||||
{"name": "Comp", "leftc": 0.5, "topc": 0.81},
|
||||
{"name": "HeatPumpStatus", "left": 1, "topc": 0.81},
|
||||
{"name": "TempInput", "parts": "0", "left": 0.2, "topc": 0.94},
|
||||
{"name": "CondensorTemp", "parts": "0", "left": 0.65, "topc": 0.81},
|
||||
{"name": "CompPressLow", "parts": "0", "left": 0.6, "topc": 0.94},
|
||||
{"name": "YieldEnvironmentEnergy", "parts": "0", "left": 0, "top": 1},
|
||||
{"name": "PowerCut", "parts": "cut: 0", "left": 0.5, "top": 1}
|
||||
{"name": "TempInput", "format": "$temp", "left": 0.2, "topc": 0.94},
|
||||
{"name": "CondensorTemp", "format": "$temp", "left": 0.65, "topc": 0.81},
|
||||
{"name": "CompPressLow", "format": "$press", "left": 0.6, "topc": 0.94},
|
||||
{"name": "YieldEnvironmentEnergy", "left": 0, "top": 1},
|
||||
{"name": "PowerCut", "format": "cut: $yesno", "left": 0.5, "top": 1}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"title": "Warmwasser",
|
||||
"bounds": [510,40,174,52],
|
||||
"image": "hwc.svg",
|
||||
@@ -9,6 +9,6 @@
|
||||
"items": [
|
||||
{"name": "OperatingMode", "topc": 0.2, "left": 0.6},
|
||||
{"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}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
{"name":"HcReturn", "anchor": [1, 0.96, 1, 0]}
|
||||
],
|
||||
"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},
|
||||
{"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": "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}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
"image-pos": [10,0],
|
||||
"items": [
|
||||
{"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}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
"image-pos": [10,0],
|
||||
"items": [
|
||||
{"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}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user