1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753 |
- #主業務邏輯中的視圖和路由的定義
- import os
- import datetime
- from flask import render_template, request, session
- #導入藍圖程序,用於構建路由
- from werkzeug.utils import redirect
- from . import main
- from manage import mqtt
- #導入db,用於操作數據庫
- from manage import db
- #導入實體類,用於操作數據庫
- from ..models import *
- import json
- from datetime import datetime as dt
- from sqlalchemy import text
- #主頁的訪問路徑
- @main.route('/')
- def main_index():
- #獲取登入信息
- if 'id' in session and 'uname' in session:
- username = session['uname']
- try:
- liquid = LiquidTank.query.order_by(text('datetime desc')).first()
- except Exception:
- pass
- try:
- tank1_duration1 = liquid.tk1_duration1
- except Exception:
- pass
- try:
- tank1_duration2 = liquid.tk1_duration2
- except Exception:
- pass
- try:
- tank1_duration3 = liquid.tk1_duration3
- except Exception:
- pass
- try:
- tank2_duration1 = liquid.tk2_duration1
- except Exception:
- pass
- try:
- tank2_duration2 = liquid.tk2_duration2
- except Exception:
- pass
- try:
- tank2_duration3 = liquid.tk2_duration3
- except Exception:
- pass
- try:
- tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1]
- tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1]
- tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1]
- tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1]
- tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1]
- tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1]
- tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1]
- except Exception:
- pass
- return render_template('set_liquid.html',params=locals())
- else:
- return render_template('sign_in.html')
- #登入頁面的訪問路徑
- @main.route('/login', methods=['GET','POST'])
- def login_views():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session:
- return redirect('/')
- else:
- return render_template('sign_in.html')
- else:
- #接收前端傳過來的資料
- username = request.form['username']
- password = request.form['password']
- #使用接收的用戶和密碼到資料庫中查詢
- user = User.query.filter_by(username=username, password=password).first()
- #如果用戶存在,將信息保存置session並重定向回首頁,否則重定向回登入頁
- if user:
- resp = redirect('/')
- #判斷是否有記住密碼
- if 'rem' in request.form:
- userID = str(user.userID)
- max_age = 60*60*24*365
- resp.set_cookie("username", username, max_age=max_age)
- resp.set_cookie("userID", userID, max_age=max_age)
- session['uname'] = user.username
- session['id'] = user.userID
- return resp
- else:
- errMsg = "Wrong login or password"
- return render_template('sign_in.html',errMsg=errMsg)
- #登入重設密碼的頁面
- @main.route('/reset_password', methods=['POST', 'GET'])
- def reset_password_views():
- if request.method == 'GET':
- if 'mail' in session:
- del session['mail']
- return render_template('reset_pwd1.html')
- else:
- #如果有id在session裡,代表從reset_pwd2過來的
- if "mail" in session:
- new_pwd = request.form['new_pwd']
- confirm_pwd = request.form['confirm_pwd']
- #判斷密碼是否一致
- if new_pwd == confirm_pwd:
- mail = session['mail']
- user = User.query.filter_by(mail=mail).first()
- user.password = new_pwd
- db.session.add(user)
- del session['mail']
- #修改完後回登入頁
- return redirect('/login')
- else:
- errMsg = "Passwords does not match"
- return render_template('reset_pwd2.html', errMsg=errMsg)
- email = request.form['email']
- user = User.query.filter_by(mail=email).first()
- if user:
- session['mail'] = user.mail
- return render_template('reset_pwd2.html')
- else:
- errMsg = "Wrong email.Please try again"
- return render_template('reset_pwd1.html', errMsg=errMsg)
- #註冊頁面的訪問路徑
- @main.route('/register',methods=['POST',"GET"])
- def register_views():
- if request.method == 'GET':
- return render_template('registration.html')
- else:
- #獲取文本框的值並賦值給user實體對象
- user = User()
- user.firstname = request.form['firstname']
- user.lastname = request.form['lastname']
- user.mail = request.form['email']
- user.phone = request.form['phone']
- user.username = request.form['username']
- user.password = request.form['password']
- user.status = 1
- #將數據保存進資料庫 - 註冊
- db.session.add(user)
- #手動提交,目的是為了獲取提交後的user的id
- db.session.commit()
- #當user成功插入進資料庫之後,程序會自動將所有信息取出來在賦值給user
- #完成登入的操作
- user = User.query.filter_by(username=user.username).first()
- session['id'] = user.userID
- session['uname'] = user.username
- return redirect('/')
- #驗證email訪問路徑
- @main.route('/check_email')
- def check_email_views():
- email = request.args['email']
- user = User.query.filter_by(mail=email).first()
- if user:
- result = {"errMsg":" "}
- else:
- result = {"pass":" "}
- return json.dumps(result)
- #驗證username訪問路徑
- @main.route('/check_username')
- def check_username_views():
- username = request.args['username']
- user = User.query.filter_by(username=username).first()
- if user:
- result = {"errMsg":" "}
- else:
- result = {"pass":" "}
- return json.dumps(result)
- #liquid的訪問路徑
- @main.route('/setting_liquid', methods=['POST','GET'])
- def setting_liquid_views():
- username = session['uname']
- if request.method == 'GET':
- liquid = LiquidTank.query.order_by('datetime desc').limit(1)
- return render_template('set_liquid.html', params=locals())
- else:
- liquid = LiquidTank()
- liquid.datetime = dt.now()
- tank1_num = 1
- tank1_from_num = 1
- tank1_to_num = 1
- tank2_num = 1
- tank2_from_num = 1
- tank2_to_num = 1
- for i in request.form:
- if i[:14] == 'tank1_duration':
- if tank1_num == 1:
- liquid.tk1_duration1 = request.form[i]
- tank1_num += 1
- elif tank1_num == 2:
- liquid.tk1_duration2 = request.form[i]
- tank1_num += 1
- elif tank1_num == 3:
- liquid.tk1_duration3 = request.form[i]
- else:
- if i[:13] == 'tank1_from_hr':
- tk1_from_hr = request.form[i]
- elif i[:14] == 'tank1_from_min':
- tk1_from_min = request.form[i]
- if tank1_from_num == 1:
- liquid.tk1_start1 = tk1_from_hr + ":" + tk1_from_min
- tank1_from_num += 1
- elif tank1_from_num == 2:
- liquid.tk1_start2 = tk1_from_hr + ":" + tk1_from_min
- tank1_from_num += 1
- elif tank1_from_num == 3:
- liquid.tk1_start3 = tk1_from_hr + ":" + tk1_from_min
- elif i[:11] == 'tank1_to_hr':
- tk1_to_hr = request.form[i]
- elif i[:12] == 'tank1_to_min':
- tk1_to_min = request.form[i]
- if tank1_to_num ==1 :
- liquid.tk1_end1 = tk1_to_hr + ":" + tk1_to_min
- tank1_to_num += 1
- elif tank1_to_num == 2:
- liquid.tk1_end2 = tk1_to_hr + ":" + tk1_to_min
- tank1_to_num += 1
- elif tank1_to_num == 3:
- liquid.tk1_end3 = tk1_to_hr + ":" + tk1_to_min
- if i[:14] == 'tank2_duration':
- if tank2_num == 1:
- liquid.tk2_duration1 = request.form[i]
- tank2_num += 1
- elif tank2_num == 2:
- liquid.tk2_duration2 = request.form[i]
- tank2_num += 1
- elif tank2_num == 3:
- liquid.tk2_duration3 = request.form[i]
- else:
- if i[:13] == 'tank2_from_hr':
- tk2_from_hr = request.form[i]
- elif i[:14] == 'tank2_from_min':
- tk2_from_min = request.form[i]
- if tank2_from_num == 1:
- liquid.tk2_start1 = tk2_from_hr + ":" + tk2_from_min
- tank2_from_num += 1
- elif tank2_from_num == 2:
- liquid.tk2_start2 = tk2_from_hr + ":" + tk2_from_min
- tank2_from_num += 1
- elif tank2_from_num == 3:
- liquid.tk2_start3 = tk2_from_hr + ":" + tk2_from_min
- elif i[:11] == 'tank2_to_hr':
- tk2_to_hr = request.form[i]
- elif i[:12] == 'tank2_to_min':
- tk2_to_min = request.form[i]
- if tank2_to_num == 1:
- liquid.tk2_end1 = tk2_to_hr + ":" + tk2_to_min
- tank2_to_num += 1
- elif tank2_to_num == 2:
- liquid.tk2_end2 = tk2_to_hr + ":" + tk2_to_min
- tank2_to_num += 1
- elif tank2_to_num == 3:
- liquid.tk2_end3 = tk2_to_hr + ":" + tk2_to_min
- db.session.add(liquid)
- db.session.commit()
- # return render_template('set_root.html', params=locals())
- return redirect('/setting_root')
- #root systems的訪問路徑
- @main.route('/setting_root', methods=['POST','GET'])
- def setting_root_views():
- username = session['uname']
- if request.method == 'GET':
- root = RootSystem.query.order_by(text('datetime desc')).first()
- try:
- tem1 = root.tem_tem1
- except Exception:
- pass
- try:
- tem2 = root.tem_tem2
- except Exception:
- pass
- try:
- tem3 = root.tem_tem3
- except Exception:
- pass
- try:
- tem_from_hr1, tem_from_min1 = root.tem_start1.split(':')[0], root.tem_start1.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr1, tem_to_min1 = root.tem_end1.split(':')[0], root.tem_end1.split(':')[1]
- except Exception:
- pass
- try:
- tem_from_hr2, tem_from_min2 = root.tem_start2.split(':')[0], root.tem_start2.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr2, tem_to_min2 = root.tem_end2.split(':')[0], root.tem_end2.split(':')[1]
- except Exception:
- pass
- try:
- tem_from_hr3, tem_from_min3 = root.tem_start3.split(':')[0], root.tem_start3.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr3, tem_to_min3 = root.tem_end3.split(':')[0], root.tem_end3.split(':')[1]
- except Exception:
- pass
- try:
- lamp_from_hr1, lamp_from_min1 = root.l_start1.split(':')[0], root.l_start1.split(':')[1]
- except Exception:
- pass
- try:
- lamp_to_hr1, lamp_to_min1 = root.l_end1.split(':')[0], root.l_end1.split(':')[1]
- except Exception:
- pass
- try:
- lamp_from_hr2, lamp_from_min2 = root.l_start2.split(':')[0], root.l_start2.split(':')[1]
- except Exception:
- pass
- try:
- lamp_to_hr2, lamp_to_min2 = root.l_end2.split(':')[0], root.l_end2.split(':')[1]
- except Exception:
- pass
- try:
- lamp_from_hr3, lamp_from_min3 = root.l_start3.split(':')[0], root.l_start3.split(':')[1]
- except Exception:
- pass
- try:
- lamp_to_hr3, lamp_to_min3 = root.l_end3.split(':')[0], root.l_end3.split(':')[1]
- except Exception:
- pass
- try:
- r = str(root.l_r)
- g = str(root.l_g)
- b = str(root.l_b)
- color = '(' + r + ',' + g + ',' + b + ')'
- except Exception:
- pass
- try:
- if root.l_bright_auto == 0:
- #+1是為了讓前端不要判定為假
- bright_on = root.l_bright_auto + 1
- bright_vol = root.l_bright_vol
- if root.fan_status == 0:
- fan_on = root.fan_status + 1
- periodicity = root.fan_periodicity
- duration = root.fan_duration
- speed = root.fan_speed
- humidity = root.humidity
- except Exception:
- pass
- return render_template('set_root.html', params=locals())
- else:
- root = RootSystem()
- root.datetime = dt.now()
- tem_num = 1
- tem_from_num = 1
- tem_to_num = 1
- lamp_from_num = 1
- lamp_to_num = 1
- for i in request.form:
- if i[:3] == 'tem' and len(i) <= 7:
- if tem_num == 1:
- root.tem_tem1 = request.form[i]
- tem_num += 1
- elif tem_num == 2:
- root.tem_tem2 = request.form[i]
- tem_num += 1
- elif tem_num == 3:
- root.tem_tem3 = request.form[i]
- else:
- if i[:11] == 'tem_from_hr':
- tem_from_hr = request.form[i]
- elif i[:12] == 'tem_from_min':
- tem_from_min = request.form[i]
- if tem_from_num == 1:
- root.tem_start1 = tem_from_hr + ":" + tem_from_min
- tem_from_num += 1
- elif tem_from_num == 2:
- root.tem_start2 = tem_from_hr + ":" + tem_from_min
- tem_from_num += 1
- elif tem_from_num == 3:
- root.tem_start3 = tem_from_hr + ":" + tem_from_min
- elif i[:9] == 'tem_to_hr':
- tem_to_hr = request.form[i]
- elif i[:10] == 'tem_to_min':
- tem_to_min = request.form[i]
- if tem_to_num ==1 :
- root.tem_end1 = tem_to_hr + ":" + tem_to_min
- tem_to_num += 1
- elif tem_to_num == 2:
- root.tem_end2 = tem_to_hr + ":" + tem_to_min
- tem_to_num += 1
- elif tem_to_num == 3:
- root.tem_end3 = tem_to_hr + ":" + tem_to_min
- if i[:12] == 'lamp_from_hr':
- lamp_from_hr = request.form[i]
- elif i[:13] == 'lamp_from_min':
- lamp_from_min = request.form[i]
- if lamp_from_num == 1:
- root.l_start1 = lamp_from_hr + ":" + lamp_from_min
- lamp_from_num += 1
- elif lamp_from_num == 2:
- root.l_start2 = lamp_from_hr + ":" + lamp_from_min
- lamp_from_num += 1
- elif lamp_from_num == 3:
- root.l_start3 = lamp_from_hr + ":" + lamp_from_min
- if i[:10] == 'lamp_to_hr':
- lamp_to_hr = request.form[i]
- elif i[:11] == 'lamp_to_min':
- lamp_to_min = request.form[i]
- if lamp_to_num ==1 :
- root.l_end1 = lamp_to_hr + ":" + lamp_to_min
- lamp_to_num += 1
- elif lamp_to_num == 2:
- root.l_end2 = lamp_to_hr + ":" + lamp_to_min
- lamp_to_num += 1
- elif lamp_to_num == 3:
- root.l_end3 = lamp_to_hr + ":" + lamp_to_min
- if i == 'color':
- try:
- color = request.form['color']
- root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- if 'bright-on' in request.form:
- root.l_bright_auto = 1
- else:
- root.l_bright_auto = 0
- root.l_bright_vol = request.form['bright-vol']
- if 'fan-on' in request.form:
- root.fan_status = 1
- else:
- root.fan_status = 0
- root.fan_periodicity = request.form['periodicity']
- root.fan_duration = request.form['duration']
- root.fan_speed = request.form['speed']
- root.humidity = request.form['humidity']
- db.session.add(root)
- db.session.commit()
- # return render_template('set_stem.html', params=locals())
- return redirect('/setting_stem')
- #stem systems的訪問路徑
- @main.route('/setting_stem', methods=['POST','GET'])
- def setting_stem_views():
- username = session['uname']
- if request.method == 'GET':
- stem = StemSystem.query.order_by(text('datetime desc')).first()
- try:
- tem1 = stem.tem_tem1
- except Exception:
- pass
- try:
- tem2 = stem.tem_tem2
- except Exception:
- pass
- try:
- tem3 = stem.tem_tem3
- except Exception:
- pass
- try:
- tem_from_hr1, tem_from_min1 = stem.tem_start1.split(':')[0], stem.tem_start1.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr1, tem_to_min1 = stem.tem_end1.split(':')[0], stem.tem_end1.split(':')[1]
- except Exception:
- pass
- try:
- tem_from_hr2, tem_from_min2 = stem.tem_start2.split(':')[0], stem.tem_start2.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr2, tem_to_min2 = stem.tem_end2.split(':')[0], stem.tem_end2.split(':')[1]
- except Exception:
- pass
- try:
- tem_from_hr3, tem_from_min3 = stem.tem_start3.split(':')[0], stem.tem_start3.split(':')[1]
- except Exception:
- pass
- try:
- tem_to_hr3, tem_to_min3 = stem.tem_end3.split(':')[0], stem.tem_end3.split(':')[1]
- except Exception:
- pass
- try:
- led_from_hr1, led_from_min1 = stem.l_start1.split(':')[0], stem.l_start1.split(':')[1]
- except Exception:
- pass
- try:
- led_to_hr1, led_to_min1 = stem.l_end1.split(':')[0], stem.l_end1.split(':')[1]
- except Exception:
- pass
- try:
- led_from_hr2, led_from_min2 = stem.l_start2.split(':')[0], stem.l_start2.split(':')[1]
- except Exception:
- pass
- try:
- led_to_hr2, led_to_min2 = stem.l_end2.split(':')[0], stem.l_end2.split(':')[1]
- except Exception:
- pass
- try:
- led_from_hr3, led_from_min3 = stem.l_start3.split(':')[0], stem.l_start3.split(':')[1]
- except Exception:
- pass
- try:
- led_to_hr3, led_to_min3 = stem.l_end3.split(':')[0], stem.l_end3.split(':')[1]
- except Exception:
- pass
- try:
- r = str(stem.l_r)
- g = str(stem.l_g)
- b = str(stem.l_b)
- color = '(' + r + ',' + g + ',' + b + ')'
- except Exception:
- pass
- try:
- if stem.l_bright_auto == 0:
- #+1是為了讓前端不要判定為假
- bright_on = stem.l_bright_auto + 1
- bright_vol = stem.l_bright_vol
- except Exception:
- pass
- try:
- if stem.c_status == 0:
- # +1是為了讓前端不要判定為假
- camera_on = stem.c_status + 1
- except Exception:
- pass
- try:
- duration = stem.c_duration
- except Exception:
- pass
- try:
- tem_near_stem1 = stem.t_n_s_tem1
- except Exception:
- pass
- try:
- tem_near_stem2 = stem.t_n_s_tem2
- except Exception:
- pass
- try:
- tem_near_stem3 = stem.t_n_s_tem3
- except Exception:
- pass
- try:
- t_n_s_from_hr1, t_n_s_from_min1 = stem.t_n_s_start1.split(':')[0], stem.t_n_s_start1.split(':')[1]
- except Exception:
- pass
- try:
- t_n_s_to_hr1, t_n_s_to_min1 = stem.t_n_s_end1.split(':')[0], stem.t_n_s_end1.split(':')[1]
- except Exception:
- pass
- try:
- t_n_s_from_hr2, t_n_s_from_min2 = stem.t_n_s_start2.split(':')[0], stem.t_n_s_start2.split(':')[1]
- except Exception:
- pass
- try:
- t_n_s_to_hr2, t_n_s_to_min2 = stem.t_n_s_end2.split(':')[0], stem.t_n_s_end2.split(':')[1]
- except Exception:
- pass
- try:
- t_n_s_from_hr3, t_n_s_from_min3 = stem.t_n_s_start3.split(':')[0], stem.t_n_s_start3.split(':')[1]
- except Exception:
- pass
- try:
- t_n_s_to_hr3, t_n_s_to_min3 = stem.t_n_s_end3.split(':')[0], stem.t_n_s_end3.split(':')[1]
- except Exception:
- pass
- try:
- music1 = stem.m_playlist1
- except Exception:
- pass
- try:
- music2 = stem.m_playlist2
- except Exception:
- pass
- try:
- music3 = stem.m_playlist3
- except Exception:
- pass
- try:
- music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1]
- except Exception:
- pass
- try:
- u_s_from_hr1, u_s_from_min1 = stem.u_s_start1.split(':')[0], stem.u_s_start1.split(':')[1]
- except Exception:
- pass
- try:
- u_s_to_hr1, u_s_to_min1 = stem.u_s_end1.split(':')[0], stem.u_s_end1.split(':')[1]
- except Exception:
- pass
- try:
- u_s_from_hr2, u_s_from_min2 = stem.u_s_start2.split(':')[0], stem.u_s_start2.split(':')[1]
- except Exception:
- pass
- try:
- u_s_to_hr2, u_s_to_min2 = stem.u_s_end2.split(':')[0], stem.u_s_end2.split(':')[1]
- except Exception:
- pass
- try:
- u_s_from_hr3, u_s_from_min3 = stem.u_s_start3.split(':')[0], stem.u_s_start3.split(':')[1]
- except Exception:
- pass
- try:
- u_s_to_hr3, u_s_to_min3 = stem.u_s_end3.split(':')[0], stem.u_s_end3.split(':')[1]
- except Exception:
- pass
- try:
- if stem.u_s_status == 0:
- # +1是為了讓前端不要判定為假
- ultra_sonic_on = stem.u_s_status + 1
- except Exception:
- pass
- try:
- volume = stem.u_s_vol
- except Exception:
- pass
- try:
- vibration1 = stem.v_vol1
- except Exception:
- pass
- try:
- vibration2 = stem.v_vol2
- except Exception:
- pass
- try:
- vibration3 = stem.v_vol3
- except Exception:
- pass
- try:
- v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1]
- except Exception:
- pass
- try:
- wind_flow1 = stem.w_vol1
- except Exception:
- pass
- try:
- wind_flow2 = stem.w_vol2
- except Exception:
- pass
- try:
- wind_flow3 = stem.w_vol3
- except Exception:
- pass
- try:
- w_from_hr1, w_from_min1 = stem.w_start1.split(':')[0], stem.w_start1.split(':')[1]
- except Exception:
- pass
- try:
- w_to_hr1, w_to_min1 = stem.w_end1.split(':')[0], stem.w_end1.split(':')[1]
- except Exception:
- pass
- try:
- w_from_hr2, w_from_min2 = stem.w_start2.split(':')[0], stem.w_start2.split(':')[1]
- except Exception:
- pass
- try:
- w_to_hr2, w_to_min2 = stem.w_end2.split(':')[0], stem.w_end2.split(':')[1]
- except Exception:
- pass
- try:
- w_from_hr3, w_from_min3 = stem.w_start3.split(':')[0], stem.w_start3.split(':')[1]
- except Exception:
- pass
- try:
- w_to_hr3, w_to_min3 = stem.w_end3.split(':')[0], stem.w_end3.split(':')[1]
- except Exception:
- pass
- try:
- c_duration = stem.c_duration
- except Exception:
- pass
- try:
- rh = stem.rh
- except Exception:
- pass
- return render_template('set_stem.html', params=locals())
- else:
- stem = StemSystem()
- stem.datetime = dt.now()
- tem_num = 1
- tem_from_num = 1
- tem_to_num = 1
- led_from_num = 1
- led_to_num = 1
- t_n_s_num = 1
- t_n_s_from_num = 1
- t_n_s_to_num = 1
- music_num = 1
- music_from_num = 1
- music_to_num = 1
- u_s_from_num = 1
- u_s_to_num = 1
- v_num = 1
- v_from_num = 1
- v_to_num = 1
- w_num = 1
- w_from_num = 1
- w_to_num = 1
- for i in request.form:
- if i[:3] == 'tem' and len(i) <= 7:
- if tem_num == 1:
- stem.tem_tem1 = request.form[i]
- tem_num += 1
- elif tem_num == 2:
- stem.tem_tem2 = request.form[i]
- tem_num += 1
- elif tem_num == 3:
- stem.tem_tem3 = request.form[i]
- else:
- if i[:11] == 'tem_from_hr':
- tem_from_hr = request.form[i]
- elif i[:12] == 'tem_from_min':
- tem_from_min = request.form[i]
- if tem_from_num == 1:
- stem.tem_start1 = tem_from_hr + ":" + tem_from_min
- tem_from_num += 1
- elif tem_from_num == 2:
- stem.tem_start2 = tem_from_hr + ":" + tem_from_min
- tem_from_num += 1
- elif tem_from_num == 3:
- stem.tem_start3 = tem_from_hr + ":" + tem_from_min
- elif i[:9] == 'tem_to_hr':
- tem_to_hr = request.form[i]
- elif i[:10] == 'tem_to_min':
- tem_to_min = request.form[i]
- if tem_to_num ==1 :
- stem.tem_end1 = tem_to_hr + ":" + tem_to_min
- tem_to_num += 1
- elif tem_to_num == 2:
- stem.tem_end2 = tem_to_hr + ":" + tem_to_min
- tem_to_num += 1
- elif tem_to_num == 3:
- stem.tem_end3 = tem_to_hr + ":" + tem_to_min
- if i[:11] == 'led_from_hr':
- led_from_hr = request.form[i]
- elif i[:12] == 'led_from_min':
- led_from_min = request.form[i]
- if led_from_num == 1:
- stem.l_start1 = led_from_hr + ":" + led_from_min
- led_from_num += 1
- elif led_from_num == 2:
- stem.l_start2 = led_from_hr + ":" + led_from_min
- led_from_num += 1
- elif led_from_num == 3:
- stem.l_start3 = led_from_hr + ":" + led_from_min
- if i[:9] == 'led_to_hr':
- led_to_hr = request.form[i]
- elif i[:10] == 'led_to_min':
- led_to_min = request.form[i]
- if led_to_num ==1 :
- stem.l_end1 = led_to_hr + ":" + led_to_min
- led_to_num += 1
- elif led_to_num == 2:
- stem.l_end2 = led_to_hr + ":" + led_to_min
- led_to_num += 1
- elif led_to_num == 3:
- stem.l_end3 = led_to_hr + ":" + led_to_min
- if i == 'color':
- try:
- color = request.form['color']
- stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- if i[:13] == 'tem-near-stem':
- if t_n_s_num == 1:
- stem.t_n_s_tem1 = request.form[i]
- print(request.form[i])
- t_n_s_num += 1
- elif t_n_s_num == 2:
- stem.t_n_s_tem2 = request.form[i]
- t_n_s_num += 1
- elif t_n_s_num == 3:
- stem.t_n_s_tem3 = request.form[i]
- else:
- if i[:11] == 'tns_from_hr':
- t_n_s_from_hr = request.form[i]
- elif i[:12] == 'tns_from_min':
- t_n_s_from_min = request.form[i]
- if t_n_s_from_num == 1:
- stem.t_n_s_start1 = t_n_s_from_hr + ":" + t_n_s_from_min
- t_n_s_from_num += 1
- elif t_n_s_from_num == 2:
- stem.t_n_s_start2 = t_n_s_from_hr + ":" + t_n_s_from_min
- t_n_s_from_num += 1
- elif t_n_s_from_num == 3:
- stem.t_n_s_start3 = t_n_s_from_hr + ":" + t_n_s_from_min
- elif i[:9] == 'tns_to_hr':
- t_n_s_to_hr = request.form[i]
- elif i[:10] == 'tns_to_min':
- t_n_s_to_min = request.form[i]
- if t_n_s_to_num == 1:
- stem.t_n_s_end1 = t_n_s_to_hr + ":" + t_n_s_to_min
- t_n_s_to_num += 1
- elif t_n_s_to_num == 2:
- stem.t_n_s_end2 = t_n_s_to_hr + ":" + t_n_s_to_min
- t_n_s_to_num += 1
- elif t_n_s_to_num == 3:
- stem.t_n_s_end3 = t_n_s_to_hr + ":" + t_n_s_to_min
- if i[:5] == 'music' and len(i) <=11:
- if music_num == 1:
- stem.m_playlist1 = request.form[i]
- music_num += 1
- elif music_num == 2:
- stem.m_playlist2 = request.form[i]
- music_num += 1
- elif music_num == 3:
- stem.m_playlist3 = request.form[i]
- else:
- if i[:13] == 'music_from_hr':
- music_from_hr = request.form[i]
- elif i[:14] == 'music_from_min':
- music_from_min = request.form[i]
- if music_from_num == 1:
- stem.m_start1 = music_from_hr + ":" + music_from_min
- music_from_num += 1
- elif music_from_num == 2:
- stem.m_start2 = music_from_hr + ":" + music_from_min
- music_from_num += 1
- elif music_from_num == 3:
- stem.m_start3 = music_from_hr + ":" + music_from_min
- elif i[:11] == 'music_to_hr':
- music_to_hr = request.form[i]
- elif i[:12] == 'music_to_min':
- music_to_min = request.form[i]
- if music_to_num == 1:
- stem.m_end1 = music_to_hr + ":" + music_to_min
- music_to_num += 1
- elif music_to_num == 2:
- stem.m_end2 = music_to_hr + ":" + music_to_min
- music_to_num += 1
- elif music_to_num == 3:
- stem.m_end3 = music_to_hr + ":" + music_to_min
- if i[:9] == 'vibration':
- if v_num == 1:
- stem.v_vol1 = request.form[i]
- v_num += 1
- elif v_num == 2:
- stem.v_vol2 = request.form[i]
- v_num += 1
- elif v_num == 3:
- stem.v_vol3 = request.form[i]
- else:
- if i[:9] == 'v_from_hr':
- v_from_hr = request.form[i]
- elif i[:10] == 'v_from_min':
- v_from_min = request.form[i]
- if v_from_num == 1:
- stem.v_start1 = v_from_hr + ":" + v_from_min
- v_from_num += 1
- elif v_from_num == 2:
- stem.v_start2 = v_from_hr + ":" + v_from_min
- v_from_num += 1
- elif v_from_num == 3:
- stem.v_start3 = v_from_hr + ":" + v_from_min
- elif i[:7] == 'v_to_hr':
- v_to_hr = request.form[i]
- elif i[:8] == 'v_to_min':
- v_to_min = request.form[i]
- if v_to_num == 1:
- stem.v_end1 = v_to_hr + ":" + v_to_min
- v_to_num += 1
- elif v_to_num == 2:
- stem.v_end2 = v_to_hr + ":" + v_to_min
- v_to_num += 1
- elif v_to_num == 3:
- stem.v_end3 = v_to_hr + ":" + v_to_min
- if i[:9] == 'wind-flow':
- if w_num == 1:
- stem.w_vol1 = request.form[i]
- w_num += 1
- elif w_num == 2:
- stem.w_vol2 = request.form[i]
- w_num += 1
- elif w_num == 3:
- stem.w_vol3 = request.form[i]
- else:
- if i[:9] == 'w_from_hr':
- w_from_hr = request.form[i]
- elif i[:10] == 'w_from_min':
- w_from_min = request.form[i]
- if w_from_num == 1:
- stem.w_start1 = w_from_hr + ":" + w_from_min
- w_from_num += 1
- elif w_from_num == 2:
- stem.w_start2 = w_from_hr + ":" + w_from_min
- w_from_num += 1
- elif w_from_num == 3:
- stem.w_start3 = w_from_hr + ":" + w_from_min
- elif i[:7] == 'w_to_hr':
- w_to_hr = request.form[i]
- elif i[:8] == 'w_to_min':
- w_to_min = request.form[i]
- if w_to_num == 1:
- stem.w_end1 = w_to_hr + ":" + w_to_min
- w_to_num += 1
- elif w_to_num == 2:
- stem.w_end2 = w_to_hr + ":" + w_to_min
- w_to_num += 1
- elif w_to_num == 3:
- stem.w_end3 = w_to_hr + ":" + w_to_min
- if i[:10] == 'us_from_hr':
- u_s_from_hr = request.form[i]
- elif i[:11] == 'us_from_min':
- u_s_from_min = request.form[i]
- if u_s_from_num == 1:
- stem.u_s_start1 = u_s_from_hr + ":" + u_s_from_min
- u_s_from_num += 1
- elif u_s_from_num == 2:
- stem.u_s_start2 = u_s_from_hr + ":" + u_s_from_min
- u_s_from_num += 1
- elif u_s_from_num == 3:
- stem.u_s_start3 = u_s_from_hr + ":" + u_s_from_min
- elif i[:8] == 'us_to_hr':
- u_s_to_hr = request.form[i]
- elif i[:9] == 'us_to_min':
- u_s_to_min = request.form[i]
- if u_s_to_num == 1:
- stem.u_s_end1 = u_s_to_hr + ":" + u_s_to_min
- u_s_to_num += 1
- elif u_s_to_num == 2:
- stem.u_s_end2 = u_s_to_hr + ":" + u_s_to_min
- u_s_to_num += 1
- elif u_s_to_num == 3:
- stem.u_s_end3 = u_s_to_hr + ":" + u_s_to_min
- if 'ultra-sonic-on' in request.form:
- stem.u_s_status = 1
- else:
- stem.u_s_status = 0
- if 'volume' in request.form:
- stem.u_s_vol = request.form['volume']
- if 'bright-on' in request.form:
- stem.l_bright_auto = 1
- else:
- stem.l_bright_auto = 0
- stem.l_bright_vol = request.form['bright-vol']
- if 'camera-on' in request.form:
- stem.c_status = 1
- else:
- stem.c_status = 0
- stem.c_duration = request.form['duration']
- stem.rh = request.form['rh']
- db.session.add(stem)
- db.session.commit()
- print(request.form)
- # return render_template('online_fitolab.html', params=locals())
- return redirect('online_fitolab')
- #online_fitolab的訪問路徑
- @main.route('/online_fitolab', methods=['POST',"GET"])
- def online_fitolib_views():
- username = session['uname']
- if request.method == 'GET':
- stem = StemSystem.query.order_by(text('datetime desc')).first()
- root = RootSystem.query.order_by(text('datetime desc')).first()
- liquid = LiquidTank.query.order_by(text('datetime desc')).first()
- fitolab1 = Fitolab1Sensor.query.order_by(text('datetime desc')).first()
- try:
- stem_r = str(stem.l_r)
- stem_g = str(stem.l_g)
- stem_b = str(stem.l_b)
- stem_color = '(' + stem_r + ',' + stem_g + ',' + stem_b + ')'
- except Exception:
- pass
- try:
- if stem.l_bright_auto == 0:
- #+1是為了讓前端不要判定為假
- stem_bright_on = stem.l_bright_auto + 1
- stem_bright_vol = stem.l_bright_vol
- except Exception:
- pass
- try:
- music1 = stem.m_playlist1
- except Exception:
- pass
- try:
- music2 = stem.m_playlist2
- except Exception:
- pass
- try:
- music3 = stem.m_playlist3
- except Exception:
- pass
- try:
- music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1]
- except Exception:
- pass
- try:
- m_vol = stem.m_vol
- except Exception:
- pass
- try:
- root_r = str(root.l_r)
- root_g = str(root.l_g)
- root_b = str(root.l_b)
- root_color = '(' + root_r + ',' + root_g + ',' + root_b + ')'
- except Exception:
- pass
- try:
- if root.l_bright_auto == 0:
- #+1是為了讓前端不要判定為假
- root_bright_on = root.l_bright_auto + 1
- root_bright_vol = root.l_bright_vol
- except Exception:
- pass
- try:
- vibration1 = stem.v_vol1
- except Exception:
- pass
- try:
- vibration2 = stem.v_vol2
- except Exception:
- pass
- try:
- vibration3 = stem.v_vol3
- except Exception:
- pass
- try:
- v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1]
- except Exception:
- pass
- try:
- v_pow = stem.v_power
- except Exception:
- pass
- try:
- tank1_duration1 = liquid.tk1_duration1
- tank2_duration1 = liquid.tk2_duration1
- tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1]
- tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1]
- tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1]
- tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1]
- tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1]
- tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1]
- tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1]
- except Exception:
- pass
- try:
- if stem.c_status == 0:
- # +1是為了讓前端不要判定為假
- camera_on = stem.c_status + 1
- except Exception:
- pass
- try:
- c_duration = stem.c_duration
- except Exception:
- pass
- try:
- music1 = stem.m_playlist1
- except Exception:
- pass
- try:
- music2 = stem.m_playlist2
- except Exception:
- pass
- try:
- music3 = stem.m_playlist3
- except Exception:
- pass
- try:
- music_from_hr1, music_from_min1 = stem.m_start1.split(':')[0], stem.m_start1.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr1, music_to_min1 = stem.m_end1.split(':')[0], stem.m_end1.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr2, music_from_min2 = stem.m_start2.split(':')[0], stem.m_start2.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr2, music_to_min2 = stem.m_end2.split(':')[0], stem.m_end2.split(':')[1]
- except Exception:
- pass
- try:
- music_from_hr3, music_from_min3 = stem.m_start3.split(':')[0], stem.m_start3.split(':')[1]
- except Exception:
- pass
- try:
- music_to_hr3, music_to_min3 = stem.m_end3.split(':')[0], stem.m_end3.split(':')[1]
- except Exception:
- pass
- try:
- m_vol = stem.m_vol
- except Exception:
- pass
- try:
- if stem.c_status == 0:
- #+1是為了讓前端不要判定為假
- camara_on = stem.c_status + 1
- except Exception:
- pass
- try:
- vibration1 = stem.v_vol1
- except Exception:
- pass
- try:
- vibration2 = stem.v_vol2
- except Exception:
- pass
- try:
- vibration3 = stem.v_vol3
- except Exception:
- pass
- try:
- v_from_hr1, v_from_min1 = stem.v_start1.split(':')[0], stem.v_start1.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr1, v_to_min1 = stem.v_end1.split(':')[0], stem.v_end1.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr2, v_from_min2 = stem.v_start2.split(':')[0], stem.v_start2.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr2, v_to_min2 = stem.v_end2.split(':')[0], stem.v_end2.split(':')[1]
- except Exception:
- pass
- try:
- v_from_hr3, v_from_min3 = stem.v_start3.split(':')[0], stem.v_start3.split(':')[1]
- except Exception:
- pass
- try:
- v_to_hr3, v_to_min3 = stem.v_end3.split(':')[0], stem.v_end3.split(':')[1]
- except Exception:
- pass
- try:
- v_pow = stem.v_power
- except Exception:
- pass
- try:
- tank1_duration1 = liquid.tk1_duration1
- except Exception:
- pass
- try:
- tank1_duration2 = liquid.tk1_duration2
- except Exception:
- pass
- try:
- tank1_duration3 = liquid.tk1_duration3
- except Exception:
- pass
- try:
- tank2_duration1 = liquid.tk2_duration1
- except Exception:
- pass
- try:
- tank2_duration2 = liquid.tk2_duration2
- except Exception:
- pass
- try:
- tank2_duration3 = liquid.tk2_duration3
- except Exception:
- pass
- try:
- tank1_from_hr1, tank1_from_min1 = liquid.tk1_start1.split(':')[0], liquid.tk1_start1.split(':')[1]
- tank1_to_hr1, tank1_to_min1 = liquid.tk1_end1.split(':')[0], liquid.tk1_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr2, tank1_from_min2 = liquid.tk1_start2.split(':')[0], liquid.tk1_start2.split(':')[1]
- tank1_to_hr2, tank1_to_min2 = liquid.tk1_end2.split(':')[0], liquid.tk1_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank1_from_hr3, tank1_from_min3 = liquid.tk1_start3.split(':')[0], liquid.tk1_start3.split(':')[1]
- tank1_to_hr3, tank1_to_min3 = liquid.tk1_end3.split(':')[0], liquid.tk1_end3.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr1, tank2_from_min1 = liquid.tk2_start1.split(':')[0], liquid.tk2_start1.split(':')[1]
- tank2_to_hr1, tank2_to_min1 = liquid.tk2_end1.split(':')[0], liquid.tk2_end1.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr2, tank2_from_min2 = liquid.tk2_start2.split(':')[0], liquid.tk2_start2.split(':')[1]
- tank2_to_hr2, tank2_to_min2 = liquid.tk2_end2.split(':')[0], liquid.tk2_end2.split(':')[1]
- except Exception:
- pass
- try:
- tank2_from_hr3, tank2_from_min3 = liquid.tk2_start3.split(':')[0], liquid.tk2_start3.split(':')[1]
- tank2_to_hr3, tank2_to_min3 = liquid.tk2_end3.split(':')[0], liquid.tk2_end3.split(':')[1]
- except Exception:
- pass
- try:
- air_temp1 = fitolab1.s_air_tem1
- except Exception:
- pass
- try:
- air_humidity1 = fitolab1.s_humidity
- except Exception:
- pass
- try:
- ph = fitolab1.r_ph
- except Exception:
- pass
- try:
- do = fitolab1.r_do
- except Exception:
- pass
- try:
- ec = fitolab1.r_ec
- except Exception:
- pass
- try:
- water_level = fitolab1.r_water_level
- except Exception:
- pass
- try:
- tds1 = fitolab1.r_turbidity
- except Exception:
- pass
- try:
- o3 = fitolab1.s_o3
- except Exception:
- pass
- try:
- co2 = fitolab1.s_co2
- except Exception:
- pass
- try:
- h2 = fitolab1.s_h2
- except Exception:
- pass
- try:
- weight1 = fitolab1.s_wgt_sensor1
- except Exception:
- pass
- try:
- weight2 = fitolab1.s_wgt_sensor2
- except Exception:
- pass
- return render_template('online_fitolab.html', params=locals())
- else:
- stem = StemSystem.query.order_by(text('datetime desc')).first()
- root = RootSystem.query.order_by(text('datetime desc')).first()
- liquid = LiquidTank.query.order_by(text('datetime desc')).first()
- fitolab1 = Fitolab1Sensor.query.order_by(text('datetime desc')).first()
- music_num = 1
- music_from_num = 1
- music_to_num = 1
- v_num = 1
- v_from_num = 1
- v_to_num = 1
- tank1_num = 1
- tank1_from_num = 1
- tank1_to_num = 1
- tank2_num = 1
- tank2_from_num = 1
- tank2_to_num = 1
- for i in request.form:
- if i == 'stem-color':
- try:
- color = request.form['stem-color']
- stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- elif i == 'root-color':
- try:
- color = request.form['root-color']
- root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- if 'stem-bright-on' in request.form:
- stem.l_bright_auto = 1
- else:
- stem.l_bright_auto = 0
- if 'root-bright-on' in request.form:
- root.l_bright_auto = 1
- else:
- root.l_bright_auto = 0
- if i[:5] == 'music' and len(i) <=11:
- if music_num == 1:
- stem.m_playlist1 = request.form[i]
- stem.m_playlist2 = None
- stem.m_playlist3 = None
- music_num += 1
- elif music_num == 2:
- stem.m_playlist2 = request.form[i]
- stem.m_playlist3 = None
- music_num += 1
- elif music_num == 3:
- stem.m_playlist3 = request.form[i]
- else:
- if i[:13] == 'music_from_hr':
- music_from_hr = request.form[i]
- elif i[:14] == 'music_from_min':
- music_from_min = request.form[i]
- if music_from_num == 1:
- stem.m_start1 = music_from_hr + ":" + music_from_min
- stem.m_start2 = None
- stem.m_start3 = None
- music_from_num += 1
- elif music_from_num == 2:
- stem.m_start2 = music_from_hr + ":" + music_from_min
- stem.m_start3 = None
- music_from_num += 1
- elif music_from_num == 3:
- stem.m_start3 = music_from_hr + ":" + music_from_min
- elif i[:11] == 'music_to_hr':
- music_to_hr = request.form[i]
- elif i[:12] == 'music_to_min':
- music_to_min = request.form[i]
- if music_to_num == 1:
- stem.m_end1 = music_to_hr + ":" + music_to_min
- stem.m_end2 = None
- stem.m_end3 = None
- music_to_num += 1
- elif music_to_num == 2:
- stem.m_end2 = music_to_hr + ":" + music_to_min
- stem.m_end3 = None
- music_to_num += 1
- elif music_to_num == 3:
- stem.m_end3 = music_to_hr + ":" + music_to_min
- if 'camera-on' in request.form:
- stem.c_status = 1
- else:
- stem.c_status = 0
- if i[:9] == 'vibration':
- if v_num == 1:
- stem.v_vol1 = request.form[i]
- stem.v_vol2 = None
- stem.v_vol3 = None
- v_num += 1
- elif v_num == 2:
- stem.v_vol2 = request.form[i]
- stem.v_vol3 = None
- v_num += 1
- elif v_num == 3:
- stem.v_vol3 = request.form[i]
- else:
- if i[:9] == 'v_from_hr':
- v_from_hr = request.form[i]
- elif i[:10] == 'v_from_min':
- v_from_min = request.form[i]
- if v_from_num == 1:
- stem.v_start1 = v_from_hr + ":" + v_from_min
- stem.v_start2 = None
- stem.v_start3 = None
- v_from_num += 1
- elif v_from_num == 2:
- stem.v_start2 = v_from_hr + ":" + v_from_min
- stem.v_start3 = None
- v_from_num += 1
- elif v_from_num == 3:
- stem.v_start3 = v_from_hr + ":" + v_from_min
- elif i[:7] == 'v_to_hr':
- v_to_hr = request.form[i]
- elif i[:8] == 'v_to_min':
- v_to_min = request.form[i]
- if v_to_num == 1:
- stem.v_end1 = v_to_hr + ":" + v_to_min
- stem.v_end2 = None
- stem.v_end3 = None
- v_to_num += 1
- elif v_to_num == 2:
- stem.v_end2 = v_to_hr + ":" + v_to_min
- stem.v_end3 = None
- v_to_num += 1
- elif v_to_num == 3:
- stem.v_end3 = v_to_hr + ":" + v_to_min
- if i[:14] == 'tank1_duration':
- if tank1_num == 1:
- liquid.tk1_duration1 = request.form[i]
- liquid.tk1_duration2 = None
- liquid.tk1_duration3 = None
- tank1_num += 1
- elif tank1_num == 2:
- liquid.tk1_duration2 = request.form[i]
- liquid.tk1_duration3 = None
- tank1_num += 1
- elif tank1_num == 3:
- liquid.tk1_duration3 = request.form[i]
- else:
- if i[:13] == 'tank1_from_hr':
- tk1_from_hr = request.form[i]
- elif i[:14] == 'tank1_from_min':
- tk1_from_min = request.form[i]
- if tank1_from_num == 1:
- liquid.tk1_start1 = tk1_from_hr + ":" + tk1_from_min
- liquid.tk1_start2 = None
- liquid.tk1_start3 = None
- tank1_from_num += 1
- elif tank1_from_num == 2:
- liquid.tk1_start2 = tk1_from_hr + ":" + tk1_from_min
- liquid.tk1_start3 = None
- tank1_from_num += 1
- elif tank1_from_num == 3:
- liquid.tk1_start3 = tk1_from_hr + ":" + tk1_from_min
- elif i[:11] == 'tank1_to_hr':
- tk1_to_hr = request.form[i]
- elif i[:12] == 'tank1_to_min':
- tk1_to_min = request.form[i]
- if tank1_to_num == 1:
- liquid.tk1_end1 = tk1_to_hr + ":" + tk1_to_min
- liquid.tk1_end2 = None
- liquid.tk1_end3 = None
- tank1_to_num += 1
- elif tank1_to_num == 2:
- liquid.tk1_end2 = tk1_to_hr + ":" + tk1_to_min
- liquid.tk1_end3 = None
- tank1_to_num += 1
- elif tank1_to_num == 3:
- liquid.tk1_end3 = tk1_to_hr + ":" + tk1_to_min
- if i[:14] == 'tank2_duration':
- if tank2_num == 1:
- liquid.tk2_duration1 = request.form[i]
- liquid.tk2_duration2 = None
- liquid.tk2_duration3 = None
- tank2_num += 1
- elif tank2_num == 2:
- liquid.tk2_duration2 = request.form[i]
- liquid.tk2_duration3 = None
- tank2_num += 1
- elif tank2_num == 3:
- liquid.tk2_duration3 = request.form[i]
- else:
- if i[:13] == 'tank2_from_hr':
- tk2_from_hr = request.form[i]
- elif i[:14] == 'tank2_from_min':
- tk2_from_min = request.form[i]
- if tank2_from_num == 1:
- liquid.tk2_start1 = tk2_from_hr + ":" + tk2_from_min
- liquid.tk2_start2 = None
- liquid.tk2_start3 = None
- tank2_from_num += 1
- elif tank2_from_num == 2:
- liquid.tk2_start2 = tk2_from_hr + ":" + tk2_from_min
- liquid.tk2_start3 = None
- tank2_from_num += 1
- elif tank2_from_num == 3:
- liquid.tk2_start3 = tk2_from_hr + ":" + tk2_from_min
- elif i[:11] == 'tank2_to_hr':
- tk2_to_hr = request.form[i]
- elif i[:12] == 'tank2_to_min':
- tk2_to_min = request.form[i]
- if tank2_to_num == 1:
- liquid.tk2_end1 = tk2_to_hr + ":" + tk2_to_min
- liquid.tk2_end2 = None
- liquid.tk2_end3 = None
- tank2_to_num += 1
- elif tank2_to_num == 2:
- liquid.tk2_end2 = tk2_to_hr + ":" + tk2_to_min
- liquid.tk2_end3 = None
- tank2_to_num += 1
- elif tank2_to_num == 3:
- liquid.tk2_end3 = tk2_to_hr + ":" + tk2_to_min
- if i == 'root-color':
- try:
- color = request.form['root-color']
- root.l_r, root.l_g, root.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- if i == 'stem-color':
- try:
- color = request.form['stem-color']
- stem.l_r, stem.l_g, stem.l_b = color.split(',')[0], color.split(',')[1][1:], color.split(',')[2][1:]
- except Exception:
- pass
- stem.l_bright_vol = request.form['stem-bright-vol']
- root.l_bright_vol = request.form['root-bright-vol']
- stem.m_vol = request.form['m-vol']
- stem.c_duration = request.form['c-duration']
- stem.v_power = request.form['v-pow']
- db.session.add(stem)
- db.session.add(root)
- db.session.commit()
- return redirect('/online_fitolab')
- #退出的訪問路徑
- @main.route('/logout')
- def logout_views():
- if 'id' in session and 'uname' in session:
- del session['id']
- del session['uname']
- return redirect('/')
|