X-Git-Url: http://www.average.org/gitweb/?p=pulsecounter.git;a=blobdiff_plain;f=web%2Findex.html;h=9170885ed902f4ce41728adc2dace7b4e6bf5ab9;hp=9e459a20450ddcba8543270404b1fdbe25633d8f;hb=97b05be5674c0fa9562ce531a12f89e7462dcc6b;hpb=6db8bb22e8ead45eede4226e6cfb9682e206fb1b diff --git a/web/index.html b/web/index.html index 9e459a2..9170885 100644 --- a/web/index.html +++ b/web/index.html @@ -13,12 +13,42 @@ var xzero = 20, yzero = 20; var cold_d = [], hot_d = []; + function showdate(utime) { + var dt = new Date(utime*1000); + return dt.toLocaleDateString() + " " + dt.toLocaleTimeString(); + } + + function getcomb(lo, hi) { + var comb = [], lb = []; + var d = hi - lo; + var ord = Math.pow(10, Math.floor(Math.log10(d))); + var scl = Math.floor(d / ord); + var inc, inc2, first, x, lb; + + if (scl < 2) { inc = 0.1; inc2 = 0.5; } + else if (scl < 5) { inc = 0.2; inc2 = 1; } + else { inc = 0.5; inc2 = 2; } + inc *= ord; + inc2 *= ord; + first = (Math.floor(lo / inc) + 1) * inc; + for (x = 0; x < (d / inc) - 1.5; x++) + comb.push(first + inc * x); + first = (Math.floor(lo / inc2) + 1) * inc2; + for (x = 0; x < (d / inc2) - 1.5; x++) + lb.push(first + inc2 * x); + //dbg.innerHTML = "ord=" + ord + "
inc=" + inc + "
" + // + comb + "
" + lb; + return [comb, lb]; + } + function px(x) { return xzero + ((x - tmin) * tfact); } + function py(y) { return wh - yzero - (y * hfact); } + function xaxis() { ctx.beginPath(); ctx.moveTo(px(tmin), py(0)); @@ -26,13 +56,34 @@ ctx.strokeStyle = "black"; ctx.stroke(); } + function yaxis() { + var comb = getcomb(0, hmax); + var i; + + ctx.beginPath(); + for (i = 0; comb[0][i]; i++) { + ctx.moveTo(px(tmin) - 5, py(comb[0][i])); + ctx.lineTo(px(tmax), py(comb[0][i])); + } + ctx.strokeStyle = "lightgray"; + ctx.stroke(); + ctx.beginPath(); ctx.moveTo(px(tmin), py(0)); ctx.lineTo(px(tmin), py(hmax)); ctx.strokeStyle = "black"; ctx.stroke(); + + ctx.fillStyle = "black"; + ctx.font = "bold 8px Courier"; + ctx.fillText(0, px(tmin) - 8, py(0)); + for (i = 0; comb[1][i]; i++) { + ctx.fillText(comb[1][i], px(tmin) - xzero + 2, py(comb[1][i])); + } + ctx.fillText("l/h", px(tmin) + 2, py(hmax) + 8); } + /* @ updates global var `hmax` */ function differentiate(times) { var res = []; @@ -51,6 +102,7 @@ return res; } + function drawplot(data, color) { var i; @@ -63,21 +115,26 @@ ctx.strokeStyle = color; ctx.stroke(); } + function showloading() { ctx.fillStyle = "green"; ctx.font = "bold 16px Courier"; ctx.fillText("loading", (ww / 2) - 40 , (wh / 2) + 8); } + function clearplot() { ctx.clearRect(0, 0, ww, wh); } + function redraw() { if (cold_d.length && hot_d.length) { + tfact = (ww - xzero) / (tmax - tmin); + hfact = (wh - yzero) / hmax; clearplot(); - drawplot(cold_d, "blue"); - drawplot(hot_d, "red"); xaxis(); yaxis(); + drawplot(cold_d, "blue"); + drawplot(hot_d, "red"); } else { showloading(); } @@ -90,22 +147,25 @@ (data.current.hot / 100).toFixed(2); tmin = data.range.lo; tmax = data.range.hi; - tfact = (ww - xzero) / (tmax - tmin); + dbg.innerHTML = "from " + tmin + " to " + tmax + + "
from " + showdate(tmin) + " to " + showdate(tmax); /* differetiate() updates hmax */ hmax = 0; cold_d = differentiate(data.cold); hot_d = differentiate(data.hot); - hfact = (wh - yzero) / hmax; //dbg.innerHTML = "hmax=" + hmax + " hfact=" + hfact + "
" // + cold_d + "
" + hot_d; redraw(); } + function iso2qu(idate) { + return idate.replace("T", "+").replace("0Z", ""); + } + function sendquery(lo, hi) { - var url = "query.cgi"; + var url = "query.cgi" + "?lo=" + iso2qu(lo) + "&hi=" + iso2qu(hi); - if (lo && hi) url += "?lo=" + lo + "&" + hi; - else url = "query.cgi?lo=2015-12-19+00:00:00&hi=2015-12-20+00:00:00"; //FIX + //dbg.innerHTML = url; xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // dbg.innerHTML = xmlhttp.responseText; @@ -129,12 +189,21 @@ } function initialize() { + var tdy = new Date(); + var tmr; + + tdy.setMilliseconds(0); + tdy.setSeconds(0); + tdy.setMinutes(0); + tdy.setHours(0); + tmr = new Date(1*tdy + 86400000); dbg = document.getElementById("debug"); canvas = document.getElementById("plot"); ctx = canvas.getContext("2d"); - xmlhttp = new XMLHttpRequest(); resize(); - sendquery(); + + xmlhttp = new XMLHttpRequest(); + sendquery(tdy.toISOString(), tmr.toISOString()); } /* Set up */ @@ -147,8 +216,18 @@ } Water Meters -

Water Meters

+

WATER METERS

Current Values
cold