Browse Source

Update

Signed-off-by: Nicholas Tan Jerome <nicholas.tanjerome@kit.edu>
Nicholas Tan Jerome 4 years ago
parent
commit
8de15030ee
5 changed files with 95 additions and 23 deletions
  1. 54 15
      core.py
  2. 21 7
      index.html
  3. 0 1
      static/background.png
  4. BIN
      static/background.png
  5. 20 0
      static/style.css

+ 54 - 15
core.py

@@ -11,6 +11,7 @@ import datetime
 from shutil import copyfile
 from time import gmtime, strftime
 import time
+import calendar
 
 import tornado.escape
 import tornado.ioloop
@@ -64,6 +65,20 @@ class RepeatedTimer(object):
         self.interval = interval
     
 
+months = {
+    'Jan' : 1,
+    'Feb' : 2,
+    'Mar' : 3,
+    'Apr' : 4,
+    'May' : 5,
+    'Jun' : 6,
+    'Jul' : 7,
+    'Aug' : 8,
+    'Sep' : 9, 
+    'Oct' : 10,
+    'Nov' : 11,
+    'Dec' : 12
+}
 
 
 def fetchDataADEI():
@@ -84,37 +99,60 @@ def fetchDataADEI():
     #time_range = str((curtime-1800)) + "-" + str(curtime)
     time_range = "-1" 
     for param in varname:
-        print param
+        #print param
         dest = config['server'] + config['script']
         #url = dest + "?" + varname[param] + "&window=-1"
         url = dest + "?" + varname[param] + "&window=" + time_range
-        print url
+        #print url
+        #print config['username'], config['password']
         data = requests.get(url,
                             auth=(config['username'],
                                   config['password'])).content
         #tmp_data = data.content
-        #print "CHECK THIS"
+        
         #print data
 
-        last_value = data.split(",")[-1].strip()
+        # Date/Time, p_string2
+        # 11-Aug-17 14:49:32.446682, 0.495
+        lines = data.splitlines()
+        if len(lines) < 2:
+	    print "No data:"
+	    print "URL:  " + url
+	    print "\n"
+	    continue
+
+        tmp_data = lines[-1]
+        last_value = tmp_data.split(",")[-1].strip()
+        first_value = tmp_data.split(",")[-2].strip()
         try:
-            print last_value
+            #print last_value
             test_x = float(last_value)
         except ValueError:
             last_value = ""
- 	    print last_value
-        cache_data[param] = last_value
-        #current_timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
-        current_timestamp = strftime("%Y-%m-%d %H:%M:%S")
-        cache_data['time'] = current_timestamp
+ 	    #print last_value
+
+	try:
+	    time_buffer = first_value.split("-")
+	    time_buffer[1] = str(months[time_buffer[1]])
+	    first_value = "-".join(time_buffer)
+	    first_ts = calendar.timegm(datetime.datetime.strptime(first_value, "%d-%m-%y %H:%M:%S.%f").timetuple())
+
+	    cache_data[param] = {'timestamp': first_ts, 'value': last_value}
+        
+	    #current_timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
+	    current_timestamp = strftime("%Y-%m-%d %H:%M:%S")
+	    cache_data['time'] = {"value": current_timestamp}
+	except:
+	    print "Problem parsing data:"
+	    print "URL:  " + url
+	    print "Data: " + first_value
+	    print "\n"
 
     with open(".tmp.yaml", 'w') as stream_tmp:
         stream_tmp.write(yaml.dump(cache_data, default_flow_style=False))
     src_file = os.getcwd() + "/.tmp.yaml"
     dst_file = os.getcwd() + "/cache.yaml"
     shutil.copy(src_file, dst_file)
-    
-    
 
     
 print "Start torrenting..."
@@ -294,7 +332,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
         data = requests.get(url, auth=(config['username'], config['password']))
         cr = data.content
         cr = cr.split(",")
-        print cr, len(cr)
+        #print cr, len(cr)
        
 
         # handling the inconsistency on naming convention
@@ -364,16 +402,17 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
 
 class GetDataHandler(tornado.web.RequestHandler):
     def get(self):
+        cache_data = None
         with open("cache.yaml", 'r') as stream:
             try:
                 #print(yaml.load(stream))
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
                 print(exc)
-        print("GetData:")
+        #print("GetData:")
         if cache_data == None:
             cache_data = {}
-        print cache_data
+        #print cache_data
         self.write(cache_data) 
 
     

+ 21 - 7
index.html

@@ -21,6 +21,8 @@
     <div id="slider-tooltip"></div>
     <div id="obj-tooltip">Module: </div>
     <div id="val-tooltip">Power: </div>
+    <div id="ts-tooltip">Last fetched (ADEI): </div>
+    <div id="delta-tooltip">Delta Time: </div>
     <!--<div id="stat-tooltip">Status: </div>-->
     <div class="window-item window-unitem" id="message">
         <div class="bar-header">
@@ -3571,8 +3573,13 @@ scene.add(pv101a);
                 //console.log(intersects);
 	        for ( var i = 0; i < intersects.length; i++ ) {
                     if (intersects[ i ].object.name != "" && intersects[ i ].object.name != "legend") {
+                        delta = (new Date().getTime()/1000.0) - data[ intersects[ i ].object.name ]["timestamp"];
+                        var dateTime = new Date( data[ intersects[ i ].object.name ]["timestamp"]*1000.0 );
                         $("#obj-tooltip").text("Array: " + intersects[ i ].object.name);
-                        $("#val-tooltip").text("Power: " + parseFloat(data[ intersects[ i ].object.name ]).toFixed(3) + " kW");
+                        $("#val-tooltip").text("Power: " + parseFloat(data[ intersects[ i ].object.name ]["value"]).toFixed(3) + " kW");
+                        //$("#ts-tooltip").text("Last fetched (ADEI): " + dateTime.toUTCString());
+                        $("#ts-tooltip").text("Last fetched (ADEI): " + dateTime.toString());
+                        $("#delta-tooltip").text("Delta Time: " + parseFloat(delta).toFixed(3) + " s (" + parseFloat(delta / 60.0).toFixed(3) + " min)");
                     }
             }
             
@@ -3819,6 +3826,7 @@ jQuery(window).load(function () {
 
 
 myTimer();
+// set higher delay, but need to trigger change
 var myVar = setInterval(myTimer, 1000);
 //clearInterval(refreshIntervalId);
 
@@ -4023,10 +4031,11 @@ function myTimer() {
             data = response;
             var obj = response;
             for (var prop in obj) {
-                value = obj[prop];
                 if (prop == "time") {
-                    $("#slider-tooltip").text(value);
+                    $("#slider-tooltip").text(obj[prop]["value"]);
                 } else {
+                    value = obj[prop]["value"];
+                    delta = (new Date().getTime() / 1000.0) - obj[prop]["timestamp"]
                     var mode = $('input[type=radio][name=moduleMode]:checked').val();
                     current_type = prop.split("_")[0][1];
                     current_array = parseInt(prop.split("_")[3]) - 1;
@@ -4037,11 +4046,16 @@ function myTimer() {
                             scene.remove(legend_object);
                         }
                         //animate();
-                        if (value <= 0) {
-                            colour = "0xff0000";
+                        if (delta > 600) {
+                            //colour = "0xff8c00";
+                            colour = "0xffd700";
                         } else {
-                            //colour = "0x242b72";
-                            colour = "0x00ff00";
+                            if (value <= 0) {
+                                colour = "0xff0000";
+                            } else {
+                                //colour = "0x242b72";
+                                colour = "0x00ff00";
+                            }
                         }
                     } else if (mode == "1") {
                         legend_object = scene.getObjectByName( "legend", true );

+ 0 - 1
static/background.png

@@ -1 +0,0 @@
-cps_02.png

BIN
static/background.png


+ 20 - 0
static/style.css

@@ -109,6 +109,26 @@ table {
     font-size: 100%;
 }
 
+#ts-tooltip {
+    position: absolute;
+    top: 180px;
+    right: 0px;
+    width: 20%;
+    font-family: 'Source Code Pro';
+    color: #808080;
+    font-size: 100%;
+}
+
+#delta-tooltip {
+    position: absolute;
+    top: 230px;
+    right: 0px;
+    width: 20%;
+    font-family: 'Source Code Pro';
+    color: #808080;
+    font-size: 100%;
+}
+
 #stat-tooltip {
     position: absolute;
     top: 100px;