<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
- var dbg;
+ var dbg, errordiv;
var canvas, ctx;
var ww, wh;
var hmax, hfact;
var tmin, tmax, tfact;
- var xzero = 40, yzero = 48;
+ var xzero = 60, yzero = 48;
var cold_d = [], hot_d = [];
function showdate(utime) {
const mn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
- function getcombx(lo, hi) {
+ function getcombx(tmin, tmax) {
var comb = [], lb = [];
var trange = tmax - tmin;
- var inc, inc2, base, t, dt;
+ var inc, inc2, base, base2, t, dt, zoff;
var label = function(t) { return "<<" + t.toFixed(1) + ">>"; }
function tohour(t) { var dt = new Date(t*1000); return dt.getHours(); }
function todow(t) { var dt = new Date(t*1000); return dow[dt.getDay()]; }
else { /* ~ one month */
/* TODO: make this a separate case with loop over months rather than
fixed number of seconds. */
- inc = 2592000;
+ inc = 86400;
inc2 = 2592000;
label = tomonth;
}
dt = new Date(tmin*1000);
- base = (Math.floor(tmin / inc) + 1) * inc + 60 * dt.getTimezoneOffset();
+ zoff = 60 * dt.getTimezoneOffset();
+ base = (Math.floor((tmin - zoff - 1) / inc) + 1) * inc + zoff;
for (t = base; t < tmax; t += inc)
comb.push(t);
- base = (Math.floor(tmin / inc2) + 1) * inc2 + 60 * dt.getTimezoneOffset();
- for (t = base; t < tmax; t += inc2)
+ base2 = (Math.floor((tmin - zoff - 1) / inc2) + 1) * inc2 + zoff;
+ for (t = base2; t < tmax; t += inc2)
lb.push([t, label(t)]);
- //dbg.innerHTML = "ord=" + ord + "<br>inc=" + inc + "<br>"
+ //dbg.innerHTML = "inc=" + inc + "<br>inc2=" + inc2 + "<br>"
+ // + "tmin=" + tmin + " tmax=" + tmax + "<br>"
+ // + "base=" + base + " base2=" + base2 + "<br>"
// + comb + "<br>" + lb;
return [comb, lb];
}
function xaxis() {
- var comb = getcombx(0, hmax);
+ var comb = getcombx(tmin, tmax);
var i;
ctx.beginPath();
}
function redraw() {
+ errordiv.style.visibility = "hidden";
+ errordiv.innerHTML = "";
clearplot();
if (cold_d.length || hot_d.length) {
tfact = (ww - xzero) / (tmax - tmin);
}
function gotdata(data) {
- document.getElementById("cold").innerHTML =
+ document.getElementById("curcold").innerHTML =
(data.current.cold / 100).toFixed(2);
- document.getElementById("hot").innerHTML =
+ document.getElementById("curhot").innerHTML =
(data.current.hot / 100).toFixed(2);
+
+ if (data.cold.length)
+ document.getElementById("totcold").innerHTML =
+ ((data.cold[data.cold.length - 1][1] - data.cold[0][1]) * 10);
+ else document.getElementById("totcold").innerHTML = "0";
+ if (data.hot.length)
+ document.getElementById("tothot").innerHTML =
+ ((data.hot[data.hot.length - 1][1] - data.hot[0][1]) * 10);
+ else document.getElementById("tothot").innerHTML = "0";
+
tmin = data.range.lo;
tmax = data.range.hi;
//dbg.innerHTML = "from " + tmin + " to " + tmax
//dbg.innerHTML = url;
xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- // dbg.innerHTML = xmlhttp.responseText;
- var myData = JSON.parse(xmlhttp.responseText);
- gotdata(myData);
- }
+ if (xmlhttp.readyState == 4)
+ if (xmlhttp.status == 200) {
+ // dbg.innerHTML = xmlhttp.responseText;
+ var myData = JSON.parse(xmlhttp.responseText);
+ gotdata(myData);
+ } else {
+ errordiv.style.visibility = "visible";
+ errordiv.style.display = "block";
+ errordiv.innerHTML = xmlhttp.responseText;
+ }
}
xmlhttp.open("GET", url, true);
clearplot();
var qstr = window.location.search;
dbg = document.getElementById("debug");
+ errordiv = document.getElementById("errormsg");
canvas = document.getElementById("plot");
ctx = canvas.getContext("2d");
resize();
text-align: center;
font-size: 150%;
}
+div#totalvals {
+ width: 18em;
+ margin-left: auto;
+ margin-right: auto;
+ margin-bottom: 10px;
+ text-align: center;
+ font-size: 100%;
+}
div.current {
position: relative;
padding: 0.2em;
border: solid 1px black;
margin: 0.2em;
}
-div#cold {
+div.cold {
float: left;
background-color: #d0e0ff;
}
-div#hot {
+div.hot {
float: right;
background-color: #ffd0e0;
}
height: 320px;
/* border: solid 1px black; */
}
+div#errormsg {
+ visibility: hidden;
+ color: red;
+ text-align: center;
+}
div#queries {
margin-left: auto;
margin-right: auto;
</head><body>
<h1>WATER METERS</h1>
<div id="currentvals">
- Current Values
- <div class="current" id="cold">cold</div>
- <div class="current" id="hot">hot</div>
+ Current Readings (m<sup>3</sup>)
+ <div class="current cold" id="curcold">cold</div>
+ <div class="current hot" id="curhot">hot</div>
</div>
<br />
<canvas id="plot" width="640" height = "320"></canvas>
<br />
+<div id="errormsg"></div>
+<br />
+<div id="totalvals">
+ Total for the period (l)
+ <div class="current cold" id="totcold">cold</div>
+ <div class="current hot" id="tothot">hot</div>
+</div>
+<br />
<div id="queries">
<div class="query" id="prevweek"><div class="label">PREVIOUS WEEK</div></div>
<div class="query" id="beforeyesterday"><div class="label">DAY