Merge branch 'develop' into 'master'

Add filtering to coffee data

See merge request !43
This commit is contained in:
Jan Tuomi
2017-09-19 21:05:07 +03:00
3 changed files with 26 additions and 8 deletions
+20 -5
View File
@@ -8,9 +8,10 @@ MQTT_HOST = "mqtt.sik.party"
TOPIC_TEMP = "sik/kiltahuone/kahvivaaka/temperature"
TOPIC_WEIGHT = "sik/kiltahuone/kahvivaaka/weight"
BREWING_DIFFERENTIAL = 60
BREWING_DIFFERENTIAL_MIN = 60
# setting down the pan creates at least 800 g of weight
BREWING_DIFFERENTIAL_ERROR_MAX = 800
BREWING_DIFFERENTIAL_MAX = 180
WEIGHT_DEQUE_LENGTH = 20
weight_deque = deque(maxlen=WEIGHT_DEQUE_LENGTH)
latest = {
@@ -18,6 +19,17 @@ latest = {
}
def calc_averaged_weight():
if len(weight_deque) > 2:
half = []
for i in range(0, int(len(weight_deque) / 2)):
half.append(weight_deque[i])
return sum(half) / len(half)
else:
return 0
def on_connect(client, userdata, flags, rc):
logging.info('Subscribing to all topics on mqtt.sik.party.')
client.subscribe("#")
@@ -28,8 +40,10 @@ def on_message(client, userdata, msg):
latest['temp'] = float(msg.payload.decode('utf-8'))
elif msg.topic == TOPIC_WEIGHT:
weight = float(msg.payload.decode('utf-8'))
latest['weight'] = weight
weight_deque.appendleft(weight)
# avoid showing erroneous data from an empty scale
if weight > 50: # g
weight_deque.appendleft(weight)
def on_disconnect(client, userdata, rc):
@@ -49,13 +63,14 @@ def get_latest():
if len(weight_deque) < WEIGHT_DEQUE_LENGTH:
brewing = False
else:
if BREWING_DIFFERENTIAL < diff < BREWING_DIFFERENTIAL_ERROR_MAX:
if BREWING_DIFFERENTIAL_MIN < diff < BREWING_DIFFERENTIAL_MAX:
brewing = True
latest['last_brew'] = datetime.datetime.now()
else:
brewing = False
latest['brewing'] = brewing
latest['weight'] = calc_averaged_weight()
return latest
+4 -1
View File
@@ -233,7 +233,10 @@ function setData(cups, temp, opa, timeFromUpdate, timeFromBrew, brewing){
formatBrewTime();
if($("#text").html() == "+" && !brewing)
$("body").addClass("coffeeready");
len = cups.toString().length;
cups = Number(cups).toFixed(1);
var cupsString = cups.toString();
len = cupsString.length;
$("#text").html(cups);
}
+2 -2
View File
@@ -18,12 +18,12 @@ def get_cups_from_weight(weight):
cups = 10 * (weight - EMPTY) / (FULL - EMPTY)
cups = round(cups, 1)
if cups < 0:
if cups < 0.5:
cups = 0
if cups > 10:
cups = 10
logging.debug("Coffee cups: {}, weight: {}".format(cups, weight))
# logging.debug("Coffee cups: {}, weight: {}".format(cups, weight))
return cups