Browse Source

cleanup unused files and renamed files.

Signed-off-by: nicolaisi <nicholas.jerome@kit.edu>
nicolaisi 8 years ago
parent
commit
96c6c259bf
11 changed files with 78 additions and 243 deletions
  1. 1 9
      cache.yaml
  2. 12 180
      core.py
  3. 0 0
      position.yaml
  4. 2 2
      res/adei2rest.py
  5. 34 0
      res/style_stable.yaml
  6. 9 0
      res/varname_stable.yaml
  7. 1 1
      static/style.css
  8. 13 0
      status.html
  9. 6 23
      style.yaml
  10. 0 20
      test.py
  11. 0 8
      varname.yaml

+ 1 - 9
cache.yaml

@@ -1,9 +1 @@
-320-RTP-3-1101: '275.4249572753906'
-320-RTP-3-6101: '268.7811584472656'
-320-RTP-3-7101: '276.6007995605469'
-320-RTP-8-1103: '294.2000122070312'
-320-RTT-1-1107: '260.0961303710938'
-320-RTY-3-2101: '265.6397705078125'
-320-RTY-3-3101: '263.7976989746094'
-320-RTY-3-4101: '261.9103698730469'
-320-RTY-3-5101: '258.9263000488281'
+320-RTP-3-1101: '217.3256072998047'

+ 12 - 180
opa.py → core.py

@@ -2,7 +2,6 @@ import os
 import sys
 import yaml
 import requests
-import MySQLdb
 import shutil
 from datetime import date
 import csv
@@ -63,88 +62,14 @@ class RepeatedTimer(object):
         self.interval = interval
     
 
-def fetchDataMySQL(sort_name):
-    # config contains db setup
-    # varname consist column name
-    
-    
-    with open("varname.yaml", 'r') as stream:
-        try:
-            #print(yaml.load(stream))
-            varname = yaml.load(stream)
-        except yaml.YAMLError as exc:
-            print(exc)
-    if varname == None:
-        print("Error: Empty varname file.")
-        return
-    
-    # first write to tmp.yml
-    db = MySQLdb.connect(config["server"],
-                         config["user"],
-                         config["password"],
-                         config["database"])
-
-    # prepare a cursor object using cursor() method
-    cursor = db.cursor()
-
-    # execute SQL query using execute() method.
-    sql = "SELECT "
-    for table_name in varname:
-        column_names = varname[table_name]
-    if isinstance(column_names, list):
-        sql += ",".join(column_names)
-    else:
-        sql += column_names
-    sql += " FROM "
-    sql += table_name
-    sql += " ORDER BY "
-    sql += sort_name
-    sql += " DESC LIMIT 1"
-
-    
-    print sql
-    
-    cursor.execute(sql)
-    # Fetch a single row using fetchone() method.
-    data = cursor.fetchone()
-
-    print data
-    # when ready then copy to cache.yml
-    print config
-    print varname
-    
-    cache_data = {}
-    if isinstance(varname[table_name], list):
-        for i, item in enumerate(varname[table_name]):
-            cache_data[item] = float(data[i])
-    else:
-        cache_data[varname[table_name]] = float(data[0])
-
-    print cache_data
-    with open(".tmp.yaml", 'w') as stream_tmp:
-        stream_tmp.write(yaml.dump(cache_data, default_flow_style=False))
-    src_file = config["path"] + ".tmp.yaml"
-    dst_file = config["path"] + "cache.yaml"
-    shutil.copy(src_file, dst_file)
 
 
 def fetchDataADEI():
-    """
-    with open("config.yaml", 'r') as stream:
-        try:
-            #print(yaml.load(stream))
-            config = yaml.load(stream)
-        except yaml.YAMLError as exc:
-            print(exc)
-    if config == None:
-        print("Error: Empty configuration file.")
-        return
-    """
     if os.path.isfile(config["path"]+".mutex"):
-        print("Process running...")
+        #print("Process running...")
         return
     else:
-        print("Created mutex")
+        #print("Created mutex")
         file = open(config["path"]+'.mutex', 'w+')
     
     with open("varname.yaml", 'r') as stream:
@@ -155,6 +80,7 @@ def fetchDataADEI():
             print(exc)
     if varname == None:
         print("Error: Empty varname file.")
+    	os.remove(config["path"]+".mutex")
         return
     
     cache_data = {}
@@ -176,7 +102,6 @@ def fetchDataADEI():
     src_file = config["path"] + ".tmp.yaml"
     dst_file = config["path"] + "cache.yaml"
     shutil.copy(src_file, dst_file)
-
     
     
     os.remove(config["path"]+".mutex")
@@ -236,86 +161,9 @@ class SetTimerHandler(tornado.web.RequestHandler):
         print "Set interval"
         rt.setInterval(float(duration))
 
-        
-class AddHandler(tornado.web.RequestHandler):
-    def get(self, **params):
-        print params
-        table_name = str(params["table_name"])
-        column_name = str(params["column_name"])
-        response = {}
-        """
-        with open("config.yaml", 'r') as stream:
-            try:
-                #print(yaml.load(stream))
-                config = yaml.load(stream)
-            except yaml.YAMLError as exc:
-                print(exc)
-        if config == None:
-            print("Error: Empty configuration file.")
-            return
-        """
-        if config["type"] == "mysql":
-            print("Inside MySQL block:")
-            print config
-            
-            # Open database connection
-            db = MySQLdb.connect(config["server"],
-                                 config["user"],
-                                 config["password"],
-                                 config["database"])
-
-            # prepare a cursor object using cursor() method
-            cursor = db.cursor()
-
-            # execute SQL query using execute() method.
-            sql = "SHOW COLUMNS FROM `" + params["table_name"] + "` LIKE '" + params["column_name"] + "'"
-            #print sql
-            cursor.execute(sql)
-
-            # Fetch a single row using fetchone() method.
-            data = cursor.fetchone()
-            db.close()
-            
-            if data == None:
-                response = {"error": "Data name not valid."}
-            else:
-                # column name available
-                # store in yaml file
-                with open("varname.yaml", 'r') as stream:
-                    try:
-                        #print(yaml.load(stream))
-                        cache_data = yaml.load(stream)
-                    except yaml.YAMLError as exc:
-                        print(exc)
-                
-                if cache_data == None:
-                    cache_data = {table_name: column_name}
-                else:
-                    if table_name in cache_data:
-                        tmp = cache_data[table_name]
-                        print tmp
-                        if isinstance(tmp, list):
-                            tmp_lst = tmp
-                        else:
-                            tmp_lst = [tmp]
-                        tmp_lst.append(column_name)
-                        # remove redundant in list
-                        tmp_lst = list(set(tmp_lst))
-                        cache_data[table_name] = tmp_lst
-                    else:
-                        cache_data[table_name] = column_name
-                
-                with open("varname.yaml", 'w') as output:
-                    output.write(yaml.dump(cache_data, default_flow_style=False))
-                response = {"success": "Data entry inserted."}
-        
-        self.write(response)
 
 
 class DesignerHandler(tornado.web.RequestHandler):
-    # TODO: Need to load and pass style to client
-    # If user did nothing, save should actually save the
-    # same content.
     def get(self):
         print "In designer mode."
         with open("cache.yaml", 'r') as stream:
@@ -385,7 +233,7 @@ class StatusHandler(tornado.web.RequestHandler):
 
 class AdeiKatrinHandler(tornado.web.RequestHandler):
     def get(self, **params):
-        print params
+        #print params
         sensor_name = str(params["sensor_name"])
         """
         {'db_group': u'320_KRY_Kryo_4K_CurLead',
@@ -394,29 +242,12 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
          'db_server': u'cscps',
          'control_group': u'320_KRY_Kryo_3K'}
         """
-        
-        """
-        with open("config.yaml", 'r') as stream:
-            try:
-                #print(yaml.load(stream))
-                config = yaml.load(stream)
-            except yaml.YAMLError as exc:
-                print(exc)
-
-        if config == None:
-            print("Error: Empty configuration file.")
-            return
-        """
         if config["type"] != "adei":
             print("Error: Wrong handler.")
             return
         
-        """
-        requests.get('http://katrin.kit.edu/adei-katrin/services/getdata.php?db_server=cscps&db_name=ControlSystem_CPS&db_group=320_KRY_Kryo_4K_CurLead&control_group=320_KRY_Kryo_3K&db_mask=33&window=-1')
-        requests.get(url, auth=(username, password))
-        """
         
-        print config
+        #print config
         
         dest = config['server'] + config['script']
         query_cmds = []
@@ -428,7 +259,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
         query = "&".join(query_cmds)
         url = dest + "?" + query
 
-        print url
+        #print url
         # get the db_masks
         # store the query command in varname
         
@@ -459,9 +290,9 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
                 print(exc)
-        print "CHECK THIS"
-        print sensor_name, query
-        print cache_data
+        #print "CHECK THIS"
+        #print sensor_name, query
+        #print cache_data
         if cache_data == None:
             cache_data = {}
             cache_data[sensor_name] = query
@@ -477,7 +308,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
             output.write(yaml.dump(cache_data, default_flow_style=False))
             response = {"success": "Data entry inserted."}
         
-        print match_token, db_mask
+        #print match_token, db_mask
         self.write(response)
         
 class GetDataHandler(tornado.web.RequestHandler):
@@ -489,6 +320,8 @@ class GetDataHandler(tornado.web.RequestHandler):
             except yaml.YAMLError as exc:
                 print(exc)
         print("GetData:")
+        if cache_data == None:
+            cache_data = {}
         print cache_data
         self.write(cache_data) 
 
@@ -503,7 +336,6 @@ application = tornado.web.Application([
     (r"/save/", SaveHandler),
     (r"/getdata/", GetDataHandler),
     (r"/timer/(?P<duration>[^\/]+)/?", SetTimerHandler),
-    (r"/mysql/add/(?P<table_name>[^\/]+)/?(?P<column_name>[^\/]+)?", AddHandler),
     (r"/add/(?P<db_server>[^\/]+)/?(?P<db_name>[^\/]+)/?(?P<db_group>[^\/]+)/?(?P<sensor_name>[^\/]+)?", AdeiKatrinHandler)
 ], debug=True, static_path=os.path.join(root, 'static'), js_path=os.path.join(root, 'js'))
  

+ 0 - 0
position.yaml


+ 2 - 2
res/adei2rest.py

@@ -24,7 +24,7 @@ def main(sensor, mystr):
     #print query
     
     rest_str = []
-    rest_str.append("http://localhost:8888/add")
+    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)
@@ -34,4 +34,4 @@ def main(sensor, mystr):
 
 
 if __name__ == "__main__":
-   main(sys.argv[1], sys.argv[2])
+   main(sys.argv[1], sys.argv[2])

+ 34 - 0
res/style_stable.yaml

@@ -0,0 +1,34 @@
+320-RTP-3-1101:
+  header:
+    size: 27.360000610351563px
+    title: ''
+    weight: '400'
+  height: 112
+  larger: ''
+  left: 1109.97998046875px
+  lesser: ''
+  max: ''
+  min: ''
+  top: 409.9779968261719px
+  unit:
+    size: 40.31999969482422px
+    title: ' K'
+    weight: '400'
+  width: 228
+320-RTY-3-2101:
+  header:
+    size: 27.360000610351563px
+    title: ''
+    weight: '400'
+  height: 69
+  larger: '70'
+  left: 1116.9849853515625px
+  lesser: ''
+  max: '70'
+  min: '0'
+  top: 192.99749755859375px
+  unit:
+    size: 27.360000610351563px
+    title: '   K'
+    weight: '400'
+  width: 158

+ 9 - 0
res/varname_stable.yaml

@@ -0,0 +1,9 @@
+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-RTP-3-6101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=195
+320-RTP-3-7101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=207
+320-RTP-8-1103: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_KRY_Kryo_4K_CurLead&db_mask=all&window=-1&db_mask=33
+320-RTT-1-1107: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_KRY_Kryo_4K&db_mask=all&window=-1&db_mask=42
+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
+320-RTY-3-4101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=231
+320-RTY-3-5101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=240

+ 1 - 1
static/style.css

@@ -15,7 +15,7 @@ span,
 .varval {
     font-family: 'Open Sans', sans-serif;
     font-size: 28px; 
-    font-weight: 700;
+    font-weight: 400;
 }
 
 .button {

+ 13 - 0
status.html

@@ -14,6 +14,8 @@
 </head>
 
 <body>
+
+<div id="page_info">CPS data monitoring. Last refreshed</div>
     
 {% if data['style'] %}
 {% for key in data['style'] %}
@@ -54,6 +56,17 @@ function myTimer() {
                     $(".varval", "#" + key).text(parseFloat(response[key]).toFixed(2));
                 }
             }
+
+
+	    var currentdate = new Date(); 
+	    var datetime = "CPS data monitoring page. Last Sync: " + ( (currentdate.getDate()<10?'0':'').toString() + (currentdate.getDate()).toString() ) + "/"
+                + ( ((currentdate.getMonth()+1)<10?'0':'').toString() + (currentdate.getMonth()+1)).toString()  + "/" 
+                + ( (currentdate.getFullYear()<10?'0':'').toString() + (currentdate.getFullYear()).toString() ) + " @ "  
+                + ( (currentdate.getHours()<10?'0':'').toString() + (currentdate.getHours()).toString() ) + ":"  
+                + ( (currentdate.getMinutes()<10?'0':'').toString() + (currentdate.getMinutes()).toString() ) + ":" 
+                + ( (currentdate.getSeconds()<10?'0':'').toString() + (currentdate.getSeconds()).toString() );
+   	    $("#page_info").text(datetime);
+            console.log(datetime);
         },
         error: function () {
             console.log("Error.")

+ 6 - 23
style.yaml

@@ -3,32 +3,15 @@
     size: 28px
     title: ''
     weight: '400'
-  height: 112.991
-  larger: ''
-  left: 1109.98px
+  height: 79.991
+  larger: '77'
+  left: 734.968px
   lesser: ''
-  max: ''
-  min: ''
-  top: 409.978px
-  unit:
-    size: 40px
-    title: K
-    weight: '400'
-  width: 227.99099999999999
-320-RTY-3-2101:
-  header:
-    size: 28px
-    title: ''
-    weight: '400'
-  height: 68.991
-  larger: '70'
-  left: 744px
-  lesser: ''
-  max: '70'
+  max: '77'
   min: '0'
-  top: 268px
+  top: 266.946px
   unit:
     size: 28px
     title: '  K'
     weight: '400'
-  width: 158.99099999999999
+  width: 191.99099999999999

+ 0 - 20
test.py

@@ -1,20 +0,0 @@
-import yaml
-
-with open("config.yaml", 'r') as stream:
-    try:
-        #print(yaml.load(stream))
-        a = yaml.load(stream)
-    except yaml.YAMLError as exc:
-        print(exc)
-        
-print a
-
-definitions = {"one" : 1, "two" : 2, "three" : 3}
-actions = {"run" : "yes", "print" : "no", "report" : "maybe"}
-
-output = yaml.dump(actions, default_flow_style=False, explicit_start=True)
-output += yaml.dump(definitions, default_flow_style=False, explicit_start=True)
-
-print output
-
-

+ 0 - 8
varname.yaml

@@ -1,9 +1 @@
 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-RTP-3-6101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=195
-320-RTP-3-7101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=207
-320-RTP-8-1103: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_KRY_Kryo_4K_CurLead&db_mask=all&window=-1&db_mask=33
-320-RTT-1-1107: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_KRY_Kryo_4K&db_mask=all&window=-1&db_mask=42
-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
-320-RTY-3-4101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=231
-320-RTY-3-5101: db_server=cscps&db_name=ControlSystem_CPS&db_group=320_STR_Strahlrohr&db_mask=all&window=-1&db_mask=240