2 * Copyright (C) 2010-2011 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 function format_mem_size(s) {
21 var mo_bytes, go_bytes, o, k, m, g;
23 mo_bytes = 1024 * 1024;
24 go_bytes = 1024 * mo_bytes;
27 k = Math.round((s / 1024) % 1024);
28 m = Math.round((s / (1024*1024)) % 1024);
29 g = Math.round(s / (1024*1024*1024));
46 function type_to_str(stype) {
53 else if (stype & 0x0200)
55 else if (stype & 0x0400)
57 else if (stype & 0x1000)
61 stype_str += " Temperature";
62 else if (stype & 0x0002)
68 function type_to_unit(stype) {
71 else if (stype & 0x0002)
77 function get_url_params()
82 hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
84 for(i = 0; i < hashes.length; i++) {
85 hash = hashes[i].split('=');
87 vars[hash[0]] = hash[1];
93 function update_chart(chart_id, title, data) {
94 var min_date, max_date, min, max, value;
95 var measures, data_chart, date, entry;
98 measures = data["measures"];
101 $("h1").append(data["name"]);
102 $("title").append(data["name"]);
104 $.each(measures, function(i, item) {
105 value = item["value"];
106 date = new Date(item["time"]*1000);
107 entry = [date, item["value"]];
109 data_chart.push(entry);
111 if (!max_date || max_date < date)
113 if (!min_date || min_date > date)
116 if (!min || value < min)
118 if (!max || value > max)
126 renderer: $.jqplot.DateAxisRenderer,
128 formatString:'%H:%M:%S'
144 $.jqplot (chart_id, [data_chart], style);
147 function update_menu() {
148 var name, link, url, str;
150 $.getJSON("/api/1.0/sensors", function(data) {
151 str = "<li><em>Sensors</em>\n<ul>";
153 $.each(data, function(i, item) {
155 url = "details.html?id="+escape("/api/1.0/sensors/"+item["id"]);
156 link = "<a href='"+url+"'>"+name+"</a>";
157 str += "<li>"+link+"</li>";
162 $("#menu-list").append(str);