lightwaverf 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/app/views/_graphs.ejs +19 -40
  2. data/lib/lightwaverf.rb +2 -3
  3. metadata +2 -2
@@ -1,51 +1,30 @@
1
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
2
- <script src="https://www.google.com/jsapi"></script>
1
+ <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
3
2
  <script>
4
3
  var gauge, gauge_data, gauge_options;
5
- google.load( 'visualization', '1.0', { packages: [ 'corechart', 'gauge', 'annotatedtimeline' ] } );
6
- google.setOnLoadCallback( function ( ) {
7
- var energy_data = new google.visualization.DataTable( );
8
- energy_data.addColumn( 'date', 'Date' );
9
- energy_data.addColumn( 'number', 'Electricity used' );
10
- energy_data.addColumn( 'string', 'title1' );
11
- energy_data.addColumn( 'string', 'text1' );
12
- if ( ! Array.prototype.map ) { // polyfill
13
- Array.prototype.map = function( callback, thisArg ) {
14
- var T, A, k;
15
- if ( this == null ) throw new TypeError( 'this is null or not defined' );
16
- var O = Object(this);
17
- var len = O.length >>> 0;
18
- if ( typeof callback !== 'function' ) throw new TypeError( callback + ' is not a function' );
19
- if ( thisArg ) T = thisArg;
20
- A = new Array( len );
21
- k = 0;
22
- while ( k < len ) {
23
- var kValue, mappedValue;
24
- if ( k in O ) {
25
- kValue = O[ k ];
26
- mappedValue = callback.call(T, kValue, k, O);
27
- A[ k ] = mappedValue;
28
- }
29
- k ++;
30
- }
31
- return A;
32
- };
33
- }
4
+ google.charts.load('current', { packages: ['annotationchart'] });
5
+ google.charts.setOnLoadCallback(function() {
6
+ var energy_data = new google.visualization.DataTable();
7
+ energy_data.addColumn('date', 'Date');
8
+ energy_data.addColumn('number', 'Electricity used');
9
+ energy_data.addColumn('string', 'title1');
10
+ energy_data.addColumn('string', 'text1');
34
11
  var rawData = <%- summary %>;
35
12
  // var startDate = rawData[0][0];
36
13
  var i = 0;
37
- energy_data.addRows( rawData.map( function ( e ) {
14
+ energy_data.addRows(rawData.map(function(e) {
38
15
  ++ i;
39
16
  // if ( e[0] !== startDate ) e[0] += startDate;
40
17
  e[0] = new Date( e[0] * 1000 ); // as it is now a timestamp
41
- e[1] = e[1] * 10;
18
+ // e[1] = e[1] * 10;
42
19
  e[2] = e[2] || '';
43
20
  e[3] = e[3] || '';
44
21
  return e;
45
- } ));
46
- var chart = new google.visualization.AnnotatedTimeLine( document.getElementById( 'energy_chart' ));
47
- chart.draw( energy_data, { displayAnnotations: true, title: '24 hours electricity usage' } );
48
- gauge = new google.visualization.Gauge( document.getElementById( 'gauge_div' ));
22
+ }));
23
+ var chart = new google.visualization.AnnotationChart(document.getElementById('energy_chart'));
24
+ var d = new Date();
25
+ d.setDate(d.getDate() - 1);
26
+ chart.draw(energy_data, { zoomStartTime: d, displayAnnotations: true, title: 'Electricity usage' });
27
+ gauge = new google.visualization.Gauge(document.getElementById('gauge_div'));
49
28
  gauge_data = google.visualization.arrayToDataTable( [[ 'Label', 'Value' ], [ 'Electric', rawData.pop[ 1 ]]] );
50
29
  gauge_options = {
51
30
  width: '200',
@@ -57,9 +36,9 @@
57
36
  minorTicks: 5
58
37
  };
59
38
  gauge.draw( gauge_data, gauge_options );
60
- } );
61
- $( function ( ) {
62
- var key = ''; // @todo prompt for an pi key and save it in local storage like https://github.com/pauly/robot-butler does
39
+ });
40
+ window.$ && $( function ( ) {
41
+ var key = ''; // @todo prompt for an api key and save it in local storage like https://github.com/pauly/robot-butler does
63
42
  $('dt a').click( function ( ) {
64
43
  $(this).parent( ).next('dd').slideDown( );
65
44
  return false;
data/lib/lightwaverf.rb CHANGED
@@ -1140,7 +1140,6 @@ class LightWaveRF
1140
1140
  <div id="energy_chart">
1141
1141
  Not seeing an energy chart here?
1142
1142
  Maybe not working in your device yet, sorry.
1143
- This uses google chart api which may generate FLASH :-(
1144
1143
  Try in a web browser.
1145
1144
  </div>
1146
1145
  <h2>Rooms and devices</h2>
@@ -1191,13 +1190,13 @@ class LightWaveRF
1191
1190
  if last != 0 and prev != 0
1192
1191
  smoothedUsage = ( smoothedUsage + last + prev ) / 3 # average of last 3 readings
1193
1192
  end
1194
- new_line << smoothedUsage / 10
1193
+ new_line << smoothedUsage
1195
1194
  if line['message']['annotation'] and line['message']['annotation']['title'] and line['message']['annotation']['text']
1196
1195
  new_line << line['message']['annotation']['title']
1197
1196
  new_line << line['message']['annotation']['text']
1198
1197
  end
1199
1198
  data << new_line
1200
- if (( ! daily[d] ) or ( line['message']['today'] > daily[d]['today'] ))
1199
+ if (( ! daily[d] ) or ( line['message']['today'].to_i > daily[d]['today'].to_i ))
1201
1200
  daily[d] = line['message']
1202
1201
  daily[d].delete 'usage'
1203
1202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightwaverf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-01-11 00:00:00.000000000 Z
14
+ date: 2016-02-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: htmlentities