Random coffee scale fixes

This commit is contained in:
Jan Tuomi
2017-09-18 23:58:45 +03:00
parent 5da4b52bde
commit a813b502fc
2 changed files with 15 additions and 13 deletions
+14 -13
View File
@@ -9,7 +9,7 @@
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
body {
background-color: white;
@@ -140,7 +140,6 @@ var brewtext = "";
$(document).ready(function(){
$('#text').bind("DOMSubtreeModified", resize);
fetchdata();
updateTime();
setInterval(updateTime,1000);
formatBrewTime();
@@ -151,27 +150,30 @@ $(window).resize(resize);
var defaultBackoffTime = 1000;
var modified = 0;
function fetchdata(hxr, status){
function fetchdata(data, status){
var backoffTime = defaultBackoffTime;
modified = 1;
if(typeof status !== 'undefined'){
if(status == "success"){
if (typeof status !== 'undefined'){
if (status == "success"){
backoffTime = defaultBackoffTime;
parseData(hxr.responseText);
parseData(data);
}
else if(status == "error"){
else if (status == "error"){
backoffTime *= 2;
modified = 0
setTimeout(fetchdata, backoffTime);
handleError();
return;
}
}
setTimeout(function() {
$.ajax({cache: false, ifModified: modified, url: '/coffee/cups', complete: fetchdata, timeout:120000});
}, 2000);
}
setInterval(function() {
$.getJSON("/coffee/cups", fetchdata);
}, 2000);
function formatBrewTime(){
if(!brewtext && lastBrew instanceof Date){
var now = new Date();
@@ -189,8 +191,7 @@ function handleError(){
setData("?",0,0,Number.MAX_VALUE,Number.MAX_VALUE);
}
function parseData(string) {
var data = JSON.parse(string);
function parseData(data) {
if (data) {
var date = new Date(data.date);
lastBrew = new Date(data.last_brew);
+1
View File
@@ -19,6 +19,7 @@ def get_cups_from_weight(weight):
if cups > 10:
cups = 10
print("cups: ", cups, "weight: ", weight)
return cups