Commits

Ashley Felton  committed 06c02e0

Swapped out jQuery flot for Highcharts lib.

  • Participants
  • Parent commits cf449e7

Comments (0)

Files changed (3)

File temper/templates/temp_graph.html

 <div class="row-fluid">
     <div class="span12">
         <h1>Temperature log</h1>
+        <h3>Current: {{ current_temp}} &deg;C</h3>
         <div id="graph-placeholder" style="width: 100%; height: 600px;"></div>
     </div>
 </div>
 
 {% block extra_js %}
 <script src="//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
-<script src="//cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.min.js"></script>
+<script src="//code.highcharts.com/highcharts.js"></script>
 <script type="text/javascript">
     var temps_li = {{ temps_li|safe }};
     // Interate over the array and convert times to milliseconds.
         this[0] = d;
     });
     // Create the graph.
-    $.plot($("#graph-placeholder"), [temps_li], {xaxis: {mode: "time"}});
+    //$.plot($("#graph-placeholder"), [temps_li], {xaxis: {mode: "time"}});
+    $(function() {
+        chart1 = new Highcharts.Chart({
+            chart: {renderTo: "graph-placeholder", type: 'spline'},
+            title: {text: "Temperature history"},
+            xAxis: {type: "datetime", title: {text: "Date"}},
+            yAxis: {title: {text: 'Degrees C'}},
+            plotOptions: {
+                series: {
+                    marker: {
+                        enabled: false,
+                        states: {
+                            hover: {
+                                enabled: true
+                            }
+                        }
+                    }
+                }
+            },
+            tooltip: {
+                formatter: function() {
+                        return '<b>'+ this.series.name +'</b><br/>'+
+                        Highcharts.dateFormat('%d-%b %H:%M', this.x) +': '+ this.y +'C';
+                }
+            },
+            series: [{
+                name: 'Office',
+                data: temps_li
+            }]
+        });
+    });
 </script>
 {% endblock %}

File temper/utils.py

     '''
     crc_ok = False
     tries = 0
-    temp= None
+    temp = None
     while not crc_ok and tries < 20:
         # Bitbang the 1-wire interface.
         s = subprocess.check_output('cat /sys/bus/w1/devices/28-*/w1_slave', shell=True).strip()

File temper/views.py

     return render_template('index.html')
 
 @app.route('/temps')
-@cache.cached()
+#@cache.cached()
 def temps_week():
     # Read up to 7 days-worth of log files.
     temps_li = utils.read_logs(n=7)
-    return render_template('temp_graph.html', log_date=log_date, temps_li=json.dumps(temps_li))
+    current_temp = '{:.1f}'.format(temps_li[-1][1])
+    return render_template('temp_graph.html', log_date=log_date, current_temp=current_temp, temps_li=json.dumps(temps_li))
 
 
 @app.route('/temps/all')
 def temps_all():
     # Read all log files.
     temps_li = utils.read_logs()
-    return render_template('temp_graph.html', log_date=log_date, temps_li=json.dumps(temps_li))
+    current_temp = '{:.1f}'.format(temps_li[-1][1])
+    return render_template('temp_graph.html', log_date=log_date, current_temp=current_temp, temps_li=json.dumps(temps_li))
 
 
 @app.route('/temps/<int:year>/<int:month>/<int:day>')
     log_date = '{0}-{1}-{2}'.format(year, month, day)
     log_date = datetime.strptime(log_date, '%Y-%m-%d')
     temps_li = utils.read_log(log_date)
-    return render_template('temp_graph.html', log_date=log_date, temps_li=json.dumps(temps_li))
+    current_temp = '{:.1f}'.format(temps_li[-1][1])
+    return render_template('temp_graph.html', log_date=log_date, current_temp=current_temp, temps_li=json.dumps(temps_li))
 
 
 @app.route('/leds')