Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!-- Temperature Monitoring Graphs -->
- <!-- by Andrew Pattison -->
- <html><head>
- <meta charset="UTF-8">
- <title>Temperature Monitoring</title>
- <link rel="stylesheet" href="../andrew.css" type="text/css">
- <!-- start of jqPlot includes -->
- <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../jqplot/excanvas.js"></script><![endif]-->
- <script language="javascript" type="text/javascript" src="../jqplot/jquery.min.js"></script>
- <script language="javascript" type="text/javascript" src="../jqplot/jquery.jqplot.min.js"></script>
- <link rel="stylesheet" type="text/css" href="../jqplot/jquery.jqplot.css" />
- <!-- end of jqPlot includes -->
- <!-- jqPlot plugins below to enable tooltips, json, dateaxis -->
- <script type="text/javascript" src="../jqplot/plugins/jqplot.highlighter.min.js"></script>
- <script type="text/javascript" src="../jqplot/plugins/jqplot.json2.min.js"></script>
- <script type="text/javascript" src="../jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
- <!-- include date.js so we can easily construct a date in the correct format -->
- <script language="javascript" type="text/javascript" src="../date.js"></script>
- </head>
- <body>
- <h1>Temperature Monitoring</h1>
- <div style="font-size:20px; font-weight: bold;">Room Temperature</div>
- <span id="ambientcharttitle" style="font-weight: bold;"></span>
- <img src="/images/arrow-bold-left.png" onclick="leftAmbientButton()" style="cursor: pointer">
- <img src="/images/arrow-bold-right.png" onclick="rightAmbientButton();" style="cursor: pointer">
- Show:
- <select id="ambientrange" onchange="changeAmbientRange()">
- <option value="sixhours">6 Hours</option>
- <option value="oneday" selected="selected">24 Hours</option>
- <option value="sevendays">7 Days</option>
- </select>
- <span id="ambientgenerated"></span>
- <!-- div to hold the graph -->
- <div id="ambientchart" style="height:300px;width:100%; "></div>
- <div style="font-size:20px; font-weight: bold;">CPU Temperature</div>
- <span id="cpucharttitle" style="font-weight: bold;"></span>
- <img src="/images/arrow-bold-left.png" onclick="leftcpuButton()" style="cursor: pointer">
- <img src="/images/arrow-bold-right.png" onclick="rightcpuButton();" style="cursor: pointer">
- Show:
- <select id="cpurange" onchange="changecpuRange()">
- <option value="sixhours">6 Hours</option>
- <option value="oneday" selected="selected">24 Hours</option>
- <option value="sevendays">7 Days</option>
- </select>
- <span id="cpugenerated"></span>
- <!-- div to hold the graph -->
- <div id="cpuchart" style="height:300px;width:100%; "></div>
- <div style="font-size:20px; font-weight: bold;">Hard Disk Temperature</div>
- <span id="hddcharttitle" style="font-weight: bold;"></span>
- <img src="/images/arrow-bold-left.png" onclick="lefthddButton()" style="cursor: pointer">
- <img src="/images/arrow-bold-right.png" onclick="righthddButton();" style="cursor: pointer">
- Show:
- <select id="hddrange" onchange="changehddRange()">
- <option value="sixhours">6 Hours</option>
- <option value="oneday" selected="selected">24 Hours</option>
- <option value="sevendays">7 Days</option>
- </select>
- <span id="hddgenerated"></span>
- <!-- div to hold the graph -->
- <div id="hddchart" style="height:300px;width:100%; "></div>
- <script language="javascript">
- // functions for ambient temperature graph
- function getAmbientRange() {
- var $ambiente = document.getElementById("ambientrange");
- var $value = $ambiente.options[$ambiente.selectedIndex].value;
- var $text = $ambiente.options[$ambiente.selectedIndex].text;
- return($value);
- }
- function addAmbientRange($positive) {
- // jump graph start and end times forwards
- // or backwards by the amount of $range
- // $positive - true for forwards, false for backwards
- // find out when now is, so we can clamp end date
- var $n = new Date();
- // convert boolean $positive into a multiplier
- if ($positive) $m = 1; else $m = -1;
- switch ($range){
- case "sixhours":
- $ambiente = $ambiente.addHours($m * 6);
- // clamp end datetime to now
- if ($ambiente.valueOf() > $n.valueOf()) $ambiente = new Date();
- $ambients = computeAmbientStart($ambiente);
- return(true);
- break;
- case "oneday":
- $ambiente = $ambiente.addDays($m);
- // clamp end datetime to now
- if ($ambiente.valueOf() > $n.valueOf()) $ambiente = new Date();
- $ambients = computeAmbientStart($ambiente);
- return(true);
- break;
- case "sevendays":
- $ambiente = $ambiente.addDays($m * 7);
- // clamp end datetime to now
- if ($ambiente.valueOf() > $n.valueOf()) $ambiente = new Date();
- $ambients = computeAmbientStart($ambiente);
- return(true);
- break;
- default:
- return(false);
- }
- }
- function clearAmbientChart() {
- document.getElementById("ambientgenerated").textContent = "";
- document.getElementById("ambientcharttitle").textContent = "";
- document.getElementById("ambientchart").textContent = "";
- }
- function leftAmbientButton() {
- // first, get rid of existing graph
- clearAmbientChart();
- addAmbientRange(false);
- doAmbientGraph($ambients, $ambiente);
- }
- function rightAmbientButton() {
- // first, get rid of existing graph
- clearAmbientChart();
- addAmbientRange(true);
- doAmbientGraph($ambients, $ambiente);
- }
- function changeAmbientRange() {
- // update graph in response to user changing
- // which range is selected
- clearAmbientChart();
- $ambients = computeAmbientStart($ambiente);
- doAmbientGraph($ambients, $ambiente);
- }
- function computeAmbientStart($ambientend) {
- // computeStart - find start of graph datetime range
- // based on $range selected, and $ambientend datetime
- // returns - start datetime of range
- $range = getAmbientRange();
- $ambients = new Date($ambiente);
- switch ($range){
- case "sixhours":
- $ambientavg = 1;
- return($ambients.addHours(-6));
- break;
- case "oneday":
- $ambientavg = 2;
- return($ambients.addDays(-1));
- break;
- case "sevendays":
- $ambientavg = 14;
- return($ambients.addDays(-7));
- break;
- default:
- return(false);
- }
- }
- function doAmbientGraph($ambientstart, $ambientend) {
- // $ambientstart - start of datetime range as a Date object
- // $ambientend - end of datetime range as a Date object
- // get current time so we can tell the user
- // when the page was generated
- var $now = new Date()
- var $nowlabel = $now.toString("dd MMM yyyy HH:mm");
- // tell user when page was generated
- document.getElementById("ambientgenerated").textContent = "Graph generated: " + $nowlabel;
- // generate datetime strings to pass to script to get data
- // These are in a format that sqlite3 will understand
- var $ambientstartstring = $ambientstart.toString("yyyy-MM-dd HH:mm");
- var $ambientendstring = $ambientend.toString("yyyy-MM-dd HH:mm");
- //generate 'friendly' datetime strings for output as graph title
- var $ambientstartlabel = $ambientstart.toString("dd MMM yyyy HH:mm");
- var $ambientendlabel = $ambientend.toString("dd MMM yyyy HH:mm");
- // show title outside the graph
- document.getElementById("ambientcharttitle").innerHTML = $ambientstartlabel + " to " + $ambientendlabel;
- // check which range is selected
- var $range = getAmbientRange();
- // data renderer - calls php script which returns JSON data
- var ajaxDataRenderer = function(url, plot, options) {
- var ret = null;
- $.ajax({
- // have to use synchronous here, else the function
- // will return before the data is fetched
- async: false,
- url: url,
- dataType:"json",
- success: function(data) {
- ret = data;
- }
- });
- return ret;
- };
- // The url for our json data
- var jsonambienturl = "./gettemp.php?start='" + $ambientstartstring + "'&end='" + $ambientendstring + "'&sensor=ambient&range=" + $ambientavg;
- // passing in the url string as the jqPlot data argument is a handy
- // shortcut for our renderer. You could also have used the
- // "dataRendererOptions" option to pass in the url.
- var plot3 = $.jqplot('ambientchart', jsonambienturl, {
- //title:$ambientstartlabel + '<br> to <br>' + $ambientendlabel,
- axes:{
- xaxis:{
- renderer:$.jqplot.DateAxisRenderer,
- tickOptions:{formatString:'%H:%M'},
- label:'Time',
- min:$ambientstartstring,
- max:$ambientendstring
- },
- yaxis:{
- label:'Temperature (Celsius)'
- }
- },
- highlighter: {
- tooltipLocation: 'n',
- tooltipAxes: 'y',
- tooltipFormatString: '%.2f C',
- useAxesFormatters: false
- },
- dataRenderer: ajaxDataRenderer,
- dataRendererOptions: {
- unusedOptionalUrl: jsonambienturl
- },
- series:[{lineWidth:2, markerOptions:{show:false}}]
- });
- }
- // functions for cpu temperature graph
- function getcpuRange() {
- var $cpue = document.getElementById("cpurange");
- var $value = $cpue.options[$cpue.selectedIndex].value;
- var $text = $cpue.options[$cpue.selectedIndex].text;
- return($value);
- }
- function addcpuRange($positive) {
- // jump graph start and end times forwards
- // or backwards by the amount of $range
- // $positive - true for forwards, false for backwards
- // find out when now is, so we can clamp end date
- var $n = new Date();
- // convert boolean $positive into a multiplier
- if ($positive) $m = 1; else $m = -1;
- switch ($range){
- case "sixhours":
- $cpue = $cpue.addHours($m * 6);
- // clamp end datetime to now
- if ($cpue.valueOf() > $n.valueOf()) $cpue = new Date();
- $cpus = computecpuStart($cpue);
- return(true);
- break;
- case "oneday":
- $cpue = $cpue.addDays($m);
- // clamp end datetime to now
- if ($cpue.valueOf() > $n.valueOf()) $cpue = new Date();
- $cpus = computecpuStart($cpue);
- return(true);
- break;
- case "sevendays":
- $cpue = $cpue.addDays($m * 7);
- // clamp end datetime to now
- if ($cpue.valueOf() > $n.valueOf()) $cpue = new Date();
- $cpus = computecpuStart($cpue);
- return(true);
- break;
- default:
- return(false);
- }
- }
- function clearcpuChart() {
- document.getElementById("cpugenerated").textContent = "";
- document.getElementById("cpucharttitle").textContent = "";
- document.getElementById("cpuchart").textContent = "";
- }
- function leftcpuButton() {
- // first, get rid of existing graph
- clearcpuChart();
- addcpuRange(false);
- docpuGraph($cpus, $cpue);
- }
- function rightcpuButton() {
- // first, get rid of existing graph
- clearcpuChart();
- addcpuRange(true);
- docpuGraph($cpus, $cpue);
- }
- function changecpuRange() {
- // update graph in response to user changing
- // which range is selected
- clearcpuChart();
- $cpus = computecpuStart($cpue);
- docpuGraph($cpus, $cpue);
- }
- function computecpuStart($cpuend) {
- // computeStart - find start of graph datetime range
- // based on $range selected, and $cpuend datetime
- // returns - start datetime of range
- $range = getcpuRange();
- $cpus = new Date($cpue);
- switch ($range){
- case "sixhours":
- $cpuavg = 1;
- return($cpus.addHours(-6));
- break;
- case "oneday":
- $cpuavg = 5;
- return($cpus.addDays(-1));
- break;
- case "sevendays":
- $cpuavg = 14;
- return($cpus.addDays(-7));
- break;
- default:
- return(false);
- }
- }
- function docpuGraph($cpustart, $cpuend) {
- // $cpustart - start of datetime range as a Date object
- // $cpuend - end of datetime range as a Date object
- // get current time so we can tell the user
- // when the page was generated
- var $now = new Date()
- var $nowlabel = $now.toString("dd MMM yyyy HH:mm");
- // tell user when page was generated
- document.getElementById("cpugenerated").textContent = "Graph generated: " + $nowlabel;
- // generate datetime strings to pass to script to get data
- // These are in a format that sqlite3 will understand
- var $cpustartstring = $cpustart.toString("yyyy-MM-dd HH:mm");
- var $cpuendstring = $cpuend.toString("yyyy-MM-dd HH:mm");
- //generate 'friendly' datetime strings for output as graph title
- var $cpustartlabel = $cpustart.toString("dd MMM yyyy HH:mm");
- var $cpuendlabel = $cpuend.toString("dd MMM yyyy HH:mm");
- // show title outside the graph
- document.getElementById("cpucharttitle").innerHTML = $cpustartlabel + " to " + $cpuendlabel;
- // check which range is selected
- var $range = getcpuRange();
- // data renderer - calls php script which returns JSON data
- var ajaxDataRenderer = function(url, plot, options) {
- var ret = null;
- $.ajax({
- // have to use synchronous here, else the function
- // will return before the data is fetched
- async: false,
- url: url,
- dataType:"json",
- success: function(data) {
- ret = data;
- }
- });
- return ret;
- };
- // The url for our json data
- var jsoncpuurl = "./gettemp.php?start='" + $cpustartstring + "'&end='" + $cpuendstring + "'&sensor=cpu&range=" + $cpuavg;
- // passing in the url string as the jqPlot data argument is a handy
- // shortcut for our renderer. You could also have used the
- // "dataRendererOptions" option to pass in the url.
- var plot3 = $.jqplot('cpuchart', jsoncpuurl, {
- //title:$cpustartlabel + '<br> to <br>' + $cpuendlabel,
- axes:{
- xaxis:{
- renderer:$.jqplot.DateAxisRenderer,
- tickOptions:{formatString:'%H:%M'},
- label:'Time',
- min:$cpustartstring,
- max:$cpuendstring
- },
- yaxis:{
- label:'Temperature (Celsius)'
- }
- },
- highlighter: {
- tooltipLocation: 'n',
- tooltipAxes: 'y',
- tooltipFormatString: '%.2f C',
- useAxesFormatters: false
- },
- dataRenderer: ajaxDataRenderer,
- dataRendererOptions: {
- unusedOptionalUrl: jsoncpuurl
- },
- series:[{lineWidth:2, markerOptions:{show:false}}]
- });
- }
- // functions for hdd temperature graph
- function gethddRange() {
- var $hdde = document.getElementById("hddrange");
- var $value = $hdde.options[$hdde.selectedIndex].value;
- var $text = $hdde.options[$hdde.selectedIndex].text;
- return($value);
- }
- function addhddRange($positive) {
- // jump graph start and end times forwards
- // or backwards by the amount of $range
- // $positive - true for forwards, false for backwards
- // find out when now is, so we can clamp end date
- var $n = new Date();
- // convert boolean $positive into a multiplier
- if ($positive) $m = 1; else $m = -1;
- switch ($range){
- case "sixhours":
- $hdde = $hdde.addHours($m * 6);
- // clamp end datetime to now
- if ($hdde.valueOf() > $n.valueOf()) $hdde = new Date();
- $hdds = computehddStart($hdde);
- return(true);
- break;
- case "oneday":
- $hdde = $hdde.addDays($m);
- // clamp end datetime to now
- if ($hdde.valueOf() > $n.valueOf()) $hdde = new Date();
- $hdds = computehddStart($hdde);
- return(true);
- break;
- case "sevendays":
- $hdde = $hdde.addDays($m * 7);
- // clamp end datetime to now
- if ($hdde.valueOf() > $n.valueOf()) $hdde = new Date();
- $hdds = computehddStart($hdde);
- return(true);
- break;
- default:
- return(false);
- }
- }
- function clearhddChart() {
- document.getElementById("hddgenerated").textContent = "";
- document.getElementById("hddcharttitle").textContent = "";
- document.getElementById("hddchart").textContent = "";
- }
- function lefthddButton() {
- // first, get rid of existing graph
- clearhddChart();
- addhddRange(false);
- dohddGraph($hdds, $hdde);
- }
- function righthddButton() {
- // first, get rid of existing graph
- clearhddChart();
- addhddRange(true);
- dohddGraph($hdds, $hdde);
- }
- function changehddRange() {
- // update graph in response to user changing
- // which range is selected
- clearhddChart();
- $hdds = computehddStart($hdde);
- dohddGraph($hdds, $hdde);
- }
- function computehddStart($hddend) {
- // computeStart - find start of graph datetime range
- // based on $range selected, and $hddend datetime
- // returns - start datetime of range
- $range = gethddRange();
- $hdds = new Date($hdde);
- switch ($range){
- case "sixhours":
- $hddavg = 1;
- return($hdds.addHours(-6));
- break;
- case "oneday":
- $hddavg = 2;
- return($hdds.addDays(-1));
- break;
- case "sevendays":
- $hddavg = 14;
- return($hdds.addDays(-7));
- break;
- default:
- return(false);
- }
- }
- function dohddGraph($hddstart, $hddend) {
- // $hddstart - start of datetime range as a Date object
- // $hddend - end of datetime range as a Date object
- // get current time so we can tell the user
- // when the page was generated
- var $now = new Date()
- var $nowlabel = $now.toString("dd MMM yyyy HH:mm");
- // tell user when page was generated
- document.getElementById("hddgenerated").textContent = "Graph generated: " + $nowlabel;
- // generate datetime strings to pass to script to get data
- // These are in a format that sqlite3 will understand
- var $hddstartstring = $hddstart.toString("yyyy-MM-dd HH:mm");
- var $hddendstring = $hddend.toString("yyyy-MM-dd HH:mm");
- //generate 'friendly' datetime strings for output as graph title
- var $hddstartlabel = $hddstart.toString("dd MMM yyyy HH:mm");
- var $hddendlabel = $hddend.toString("dd MMM yyyy HH:mm");
- // show title outside the graph
- document.getElementById("hddcharttitle").innerHTML = $hddstartlabel + " to " + $hddendlabel;
- // check which range is selected
- var $range = gethddRange();
- // data renderer - calls php script which returns JSON data
- var ajaxDataRenderer = function(url, plot, options) {
- var ret = null;
- $.ajax({
- // have to use synchronous here, else the function
- // will return before the data is fetched
- async: false,
- url: url,
- dataType:"json",
- success: function(data) {
- ret = data;
- }
- });
- return ret;
- };
- // The url for our json data
- var jsonhddurl = "./gettemp.php?start='" + $hddstartstring + "'&end='" + $hddendstring + "'&sensor=hdd&range=" + $hddavg;
- // passing in the url string as the jqPlot data argument is a handy
- // shortcut for our renderer. You could also have used the
- // "dataRendererOptions" option to pass in the url.
- var plot3 = $.jqplot('hddchart', jsonhddurl, {
- //title:$hddstartlabel + '<br> to <br>' + $hddendlabel,
- axes:{
- xaxis:{
- renderer:$.jqplot.DateAxisRenderer,
- tickOptions:{formatString:'%H:%M'},
- label:'Time',
- min:$hddstartstring,
- max:$hddendstring
- },
- yaxis:{
- label:'Temperature (Celsius)'
- }
- },
- highlighter: {
- tooltipLocation: 'n',
- tooltipAxes: 'y',
- tooltipFormatString: '%.2f C',
- useAxesFormatters: false
- },
- dataRenderer: ajaxDataRenderer,
- dataRendererOptions: {
- unusedOptionalUrl: jsonhddurl
- },
- series:[{lineWidth:2, markerOptions:{show:false}}]
- });
- }
- // get current date and time - uses data.js to format string
- var $ambiente = new Date();
- var $ambientavg = 1;
- var $cpue = new Date();
- var $cpuavg = 1;
- var $hdde = new Date();
- var $hddavg = 1;
- // get start datetime, set $ambientavg variable
- // to control how many minutes temperatures
- // are averaged over
- $ambients = computeAmbientStart($ambiente);
- $cpus = computecpuStart($cpue);
- $hdds = computehddStart($hdde);
- $.jqplot.config.enablePlugins = true
- $(document).ready(function(){
- doAmbientGraph($ambients, $ambiente);
- docpuGraph($cpus, $cpue);
- dohddGraph($hdds, $hdde);
- });
- </script>
- <footer>
- <p>Created by andrum99. See my blog at <a href="http://andrum99.blogspot.co.uk">andrum99.blogspot.co.uk</a>.</p>
- </footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement