def index(): cookId = SMSession.getCookId() if cookId == 0: cookId = CookDL.getCurrentCookId() SMSession.setCookId(cookId) currentCook = CookDL.getCook(cookId) return render_template('smomo/index.html', cook=currentCook, currentDT=datetime.now())
def RecordData(): cookId = CookDL.getCurrentCookId() # if DEBUG: # print("CookId: {0}".format(cookId)) if cookId > 0: # Number of samplet to take numOfSamples = 3 tempSamples = [] tempFinal = [] for i in range(numOfSamples): tempSamples.append(HWTempDL.getTemps()) tempFinal.append(0.0) for tempSample in tempSamples: tempSampleCount = 0 for temp in tempSample: tempFinal[tempSampleCount] = tempFinal[tempSampleCount] + temp tempSampleCount = tempSampleCount + 1 tempSampleCount = 0 for temp in tempFinal: tempFinal[tempSampleCount] = tempFinal[tempSampleCount] / numOfSamples tempSampleCount = tempSampleCount + 1 TempDL.logTemps(tempFinal, cookId) return jsonify('OK')
def ProcessSubscriptions(cookId, target, smokerTarget, temp1, temp2, smokerTemp): cook = CookDL.getCook(cookId) subs = SubscriptionDL.getSubscriptionsForCook(cookId) alertEmail = '' # deadband for smoker = 10% smokerHigh = smokerTarget * 1.1 smokerLow = smokerTarget * 0.9 if smokerTemp > smokerHigh: alertEmail = alertEmail + 'Smoker Temp is high. Target = {} Actual = {}'.format(smokerTarget, smokerTemp) if smokerTemp < smokerLow: alertEmail = alertEmail + 'Smoker Temp is low. Target = {} Actual = {}'.format(smokerTarget, smokerTemp) # Alert when meat has gone within 5 deg of target if temp1 > target - 5 || Temp2 > temp1 - 5: alertEmail = alertEmail + 'Target Temp within 5 degrees: Target = {} Temp1 = {} Temp2 = {}'.format(smokerTarget, temp1, temp2) # Alert when meat has hit target if temp1 >= target || temp2 >= target: alertEmail = alertEmail + 'Target Temp hit: Target = {} Temp1 = {} Temp2 = {}'.format(smokerTarget, temp1, temp2) # Alert when meat has hit + 5 deg of target if temp1 >= target + 5 || temp2 >= target + 5: alertEmail = alertEmail + 'Target Temp over by 5 degrees: Target = {} Temp1 = {} Temp2 = {}'.format(smokerTarget, temp1, temp2) for sub in subs: EmailDL.SendMessage(alertEmail)
def selectCook(): cookId = request.args.get('cookId') if cookId: SMSession.setCookId(cookId) return redirect(url_for('smomo.index')) else: cooks = CookDL.getCooks() return render_template('smomo/selectcook.html', cooks=cooks)
def SetCookData(): temps = json.loads(request.json) cookId = CookDL.getCurrentCookId() print(cookId) print(temps) if (cookId > 0): TempDL.logTemps(temps, cookId) return jsonify({"Status": "OK"})
def index(): cookId = SMSession.getCookId() if cookId == 0: cookId = CookDL.getCurrentCookId() SMSession.setCookId(cookId) currentCook = CookDL.getCook(cookId) latestTime = datetime(2019,1,1) latestTemp = [0, 0, 0] minTemp = [9999, 9999, 9999] maxTemp = [0, 0, 0] temps = [] if currentCook.CookId > 0: temps = TempDL.getTempsForCook(currentCook.CookId) for x in temps: if x.EventDate > latestTime: latestTime = x.EventDate latestTemp[0] = x.Temp1 latestTemp[1] = x.Temp2 latestTemp[2] = x.Temp3 """ if x.Temp < minTemp[x.SensorNum]: minTemp[x.SensorNum] = x.Temp if x.Temp > maxTemp[x.SensorNum]: maxTemp[x.SensorNum] = x.Temp """ return render_template('index.html', cook = currentCook, latestTime = latestTime, latestTemp = latestTemp, minTemp = minTemp, maxTemp = maxTemp, temps = temps, values=temps, currentDT=datetime.now())
def editcook(): currentCookId = CookDL.getCurrentCookId() if request.method == "POST": if currentCookId == 0: title = request.form["title"] smokerTarget = request.form["smokerTarget"] target = request.form["target"] CookDL.startCook(title, smokerTarget, target) cookId = CookDL.getCurrentCookId() SMSession.setCookId(cookId) else: CookDL.endCurrentCook() return redirect(url_for('smomo.index')) else: cook = CookDL.getCook(currentCookId) subs = SubscriptionDL.getSubscriptionsForCook(currentCookId) title = cook.Title return render_template('smomo/editcook.html', cook=cook, subs=subs)
def startcook(): currentCookId = CookDL.getCurrentCookId() if request.method == "POST": if currentCookId == 0: title = request.form["title"] smokerTarget = request.form["smokerTarget"] target = request.form["target"] CookDL.startCook(title, smokerTarget, target) cookId = CookDL.getCurrentCookId() SMSession.setCookId(cookId) else: CookDL.endCurrentCook() return redirect(url_for('index')) else: if currentCookId == 0: return render_template('startcook.html') else: cook = CookDL.getCook(currentCookId) title = cook.Title return render_template('endcook.html', title=title)
def GetCookData(): date = request.args.get('lastUpdate') cookId = request.args.get('cookId') currentCook = CookDL.getCook(cookId) if currentCook.CookId > 0: allData = {} endTime = datetime.now() if currentCook.End: endTime = currentCook.End allData['duration'] = currentCook.Duration allData['cookStart']= currentCook.Start.strftime(dateFormatString) allData['currentDT']=datetime.now() allData['smokerTarget'] = GenerateTargetData(currentCook.Start, endTime, currentCook.SmokerTarget) allData['target'] = GenerateTargetData(currentCook.Start, endTime, currentCook.Target) currentDate = endTime allData['lastUpdate'] = currentDate.strftime(dateFormatString) temps = [] if date: temps = TempDL.getTempsForCook(currentCook.CookId, date) else: temps = TempDL.getTempsForCook(currentCook.CookId) temps1 = [] temps2 = [] temps3 = [] # get current temps from the first item in the list if len(temps) > 0: currentTemp = temps[-1] # last in the list allData['Sensor1Current'] = '{0:.2f}'.format(currentTemp.Temp1) allData['Sensor2Current'] = '{0:.2f}'.format(currentTemp.Temp2) allData['Sensor3Current'] = '{0:.2f}'.format(currentTemp.Temp3) for x in temps: formattedDate = x.EventDate.strftime(dateFormatString) if x.Temp1 > 0: temp1 = {} temp1['x'] = formattedDate temp1['y'] = x.Temp1 temps1.append(temp1) if x.Temp2 > 0: temp2 = {} temp2['x'] = formattedDate temp2['y'] = x.Temp2 temps2.append(temp2) if x.Temp3 > 0: temp3 = {} temp3['x'] = formattedDate temp3['y'] = x.Temp3 temps3.append(temp3) allData['Temp1'] = temps1 allData['Temp2'] = temps2 allData['Temp3'] = temps3 return jsonify(allData) return jsonify('')
def deleteCook(): cookId = request.args.get('cookId') CookDL.delete(cookId) return redirect(url_for('selectCook'))