Browse Source

added ventil

- this is actually much more cumbersome that it seems,
  there are many inconsistency in the data archival in ADEI
  system maintained by the Katrin group.

https://github.com/kit-ipe/bora/issues/2

Signed-off-by: nicolaisi <nicholas.jerome@kit.edu>
nicolaisi 8 years ago
parent
commit
3acf5e8b3f
10 changed files with 187 additions and 56 deletions
  1. 1 0
      .gitignore
  2. 4 1
      cache.yaml
  3. 16 4
      core.py
  4. 105 22
      designer.html
  5. 12 5
      res/adei2rest.py
  6. BIN
      static/ventil_active.png
  7. BIN
      static/ventil_inactive.png
  8. 32 2
      status.html
  9. 15 22
      style.yaml
  10. 2 0
      varname.yaml

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 config.yaml
 cache.yaml
 .tmp.yaml
+*.yaml

+ 4 - 1
cache.yaml

@@ -1 +1,4 @@
-320-RTP-3-1101: '217.3256072998047'
+320-RTP-3-1101: '115.8197860717773'
+320-RTY-3-2101: '120.6334609985352'
+320-RTY-3-3101: '116.0701599121094'
+411-REI-1-1110-0030: '0.0'

+ 16 - 4
core.py

@@ -6,7 +6,7 @@ import shutil
 from datetime import date
 import csv
 import urllib2
-
+import re
 
 
 
@@ -93,8 +93,15 @@ def fetchDataADEI():
                             auth=(config['username'],
                                   config['password'])).content
         #tmp_data = data.content
+        print data
+
         last_value = data.split(",")[-1].strip()
-        print last_value
+	try:
+            print last_value
+            test_x = float(last_value)
+        except ValueError:
+            last_value = None
+ 	print last_value
         cache_data[param] = last_value
 
     with open(".tmp.yaml", 'w') as stream_tmp:
@@ -272,8 +279,13 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
         match_token = params['sensor_name'] + "-IST_Val"
         db_mask = None
         for i, item in enumerate(cr):
-            if item.strip() == match_token:
-                db_mask = i - 1
+            if "[" and "]" in item.strip():
+                lhs = re.match(r"[^[]*\[([^]]*)\]", item.strip()).groups()[0]
+                if lhs == params['sensor_name']:
+                    db_mask = i - 1
+    	    else:
+	        if item.strip() == match_token:
+                    db_mask = i - 1
         if db_mask == None:
             response = {"Error": "Cannot find variable on ADEI server."}
             self.write(response)

+ 105 - 22
designer.html

@@ -21,10 +21,25 @@
 
 {% if data['style'] %}
 {% for key in data['style'] %}
-<div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-cond="{{ data['style'][key]['condition'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-larger="{{ data['style'][key]['larger'] }}" class='varbox' id="{{ key }}">
+{% if data['style'][key]['type'] == "data" %}
+<div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-cond="{{ data['style'][key]['condition'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-type="{{ data['style'][key]['type'] }}" data-larger="{{ data['style'][key]['larger'] }}" class='varbox' id="{{ key }}">
 <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX <span class='unit_title'> {{ data['style'][key]['unit']['title'] }}</span></span></p>
 </div>
+{% else %}
 {% end %}
+
+
+{% if data['style'][key]['type'] == "ventil" %}
+<div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
+<img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
+</div>
+{% else %}
+{% end %}
+
+
+
+{% end %}
+
 {% else %}
 {% end %}
 
@@ -37,6 +52,12 @@
   <option value={{data['cache'][key]}}>{{key}}</option>
   {% end %}
 </select>
+<span class="info">Type</span>
+<select id="vartype" style="font-size:16pt;">
+  <option value="data">data</option>
+  <option value="ventil">ventil</option>
+  <option value="integer-to-string">integer-to-string</option>
+</select>
 <br /><br />
 <span class="info">Title</span>
 <input type="text" id="elem_title_text" placeholder="text" style="font-size:16pt; width=100px;"/>
@@ -104,14 +125,65 @@ function add() {
     
     varval = $( "#varname option:selected").val();
     varname = $("#varname option:selected").text();
-    console.log(title_text, unit_text, varname, varval);
+    vartype = $("#vartype option:selected").val();
+    console.log(title_text, unit_text, varname, varval, vartype);
     
     
     if($("#" + varname).length == 0) {
-        html_text = "<div style='position: absolute; top:0; left:0;' class='varbox' id='" + varname + "' data-cond='" + data_condition + "' data-lesser='" + data_lesser + "' data-larger='" + data_larger + "'>";
-        html_text += "<p><span style='color: " + title_color + "; font-size:" + title_size + "px; font-weight: " + title_style + ";' " + "class='title'>" + title_text + " </span><span style='color: " + unit_color + "; font-size:" + unit_size + "px; font-weight: " + unit_style + ";' " + "class='varval'>" + parseFloat(varval).toFixed(2) + " </span><span class='unit_title'>" + unit_text + "</span></p>";
-        html_text += "</div>";
-    
+        if (vartype == "data") {
+            html_text = "<div " +
+                    "style='position: absolute; " +
+                           "top:0; " +
+                           "left:0;' " +
+                    "class='varbox' " + 
+                    "id='" + varname +
+                    "' data-type='" + vartype +
+                    "' data-cond='" + data_condition +
+                    "' data-lesser='" + data_lesser + 
+ 		    "' data-larger='" + data_larger + 
+                    "'>" +
+                    "<p>" +
+                    "<span style='color: " + title_color + ";" + 
+                    "font-size:" + title_size + "px; " + 
+                    "font-weight: " + title_style + ";' " + 
+                    "class='title'>" + title_text +
+                    " </span>" + 
+                    "<span style='color: " + unit_color + "; " + 
+                           "font-size:" + unit_size + "px; " +
+                           "font-weight: " + unit_style + ";' " + 
+                    "class='varval'>" + parseFloat(varval).toFixed(2) + " </span>" + 
+                    "<span class='unit_title'>" + unit_text + "</span></p>" +
+        	    "</div>";
+        } else if (vartype == "ventil") {
+            var token = unit_text.split(";");
+            var lhs = token[0];
+            var rhs = token[1];
+            var data_on, data_off;
+            if (lhs.split(":")[0] == "on") {
+                data_on = lhs.split(":")[1];
+                data_off = rhs.split(":")[1];
+            } else {
+                data_off = lhs.split(":")[1];
+                data_on = rhs.split(":")[1];
+            }
+
+            html_text = "<div " +
+                    "style='position: absolute; " +
+                           "top:0; " +
+                           "left:0;' " +
+                    "class='varbox' " + 
+                    "id='" + varname +
+                    "' data-type='" + vartype +
+                    "' data-cond='" + data_condition +
+                    "' data-lesser='" + data_lesser + 
+ 		    "' data-larger='" + data_larger + 
+ 		    "' data-on='" + data_on + 
+ 		    "' data-off='" + data_off + 
+                    "'>" +
+ 		    "<img width='100%' height='100%' " + 
+                    "src='{{ static_url("ventil_inactive.png") }}'></img>" +
+        	    "</div>";	    
+	}
         $( "body" ).append(html_text);
         $("#"+varname).draggable();
         $("#"+varname).resizable(); 
@@ -138,28 +210,39 @@ function mysave(data) {
             tmp["top"] = $("#"+key).css("top");
             tmp["width"] = $("#"+key).width();
             tmp["height"] = $("#"+key).height();
+            //tmp["type"] = $("#vartype option:selected").val();
             //tmp["min"] = $("#elem_min_range").val();
             //tmp["max"] = $("#elem_max_range").val();
             tmp["min"] = $("#"+key).attr("min");
             tmp["max"] = $("#"+key).attr("max");
-            tmp["condition"] = $("#"+key).attr("data-cond");
-            tmp["lesser"] = $("#"+key).attr("data-lesser");
-            tmp["larger"] = $("#"+key).attr("data-larger");
+            tmp["type"] = $("#"+key).attr("data-type");
+
+            if ( $("#"+key).attr("data-type") == "data" ) {
+            	tmp["condition"] = $("#"+key).attr("data-cond");
+            	tmp["lesser"] = $("#"+key).attr("data-lesser");
+            	tmp["larger"] = $("#"+key).attr("data-larger");
             
-            header = {};
-            header["title"] = $(".title", "#"+key).text();
-            //header["color"] = $(".title", "#"+key).css("color");
-            header["size"] = $(".title", "#"+key).css("font-size");
-            header["weight"] = $(".title", "#"+key).css("font-weight");
+            	header = {};
+            	header["title"] = $(".title", "#"+key).text();
+            	//header["color"] = $(".title", "#"+key).css("color");
+            	header["size"] = $(".title", "#"+key).css("font-size");
+            	header["weight"] = $(".title", "#"+key).css("font-weight");
             
-            unit = {};
-            unit["title"] = $(".unit_title", "#"+key).text();
-            //unit["color"] = $(".varval", "#"+key).css("color");
-            unit["size"] = $(".varval", "#"+key).css("font-size");
-            unit["weight"] = $(".varval", "#"+key).css("font-weight");
-
-            tmp["header"] = header;
-            tmp["unit"] = unit;
+            	unit = {};
+            	unit["title"] = $(".unit_title", "#"+key).text();
+            	//unit["color"] = $(".varval", "#"+key).css("color");
+            	unit["size"] = $(".varval", "#"+key).css("font-size");
+            	unit["weight"] = $(".varval", "#"+key).css("font-weight");
+
+            	tmp["header"] = header;
+            	tmp["unit"] = unit;
+            } else if ( $("#"+key).attr("data-type") == "ventil" ) {
+		//console.log("Ventil !!");
+            	//console.log($(".unit_title", "#"+key).text());
+            	tmp["on"] = $("#"+key).attr("data-on");
+            	tmp["off"] = $("#"+key).attr("data-off");
+            }
+
             position[key] = tmp;
         }
     }

+ 12 - 5
res/adei2rest.py

@@ -3,17 +3,20 @@ import sys, getopt
 
 
 def main(sensor, mystr):
-    #print mystr
+    print mystr
     query = mystr.split("#")[1]
+    print mystr.split("#")
     cmds = query.split("&")
     
+    print cmds 
+   
     db_server = None
     db_name = None
     db_group = None
     for item in cmds:
-        #print item
+        print item
         subtitle = item.split("=")
-        #print subtitle
+        print subtitle
         if subtitle[0].strip() == "db_server":
             db_server = subtitle[1].strip()
         elif subtitle[0].strip() == "db_name":
@@ -22,14 +25,18 @@ def main(sensor, mystr):
             db_group = subtitle[1].strip()
 
     #print query
-    
+    print "check"
+    print db_server   
+
+ 
     rest_str = []
     rest_str.append("http://ipepc57.ipe.kit.edu:8888/add")
     rest_str.append(db_server)
     rest_str.append(db_name)
     rest_str.append(db_group)
     rest_str.append(sensor)
-    
+  
+ 
     print "/".join(rest_str)
 
 

BIN
static/ventil_active.png


BIN
static/ventil_inactive.png


+ 32 - 2
status.html

@@ -19,14 +19,28 @@
     
 {% if data['style'] %}
 {% for key in data['style'] %}
+
+{% if data['style'][key]['type'] == "data" %}
 <div class="databox" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' 
 {% if data['style'][key]['condition'] %}
 data-cond="{{ data['style'][key]['condition'] }}"
 {% else%}
 {% end%}
-data-lesser="{{ data['style'][key]['lesser'] }}" data-larger="{{ data['style'][key]['larger'] }}" id="{{ key }}">
+data-type="{{ data['style'][key]['type'] }}" data-lesser="{{ data['style'][key]['lesser'] }}" data-larger="{{ data['style'][key]['larger'] }}" id="{{ key }}">
 <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span><span style="color: #000; font-size: {{ data['style'][key]['unit']['size'] }}; font-weight: {{ data['style'][key]['unit']['weight'] }};" class="varval"> XXX.XX </span><span class='unit_title'> {{ data['style'][key]['unit']['title'] }}</span></p>
 </div>
+{% else %}
+{% end %}
+
+
+{% if data['style'][key]['type'] == "ventil" %}
+<div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='databox' id="{{ key }}">
+<img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
+</div>
+{% else %}
+{% end %}
+
+
 {% end %}
 {% else %}
 {% end %}
@@ -56,7 +70,10 @@ function myTimer() {
             console.log(response);
             for (var key in response) {
                 console.log(key, response[key]);
+                data_type = $("#" + key).attr('data-type');
                 if($("#" + key).length > 0) {
+
+                    if (data_type == "data") {
                     $(".varval", "#" + key).text(parseFloat(response[key]).toFixed(2));
  		    var set_color = "green";
                     var condition_attr = $("#" + key).attr('data-cond');
@@ -80,7 +97,20 @@ function myTimer() {
 		    }
 		    $(".varval", "#" + key).css("color", set_color);
 		    $(".unit_title", "#" + key).css("color", set_color);
-                }
+                    
+		    } else if (data_type == "ventil") {
+			console.log("The VENTIL way");
+                        var on_attr = $("#" + key).attr('data-on');
+                        var off_attr = $("#" + key).attr('data-off');
+ 			if (parseFloat(response[key]) == parseFloat(on_attr)) {
+ 			    $("img", "#" + key).attr("src", "{{ static_url('ventil_active.png') }}");
+      			}
+ 			if (parseFloat(response[key]) == parseFloat(off_attr)) {
+ 			    $("img", "#" + key).attr("src", "{{ static_url('ventil_inactive.png') }}");
+      			}
+
+		    }
+		}
             }
 
 	    var currentdate = new Date(); 

+ 15 - 22
style.yaml

@@ -2,31 +2,24 @@
   condition: ''
   header:
     size: 28px
-    title: '  '
+    title: '        '
     weight: '400'
-  height: 88.991
+  height: 82.991
   larger: '70'
-  left: 173.968px
+  left: 1145.98px
   lesser: '0'
-  top: 811.96px
+  top: 423px
+  type: data
   unit:
     size: 28px
-    title: '      K'
+    title: '       K'
     weight: '400'
-  width: 130.99099999999999
-320-RTY-3-2101:
-  condition: ''
-  header:
-    size: 28px
-    title: 'Temperature 1 '
-    weight: '400'
-  height: 112.991
-  larger: '4.5'
-  left: 423.972px
-  lesser: ''
-  top: 359.963px
-  unit:
-    size: 28px
-    title: K
-    weight: '400'
-  width: 233.99099999999999
+  width: 139.99099999999999
+411-REI-1-1110-0030:
+  height: 50.991
+  left: 802px
+  'off': '1'
+  'on': '0'
+  top: 275px
+  type: ventil
+  width: 49.991

+ 2 - 0
varname.yaml

@@ -1,2 +1,4 @@
 320-RTP-3-1101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=180
 320-RTY-3-2101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=213
+320-RTY-3-3101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=222
+411-REI-1-1110-0030: db_server=aircoils&db_name=aircoils_rep&db_group=0&db_mask=all&window=-1&db_mask=84