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 value_to_str(value, type) {
78 return value+type_to_unit(type);
81 function get_url_params()
86 hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
88 for(i = 0; i < hashes.length; i++) {
89 hash = hashes[i].split('=');
91 vars[hash[0]] = hash[1];
97 function update_chart(chart_id, title, data) {
98 var min_date, max_date, min, max, value;
99 var measures, data_chart, date, entry;
102 measures = data["measures"];
105 $("h1").append(data["name"]);
106 $("title").append(data["name"]);
108 $.each(measures, function(i, item) {
109 value = item["value"];
110 date = new Date(item["time"]*1000);
111 entry = [date, item["value"]];
113 data_chart.push(entry);
115 if (!max_date || max_date < date)
117 if (!min_date || min_date > date)
120 if (!min || value < min)
122 if (!max || value > max)
130 renderer: $.jqplot.DateAxisRenderer,
132 formatString:'%H:%M:%S'
148 $.jqplot (chart_id, [data_chart], style);
151 function update_menu() {
152 var name, link, url, str;
154 $.getJSON("/api/1.0/sensors", function(data) {
155 str = "<li><em>Sensors</em>\n<ul>";
157 $.each(data, function(i, item) {
159 url = "details.html?id="+escape("/api/1.0/sensors/"+item["id"]);
160 link = "<a href='"+url+"'>"+name+"</a>";
161 str += "<li>"+link+"</li>";
166 $("#menu-list").append(str);
171 function update_summary_sensors() {
172 var name, value_str, min_str, max_str, type, type_str, url;
174 $.getJSON("/api/1.0/sensors", function(data) {
175 $.each(data, function(i, item) {
178 value_str = value_to_str(item["last_measure"]["value"], type);
179 min_str = value_to_str(item["min"], type);
180 max_str = value_to_str(item["max"], type);
181 type_str = type_to_str(type);
182 url = "details.html?id="+escape("/api/1.0/sensors/"+item["id"]);
184 $("#sensors").append("<tr>"
185 +"<td><a href='"+url+"'>"+name+"</a></td>"
186 +"<td>"+value_str+"</td>"
187 +"<td>"+min_str+"</td>"
188 +"<td>"+max_str+"</td>"
189 +"<td>"+type_str+"</td>"