X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=www%2Fpsensor.js;h=3e902853faa99053eb469f835de90d936cdcdd7c;hb=c1e20f2631a1249720e9c75d753eacfcb0f6c7b9;hp=2092509ff6aef41863f2becf0cfc08b4be332226;hpb=fd891ed38f7adf8b3925b37e8de5bb827f61da58;p=psensor.git diff --git a/www/psensor.js b/www/psensor.js index 2092509..3e90285 100644 --- a/www/psensor.js +++ b/www/psensor.js @@ -1,11 +1,32 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + function format_mem_size(s) { - var mo_bytes = 1024 * 1024; - var go_bytes = 1024 * mo_bytes; + var mo_bytes, go_bytes, o, k, m, g; + + mo_bytes = 1024 * 1024; + go_bytes = 1024 * mo_bytes; - var o = s % 1024; - var k = Math.round((s / 1024) % 1024); - var m = Math.round((s / (1024*1024)) % 1024); - var g = Math.round(s / (1024*1024*1024)); + o = s % 1024; + k = Math.round((s / 1024) % 1024); + m = Math.round((s / (1024*1024)) % 1024); + g = Math.round(s / (1024*1024*1024)); if (g >= 1) return g+"Go "; @@ -20,36 +41,238 @@ function format_mem_size(s) { return o+"o"; return "0"; -}; +} function type_to_str(stype) { - var stype_str = "N/A"; - - if (stype & 0x0100) { - stype_str = "Sensor"; - } else if (stype & 0x0200) { - stype_str = "NVidia"; - } else if (stype & 0x0400) { - stype_str = "HDD"; - } else if (stype & 0x1000) { - stype_str = "AMD"; - } + var stype_str; + + if (stype & 0x0200) + stype_str = "NVidia "; + else if (stype & 0x0800) + stype_str = "ATI/AMD "; + else + stype_str = ""; + + if (stype & 0x04000) + stype_str += "HDD "; + else if (stype & 0x08000) + stype_str += "CPU "; + else if (stype & 0x10000) + stype_str += "GPU "; + else if (stype & 0x20000) + stype_str += "Fan "; - if (stype & 0x0001) { - stype_str += " Temperature"; - } else if (stype & 0x0002) { - stype_str += " Fan"; - } + if (stype & 0x0001) + stype_str += "Temperature"; + else if (stype & 0x0002) + stype_str += "RPM"; + else if (stype & 0x0004) + stype_str += "Load"; return stype_str; -}; +} function type_to_unit(stype) { - if (stype & 0x0001) { - unit = " C"; - } else if (stype & 0x0002) { - unit = " RPM"; - } + if (stype & 0x0001) + unit = "C"; + else if (stype & 0x0002) + unit = "RPM"; return unit; } + +function value_to_str(value, type) { + return value+type_to_unit(type); +} + +function get_url_params() { + var vars, hashes, i; + + vars = []; + hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + + for(i = 0; i < hashes.length; i++) { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + + return vars; +} + +function update_chart(chart_id, title, data) { + var min_date, max_date, min, max, value; + var measures, data_chart, date, entry; + var style; + + $("#"+chart_id).html(""); + + measures = data["measures"]; + data_chart = []; + + $("h1").html(""); + $("h1").append(data["name"]); + + try { + $("title").html(data["name"]); + } catch(ignore) { + // IE8 doesn't allow to modify the page title + } + + $.each(measures, function(i, item) { + value = item["value"]; + date = new Date(item["time"]*1000); + entry = [date, item["value"]]; + + data_chart.push(entry); + + if (!max_date || max_date < date) + max_date = date; + if (!min_date || min_date > date) + min_date = date; + + if (!min || value < min) + min = value; + if (!max || value > max) + max = value; + }); + + style = { + title: title, + axes: { + xaxis: { + renderer: $.jqplot.DateAxisRenderer, + tickOptions: { + formatString:'%H:%M:%S' + }, + min: min_date, + max: max_date + }, + yaxis: { + min: min-1, + max: max+1 + } + }, + series: [ { + lineWidth: 1, + showMarker: false + } ] + }; + + + $.jqplot (chart_id, [data_chart], style); +} + +function update_menu() { + var name, link, url, str; + + str = ""; + + $.getJSON("/api/1.1/sensors", function(data) { + str += "