HighInBC

Untitled

Oct 18th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for (i=0,data=[];i<360; ++i) data[i] = null;
  2. var box_data;
  3.  
  4. var average;
  5. for (i=0,average=[];i<10; ++i) average[i] = null;
  6.  
  7. window.onload = function () {
  8.   var line = new RGraph.Line({
  9.     id: 'cvs',
  10.     data: data,
  11.     options: {
  12.       labels: [ '60', '55', '50', '45', '40', '35', '30', '25', '20', '15', '10', '5', '0' ],
  13.       backgroundHbars: [
  14.         [23.49,0.02,'rgba(0,0,0,1)'],
  15.         [23,1,'rgba(0,255,0,0.2)'],
  16.       ],
  17.       xaxispos: 'bottom',
  18.       ymax: 26,
  19.       ymin: 22,
  20.       linewidth: 1,
  21.       hmargin: 5,
  22.       colors: ['black'],
  23.       textAccessible: true
  24.     }
  25.   }).draw();
  26.  
  27.   function draw() {
  28.     var sum = 0;
  29.     var count = 0;
  30.     for (var i = 0; i < average.length; i++) {
  31.       if( average[i] != null ) {
  32.         sum += average[i];
  33.         count++;
  34.       }
  35.     }
  36.     var graph_point = sum / count;
  37.  
  38.     line.original_data[0].push(graph_point);
  39.     line.original_data[0].shift();
  40.     RGraph.clear(line.canvas);
  41.     line.draw();
  42.     setTimeout(draw, 10000);
  43.   }
  44.   setTimeout(draw, 10000);
  45. };
  46.  
  47. function update() {
  48.   $.getJSON( "./json" )
  49.     .done(function( data ) {
  50.       box_data = data;
  51.       var logic_mode;
  52.       if( data.mode == "T" ) {
  53.         logic_mode = "Thermostat";
  54.       } else if ( data.mode == "P" ) {
  55.         logic_mode = "PID";
  56.       } else {
  57.         logic_mode = "Unknown";
  58.       }
  59.       var percent = data.rate * 100 / data.windowSize;
  60.       $("#window_size").text(data.windowSize/1000);
  61.       $("#rate").text(parseFloat(Math.round(data.rate*1000)/1000000).toFixed(5));
  62.       $("#percent").text(Math.round(percent*10000)/10000);
  63.       $("#target").text(data.target);
  64.       $("#temperature").text(data.temperature);
  65.       $("#logic_mode").text(logic_mode);
  66.       average.push(data.temperature);
  67.       average.shift();
  68.     });
  69. };
  70. window.setInterval(update, 1000);
Advertisement
Add Comment
Please, Sign In to add comment