views.py 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. # 主業務邏輯中的視圖和路由的定義
  2. import os
  3. import datetime
  4. from flask import render_template, request, session, Response
  5. # 導入藍圖程序,用於構建路由
  6. from werkzeug.utils import redirect
  7. from . import main
  8. from manage import mqtt
  9. # 導入db,用於操作數據庫
  10. from manage import db
  11. # 導入實體類,用於操作數據庫
  12. from ..models import *
  13. import json
  14. from datetime import datetime as dt, date
  15. from sqlalchemy import text
  16. import socket
  17. import pickle
  18. import cv2
  19. import numpy as np
  20. import math
  21. import threading
  22. import time
  23. from flask_mqtt import Mqtt
  24. import requests
  25. import re
  26. from time import sleep as sl
  27. from concurrent.futures import ThreadPoolExecutor
  28. pool = ThreadPoolExecutor(25)
  29. s_sock = 0
  30. lock = threading.Lock()
  31. # 主頁的訪問路徑
  32. @main.route('/')
  33. def main_index():
  34. # 獲取登入信息
  35. if 'id' in session and 'uname' in session:
  36. return render_template('allindex.html')
  37. else:
  38. return render_template('sign_in.html')
  39. # 登入頁面的訪問路徑
  40. @main.route('/login', methods=['GET', 'POST'])
  41. def login_views():
  42. if request.method == 'GET':
  43. if 'id' in session and 'uname' in session:
  44. return redirect('/')
  45. else:
  46. return render_template('sign_in.html')
  47. else:
  48. # 接收前端傳過來的資料
  49. username = request.form['username']
  50. password = request.form['password']
  51. # 使用接收的用戶和密碼到資料庫中查詢
  52. user = User.query.filter_by(username=username, password=password).first()
  53. # 如果用戶存在,將信息保存置session並重定向回首頁,否則重定向回登入頁
  54. # if user and user.check_hash_password(password):
  55. if user:
  56. resp = redirect('/')
  57. # 判斷是否有記住密碼
  58. if 'rem' in request.form:
  59. sn = str(user.sn)
  60. max_age = 60 * 60 * 24 * 365
  61. resp.set_cookie("username", username, max_age=max_age)
  62. resp.set_cookie("sn", sn, max_age=max_age)
  63. session['uname'] = user.username
  64. session['id'] = user.sn
  65. return resp
  66. else:
  67. errMsg = "Wrong username or password"
  68. return render_template('sign_in.html', errMsg=errMsg)
  69. # 註冊頁面的訪問路徑
  70. @main.route('/register', methods=['POST', "GET"])
  71. def register_views():
  72. if request.method == 'GET':
  73. return render_template('registration.html')
  74. else:
  75. # 獲取文本框的值並賦值給user實體對象
  76. # username = request.form['username']
  77. # password = request.form['password']
  78. # user = User(username=username, password=password)
  79. user = User()
  80. user.username = request.form['username']
  81. user.password = request.form['password']
  82. # 將數據保存進資料庫 - 註冊
  83. db.session.add(user)
  84. # 手動提交,目的是為了獲取提交後的user的id
  85. db.session.commit()
  86. # 當user成功插入進資料庫之後,程序會自動將所有信息取出來在賦值給user
  87. # 完成登入的操作
  88. user = User.query.filter_by(username=user.username).first()
  89. session['id'] = user.sn
  90. session['uname'] = user.username
  91. return redirect('/')
  92. # 毛豆田的主頁面
  93. @main.route('/aindex', methods=['POST', 'GET'])
  94. def aindex_views():
  95. if 'id' not in session and 'uname' not in session:
  96. return redirect('/')
  97. return render_template('aindex.html')
  98. # 毛豆車的主頁面
  99. @main.route('/cindex/<tid>', methods=['POST', 'GET'])
  100. def cindex_views(tid):
  101. if request.method == 'GET':
  102. if 'id' not in session and 'uname' not in session:
  103. return redirect('/')
  104. return render_template('cindex.html', params=locals())
  105. else:
  106. dict = request.form.to_dict()
  107. queryDate = dict['date']
  108. year = int(queryDate.split('-')[0])
  109. month = int(queryDate.split('-')[1])
  110. day = int(queryDate.split('-')[2])
  111. #判斷月份,找出查詢日期的前一天與後一天
  112. if month == 1 or month == 3 or month == 5 or month == 7 or month == 10 or month == 12:
  113. start_year = year
  114. end_year = year
  115. if day == 1:
  116. start_month = month - 1
  117. start_day = 30
  118. end_month = month
  119. end_day = day + 1
  120. if month == 1:
  121. start_year = year - 1
  122. start_month = 12
  123. start_day = 31
  124. if month == 3:
  125. if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
  126. start_day = 29
  127. else:
  128. start_day = 28
  129. elif day == 31:
  130. start_year = year
  131. start_month = month
  132. start_day = day - 1
  133. end_year = year
  134. end_month = month + 1
  135. if month == 12:
  136. end_year = year + 1
  137. end_month = 1
  138. end_day = 1
  139. else:
  140. start_month = month
  141. start_day = day - 1
  142. end_month = month
  143. end_day = day + 1
  144. elif month == 2 or month == 4 or month == 6 or month == 8 or month == 9 or month == 11:
  145. start_year = year
  146. end_year = year
  147. if day == 1:
  148. start_month = month - 1
  149. start_day = 31
  150. end_month = month
  151. end_day = day + 1
  152. elif day == 31:
  153. start_month = month
  154. start_day = day - 1
  155. end_month = month + 1
  156. end_day = 1
  157. elif day == (28 or 29):
  158. if month == 2:
  159. start_month = month
  160. start_day = day - 1
  161. end_month = month + 1
  162. end_day = 1
  163. else:
  164. start_month = month
  165. start_day = day - 1
  166. end_month = month
  167. end_day = day + 1
  168. #print(start_year, start_month, start_day, sep='-')
  169. #print(year, month, day, sep='-')
  170. #print(end_year, end_month, end_day, sep='-')
  171. start = date(year=start_year, month=start_month, day=start_day)
  172. end = date(year=end_year, month=end_month, day=end_day)
  173. if tid == '1':
  174. gps = Skyeye5GpsNr1.query.filter(Skyeye5GpsNr1.datetime < end).filter(Skyeye5GpsNr1.datetime > start).all()
  175. elif tid == '2':
  176. gps = Skyeye5GpsNr2.query.filter(Skyeye5GpsNr2.datetime < end).filter(Skyeye5GpsNr2.datetime > start).all()
  177. elif tid == '3':
  178. gps = Skyeye5GpsNr3.query.filter(Skyeye5GpsNr3.datetime < end).filter(Skyeye5GpsNr3.datetime > start).all()
  179. return render_template('cindex.html', params=locals())
  180. # 毛豆田拍攝設定的主頁面
  181. @main.route('/ashoot_setting/<tid>', methods=['POST', 'GET'])
  182. def ashoot_setting_views(tid):
  183. if request.method == 'GET':
  184. if 'id' not in session and 'uname' not in session:
  185. return redirect('/')
  186. if tid == '1':
  187. nr = 'GTW009002001'
  188. dic = '1'
  189. elif tid == '2':
  190. nr = 'GTW009002002'
  191. dic = '2'
  192. elif tid == '3':
  193. nr = 'GTW009002003'
  194. dic = '3'
  195. elif tid == '4':
  196. nr = 'GTW009002004'
  197. dic = '4'
  198. elif tid == '5':
  199. nr = 'GTW009002005'
  200. dic = '5'
  201. elif tid == '6':
  202. nr = 'GTW009002006'
  203. dic = '6'
  204. elif tid == '7':
  205. nr = 'GTW009002007'
  206. dic = '7'
  207. elif tid == '8':
  208. nr = 'GTW009002008'
  209. dic = '8'
  210. elif tid == '9':
  211. nr = 'GTW009002009'
  212. dic = '9'
  213. elif tid == '10':
  214. nr = 'GTW009002010'
  215. dic = '10'
  216. elif tid == '11':
  217. nr = 'GTW009002011'
  218. dic = '11'
  219. elif tid == '12':
  220. nr = 'GTW009002012'
  221. dic = '12'
  222. elif tid == '13':
  223. nr = 'GTW009002013'
  224. dic = '13'
  225. elif tid == '14':
  226. nr = 'GTW009002014'
  227. dic = '14'
  228. elif tid == '15':
  229. nr = 'GTW009002015'
  230. dic = '15'
  231. elif tid == '16':
  232. nr = 'GTW009002016'
  233. dic = '16'
  234. elif tid == '17':
  235. nr = 'GTW009002017'
  236. dic = '17'
  237. elif tid == '18':
  238. nr = 'GTW009002018'
  239. dic = '18'
  240. elif tid == '19':
  241. nr = 'GTW009002019'
  242. dic = '19'
  243. #讓前端頁面顯示小兵現在的位置以及最新照片
  244. try:
  245. orientation = Orientation.query.filter_by(nr=nr).order_by(text('datetime desc')).first()
  246. mode = orientation.mode
  247. begin_tilt_angle = orientation.tilt_angle
  248. begin_pan_angle = orientation.pan_angle
  249. begin_zoom = orientation.zoom
  250. except Exception as e:
  251. pass
  252. try:
  253. # 可見光(自動拍照)路徑
  254. path = 'http://60.250.156.234/cust/' + dic + '/nj' + str(mode)
  255. res = requests.get(path).text
  256. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.jpg)"', re.S)
  257. img = p.findall(res)[-1]
  258. begin_imgPath = path + '/' + img
  259. except Exception as e:
  260. begin_imgPath = '../static/img/PV.jpg'
  261. #讓前端頁面顯示小兵已設定好哪些方位
  262. if int(tid) < 10:
  263. nr = "GTW00900200" + tid
  264. else:
  265. nr = "GTW0090020" + tid
  266. jvtotime = JvtOTime.query.filter_by(nr=nr).group_by('mode')
  267. mode = []
  268. for jvt in jvtotime:
  269. mode.append(jvt.mode)
  270. dict = request.args.to_dict()
  271. #刪除小兵設定的方位
  272. try:
  273. if dict['delete']:
  274. if int(dict['nr']) < 10:
  275. nr = "GTW00900200" + dict['nr']
  276. else:
  277. nr = "GTW0090020" + dict['nr']
  278. mode = int(dict['mode'])
  279. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  280. db.session.delete(jvtotime)
  281. db.session.commit()
  282. return {"delete":"ok"}
  283. except Exception:
  284. pass
  285. # 讓前端頁面顯示小兵已設定好的方位資訊
  286. if dict:
  287. try:
  288. if int(dict['nr']) < 10:
  289. nr = "GTW00900200" + dict['nr']
  290. else:
  291. nr = "GTW0090020" + dict['nr']
  292. mode = int(dict['mode'])
  293. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  294. name = jvtotime.name
  295. tilt_angle = jvtotime.tilt_angle
  296. pan_angle = jvtotime.pan_angle
  297. zoom = str(jvtotime.zoom)
  298. time1 = jvtotime.time1
  299. time2 = jvtotime.time2
  300. time3 = jvtotime.time3
  301. time4 = jvtotime.time4
  302. time5 = jvtotime.time5
  303. time6 = jvtotime.time6
  304. time7 = jvtotime.time7
  305. time8 = jvtotime.time8
  306. dict = {"name": name, "tilt_angle": tilt_angle, "pan_angle": pan_angle, "zoom": zoom, "time1": time1,
  307. "time2": time2, "time3": time3, "time4": time4, "time5": time5, "time6": time6,
  308. "time7": time7, "time8": time8}
  309. return json.dumps(dict)
  310. except Exception:
  311. dict = {"name": "", "tilt_angle": "0", "pan_angle": "0", "zoom": "0", "time1": "00000000",
  312. "time2": "00000000", "time3": "00000000", "time4": "00000000", "time5": "00000000",
  313. "time6": "00000000", "time7": "00000000", "time8": "00000000"}
  314. return json.dumps(dict)
  315. return render_template('aim.html', params=locals())
  316. else:
  317. dict = request.form.to_dict()
  318. if int(dict['nr']) < 10:
  319. nr = "GTW00900200" + dict['nr']
  320. else:
  321. nr = "GTW0090020" + dict['nr']
  322. mode = int(dict['mode'])
  323. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  324. #判斷是否已存在舊的方位設定,如不存在就創建新對象
  325. if not jvtotime:
  326. jvtotime = JvtOTime()
  327. jvtotimehistory = JvtOTimeHistory()
  328. orientation = Orientation()
  329. if dict['nr'] == '1':
  330. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:95:00:53'
  331. elif dict['nr'] == '2':
  332. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:e7:51:44'
  333. elif dict['nr'] == '3':
  334. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:ce:a5:35'
  335. elif dict['nr'] == '4':
  336. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:fc:9d:34'
  337. elif dict['nr'] == '5':
  338. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:86:00:c9'
  339. elif dict['nr'] == '6':
  340. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:df:4b:0f'
  341. elif dict['nr'] == '7':
  342. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:6a:5d:17'
  343. elif dict['nr'] == '8':
  344. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:d2:d0:8f'
  345. elif dict['nr'] == '9':
  346. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:57:3c:da'
  347. elif dict['nr'] == '10':
  348. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:bd:29:b1'
  349. elif dict['nr'] == '11':
  350. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:7c:f6:06'
  351. elif dict['nr'] == '12':
  352. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:59:9d:bd'
  353. elif dict['nr'] == '13':
  354. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:e7:21:e5'
  355. elif dict['nr'] == '14':
  356. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:34:9e:39'
  357. elif dict['nr'] == '15':
  358. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:e3:f1:f4'
  359. elif dict['nr'] == '16':
  360. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:f8:24:92'
  361. elif dict['nr'] == '17':
  362. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:9d:68:05'
  363. elif dict['nr'] == '18':
  364. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:4d:e4:34'
  365. elif dict['nr'] == '19':
  366. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:e7:16:28'
  367. if int(dict['nr']) < 10:
  368. jvtotime.nr = jvtotimehistory.nr = orientation.nr = 'GTW00900200' + dict['nr']
  369. else:
  370. jvtotime.nr = jvtotimehistory.nr = orientation.nr = 'GTW0090020' + dict['nr']
  371. jvtotime.name = jvtotimehistory.name = dict['ori_name']
  372. jvtotime.mode = jvtotimehistory.mode = orientation.mode = int(dict['mode'])
  373. jvtotime.tilt_angle = jvtotimehistory.tilt_angle = orientation.tilt_angle = dict['tilt_angle']
  374. jvtotime.pan_angle = jvtotimehistory.pan_angle = orientation.pan_angle = dict['pan_angle']
  375. jvtotime.zoom = jvtotimehistory.zoom = orientation.zoom = int(dict['zoom'])
  376. jvtotime.time1 = jvtotimehistory.time1 = dict['time1']
  377. jvtotime.time2 = jvtotimehistory.time2 = dict['time2']
  378. jvtotime.time3 = jvtotimehistory.time3 = dict['time3']
  379. jvtotime.time4 = jvtotimehistory.time4 = dict['time4']
  380. jvtotime.time5 = jvtotimehistory.time5 = dict['time5']
  381. jvtotime.time6 = jvtotimehistory.time6 = dict['time6']
  382. jvtotime.time7 = jvtotimehistory.time7 = dict['time7']
  383. jvtotime.time8 = jvtotimehistory.time8 = dict['time8']
  384. jvtotime.datetime = jvtotimehistory.datetime = orientation.datetime = dt.now()
  385. db.session.add(jvtotime)
  386. db.session.add(jvtotimehistory)
  387. db.session.add(orientation)
  388. db.session.commit()
  389. return {"status": "OK"}
  390. # #毛豆田車小兵現在所在位置的訪問路徑
  391. # @main.route('/orientation/<tid>', methods=['POST', 'GET'])
  392. # def orientation_views(tid):
  393. # if request.method == 'GET':
  394. # dict = request.args.to_dict()
  395. # nr = dict['nr']
  396. #
  397. # if nr == 'GTW009001001':
  398. # dic = '1m'
  399. # elif nr == 'GTW009001002':
  400. # dic = '2m'
  401. # elif nr == 'GTW009001003':
  402. # dic = '3m'
  403. # elif nr == 'GTW009002001':
  404. # dic = '1'
  405. # elif nr == 'GTW009002002':
  406. # dic = '2'
  407. # elif nr == 'GTW009002003':
  408. # dic = '3'
  409. # elif nr == 'GTW009002004':
  410. # dic = '4'
  411. # elif nr == 'GTW009002005':
  412. # dic = '5'
  413. # elif nr == 'GTW009002006':
  414. # dic = '6'
  415. # elif nr == 'GTW009002007':
  416. # dic = '7'
  417. # elif nr == 'GTW009002008':
  418. # dic = '8'
  419. # elif nr == 'GTW009002009':
  420. # dic = '9'
  421. # elif nr == 'GTW009002010':
  422. # dic = '10'
  423. # elif nr == 'GTW009002011':
  424. # dic = '11'
  425. # elif nr == 'GTW009002012':
  426. # dic = '12'
  427. # elif nr == 'GTW009002013':
  428. # dic = '13'
  429. # elif nr == 'GTW009002014':
  430. # dic = '14'
  431. # elif nr == 'GTW009002015':
  432. # dic = '15'
  433. # elif nr == 'GTW009002016':
  434. # dic = '16'
  435. # elif nr == 'GTW009002017':
  436. # dic = '17'
  437. # elif nr == 'GTW009002018':
  438. # dic = '18'
  439. #
  440. #
  441. #
  442. # try:
  443. # orientation = Orientation.query.filter_by(nr=nr).order_by(text('datetime desc')).first()
  444. # mode = orientation.mode
  445. # tilt_angle = orientation.tilt_angle
  446. # pan_angle = orientation.pan_angle
  447. # zoom = orientation.zoom
  448. #
  449. #
  450. # dict = {"tilt_angle":tilt_angle, "pan_angle":pan_angle, "zoom":zoom, "status":True}
  451. #
  452. # except Exception as e:
  453. # dict = {"status": False}
  454. # return json.dumps(dict)
  455. # try:
  456. # # 可見光(自動拍照)路徑
  457. # path = 'http://60.250.156.234/cust/' + dic + '/nj' + str(mode)
  458. # res = requests.get(path).text
  459. # p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.jpg)"', re.S)
  460. # img = p.findall(res)[-1]
  461. # imgPath = path + '/' + img
  462. # except Exception as e:
  463. # imgPath = '../static/img/PV.jpg'
  464. #
  465. # dict['img'] = imgPath
  466. # return json.dumps(dict)
  467. # else:
  468. # pass
  469. # 毛豆田歷史資料的主頁面
  470. @main.route('/aimg_history/<tid>', methods=['POST', 'GET'])
  471. def aimg_history_views(tid):
  472. if request.method == 'GET':
  473. if 'id' not in session and 'uname' not in session:
  474. return redirect('/')
  475. #手動拍攝訊息
  476. res = requests.get('http://60.250.156.234/cust/c' + tid + '.txt')
  477. data = res.text
  478. #判斷是否沒有此文件且為空頁面
  479. if "404 Not Found" not in data and data:
  480. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  481. try:
  482. #匹配出年份
  483. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  484. # 先轉成集合去重,在轉成列表做排序
  485. Ly = list(set(py.findall(data)))
  486. Ly.sort(reverse = True)
  487. #匹配出月份
  488. pm = re.compile(Ly[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  489. Lm = list(set(pm.findall(data)))
  490. Lm.sort(reverse = True)
  491. #匹配出天數
  492. pd = re.compile(Ly[0] + "-" + Lm[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  493. Ld = list(set(pd.findall(data)))
  494. Ld.sort(reverse=True)
  495. #匹配出時間
  496. pt = re.compile(Ly[0] + "-" + Lm[0] + "-" + Ld[0] + r'\_(\d+\.\d+)n', re.S)
  497. Lt = list(set(pt.findall(data)))
  498. Lt.sort(reverse = True)
  499. except Exception as e:
  500. pass
  501. #1號方位訊息
  502. res = requests.get('http://60.250.156.234/cust/c' + tid + '_1.txt')
  503. res.encoding = 'utf-8'
  504. data = res.text
  505. if "404 Not Found" not in data and data:
  506. #如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  507. try:
  508. #匹配出方位名稱
  509. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  510. L = pn.findall(data)[::-1]
  511. # 先轉成集合去重,在轉成列表做排序
  512. Ln1 = list(set(L))
  513. #讓排序不受到中文編碼影響,加入index
  514. Ln1.sort(key=L.index)
  515. #匹配出年份
  516. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  517. # 先轉成集合去重,在轉成列表做排序
  518. Ly1 = list(set(py.findall(data)))
  519. Ly1.sort(reverse=True)
  520. #匹配出月份
  521. pm = re.compile(Ly1[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  522. Lm1 = list(set(pm.findall(data)))
  523. Lm1.sort(reverse=True)
  524. #匹配出天數
  525. pd = re.compile(Ly1[0] + "-" + Lm1[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  526. Ld1 = list(set(pd.findall(data)))
  527. Ld1.sort(reverse=True)
  528. #匹配出時間
  529. pt = re.compile(Ly1[0] + "-" + Lm1[0] + "-" + Ld1[0] + r'\_(\d+\.\d+)n', re.S)
  530. Lt1 = list(set(pt.findall(data)))
  531. Lt1.sort(reverse = True)
  532. except Exception as e:
  533. pass
  534. #2號方位訊息
  535. res = requests.get('http://60.250.156.234/cust/c' + tid + '_2.txt')
  536. res.encoding = 'utf-8'
  537. data = res.text
  538. if "404 Not Found" not in data and data:
  539. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  540. try:
  541. #匹配出方位名稱
  542. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  543. L = pn.findall(data)[::-1]
  544. # 先轉成集合去重,在轉成列表做排序
  545. Ln2 = list(set(L))
  546. #讓排序不受到中文編碼影響,加入index
  547. Ln2.sort(key=L.index)
  548. #匹配出年份
  549. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  550. # 先轉成集合去重,在轉成列表做排序
  551. Ly2 = list(set(py.findall(data)))
  552. Ly2.sort(reverse = True)
  553. #匹配出月份
  554. pm = re.compile(Ly2[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  555. Lm2 = list(set(pm.findall(data)))
  556. Lm2.sort(reverse = True)
  557. #匹配出天數
  558. pd = re.compile(Ly2[0] + "-" + Lm2[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  559. Ld2 = list(set(pd.findall(data)))
  560. Ld2.sort(reverse = True)
  561. #匹配出時間
  562. pt = re.compile(Ly2[0] + "-" + Lm2[0] + "-" + Ld2[0] + r'\_(\d+\.\d+)n', re.S)
  563. Lt2 = list(set(pt.findall(data)))
  564. Lt2.sort(reverse = True)
  565. except Exception as e:
  566. pass
  567. #3號方位訊息
  568. res = requests.get('http://60.250.156.234/cust/c' + tid + '_3.txt')
  569. res.encoding = 'utf-8'
  570. data = res.text
  571. if "404 Not Found" not in data and data:
  572. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  573. try:
  574. #匹配出方位名稱
  575. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  576. L = pn.findall(data)[::-1]
  577. # 先轉成集合去重,在轉成列表做排序
  578. Ln3 = list(set(L))
  579. #讓排序不受到中文編碼影響,加入index
  580. Ln3.sort(key=L.index)
  581. #匹配出年份
  582. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  583. # 先轉成集合去重,在轉成列表做排序
  584. Ly3 = list(set(py.findall(data)))
  585. Ly3.sort(reverse = True)
  586. #匹配出月份
  587. pm = re.compile(Ly3[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  588. Lm3 = list(set(pm.findall(data)))
  589. Lm3.sort(reverse = True)
  590. #匹配出天數
  591. pd = re.compile(Ly3[0] + "-" + Lm3[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  592. Ld3 = list(set(pd.findall(data)))
  593. Ld3.sort(reverse = True)
  594. #匹配出時間
  595. pt = re.compile(Ly3[0] + "-" + Lm3[0] + "-" + Ld3[0] + r'\_(\d+\.\d+)n', re.S)
  596. Lt3 = list(set(pt.findall(data)))
  597. Lt3.sort(reverse = True)
  598. except Exception as e:
  599. pass
  600. #4號方位訊息
  601. res = requests.get('http://60.250.156.234/cust/c' + tid + '_4.txt')
  602. res.encoding = 'utf-8'
  603. data = res.text
  604. if "404 Not Found" not in data and data:
  605. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  606. try:
  607. #匹配出方位名稱
  608. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  609. L = pn.findall(data)[::-1]
  610. # 先轉成集合去重,在轉成列表做排序
  611. Ln4 = list(set(L))
  612. #讓排序不受到中文編碼影響,加入index
  613. Ln4.sort(key=L.index)
  614. #匹配出年份
  615. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  616. # 先轉成集合去重,在轉成列表做排序
  617. Ly4 = list(set(py.findall(data)))
  618. Ly4.sort(reverse = True)
  619. #匹配出月份
  620. pm = re.compile(Ly4[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  621. Lm4 = list(set(pm.findall(data)))
  622. Lm4.sort(reverse = True)
  623. #匹配出天數
  624. pd = re.compile(Ly4[0] + "-" + Lm4[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  625. Ld4 = list(set(pd.findall(data)))
  626. Ld4.sort(reverse = True)
  627. #匹配出時間
  628. pt = re.compile(Ly4[0] + "-" + Lm4[0] + "-" + Ld4[0] + r'\_(\d+\.\d+)n', re.S)
  629. Lt4 = list(set(pt.findall(data)))
  630. Lt4.sort(reverse = True)
  631. except Exception as e:
  632. pass
  633. #5號方位訊息
  634. res = requests.get('http://60.250.156.234/cust/c' + tid + '_5.txt')
  635. res.encoding = 'utf-8'
  636. data = res.text
  637. if "404 Not Found" not in data and data:
  638. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  639. try:
  640. #匹配出方位名稱
  641. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  642. L = pn.findall(data)[::-1]
  643. # 先轉成集合去重,在轉成列表做排序
  644. Ln5 = list(set(L))
  645. #讓排序不受到中文編碼影響,加入index
  646. Ln5.sort(key=L.index)
  647. #匹配出年份
  648. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  649. # 先轉成集合去重,在轉成列表做排序
  650. Ly5 = list(set(py.findall(data)))
  651. Ly5.sort(reverse = True)
  652. #匹配出月份
  653. pm = re.compile(Ly5[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  654. Lm5 = list(set(pm.findall(data)))
  655. Lm5.sort(reverse = True)
  656. #匹配出天數
  657. pd = re.compile(Ly5[0] + "-" + Lm5[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  658. Ld5 = list(set(pd.findall(data)))
  659. Ld5.sort(reverse = True)
  660. #匹配出時間
  661. pt = re.compile(Ly5[0] + "-" + Lm5[0] + "-" + Ld5[0] + r'\_(\d+\.\d+)n', re.S)
  662. Lt5 = list(set(pt.findall(data)))
  663. Lt5.sort(reverse = True)
  664. except Exception as e:
  665. pass
  666. #6號方位訊息
  667. res = requests.get('http://60.250.156.234/cust/c' + tid + '_6.txt')
  668. res.encoding = 'utf-8'
  669. data = res.text
  670. if "404 Not Found" not in data and data:
  671. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  672. try:
  673. #匹配出方位名稱
  674. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  675. L = pn.findall(data)[::-1]
  676. # 先轉成集合去重,在轉成列表做排序
  677. Ln6 = list(set(L))
  678. #讓排序不受到中文編碼影響,加入index
  679. Ln6.sort(key=L.index)
  680. #匹配出年份
  681. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  682. # 先轉成集合去重,在轉成列表做排序
  683. Ly6 = list(set(py.findall(data)))
  684. Ly6.sort(reverse = True)
  685. #匹配出月份
  686. pm = re.compile(Ly6[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  687. Lm6 = list(set(pm.findall(data)))
  688. Lm6.sort(reverse = True)
  689. #匹配出天數
  690. pd = re.compile(Ly6[0] + "-" + Lm6[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  691. Ld6 = list(set(pd.findall(data)))
  692. Ld6.sort(reverse = True)
  693. #匹配出時間
  694. pt = re.compile(Ly6[0] + "-" + Lm6[0] + "-" + Ld6[0] + r'\_(\d+\.\d+)n', re.S)
  695. Lt6 = list(set(pt.findall(data)))
  696. Lt6.sort(reverse = True)
  697. except Exception as e:
  698. pass
  699. #7號方位訊息
  700. res = requests.get('http://60.250.156.234/cust/c' + tid + '_7.txt')
  701. res.encoding = 'utf-8'
  702. data = res.text
  703. if "404 Not Found" not in data and data:
  704. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  705. try:
  706. #匹配出方位名稱
  707. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  708. L = pn.findall(data)[::-1]
  709. # 先轉成集合去重,在轉成列表做排序
  710. Ln7 = list(set(L))
  711. #讓排序不受到中文編碼影響,加入index
  712. Ln7.sort(key=L.index)
  713. #匹配出年份
  714. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  715. # 先轉成集合去重,在轉成列表做排序
  716. Ly7 = list(set(py.findall(data)))
  717. Ly7.sort(reverse = True)
  718. #匹配出月份
  719. pm = re.compile(Ly7[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  720. Lm7 = list(set(pm.findall(data)))
  721. Lm7.sort(reverse = True)
  722. #匹配出天數
  723. pd = re.compile(Ly7[0] + "-" + Lm7[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  724. Ld7 = list(set(pd.findall(data)))
  725. Ld7.sort(reverse = True)
  726. #匹配出時間
  727. pt = re.compile(Ly7[0] + "-" + Lm7[0] + "-" + Ld7[0] + r'\_(\d+\.\d+)n', re.S)
  728. Lt7 = list(set(pt.findall(data)))
  729. Lt7.sort(reverse = True)
  730. except Exception as e:
  731. pass
  732. #8號方位訊息
  733. res = requests.get('http://60.250.156.234/cust/c' + tid + '_8.txt')
  734. res.encoding = 'utf-8'
  735. data = res.text
  736. if "404 Not Found" not in data and data:
  737. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  738. try:
  739. #匹配出方位名稱
  740. pn = re.compile(r'\d+\-\d+\-\d+\_\d+\.\d+n\_([a-zA-Z\u4e00-\u9fa5]+)', re.S)
  741. L = pn.findall(data)[::-1]
  742. # 先轉成集合去重,在轉成列表做排序
  743. Ln8 = list(set(L))
  744. #讓排序不受到中文編碼影響,加入index
  745. Ln8.sort(key=L.index)
  746. #匹配出年份
  747. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  748. # 先轉成集合去重,在轉成列表做排序
  749. Ly8 = list(set(py.findall(data)))
  750. Ly8.sort(reverse = True)
  751. #匹配出月份
  752. pm = re.compile(Ly8[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  753. Lm8 = list(set(pm.findall(data)))
  754. Lm8.sort(reverse = True)
  755. #匹配出天數
  756. pd = re.compile(Ly8[0] + "-" + Lm8[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  757. Ld8 = list(set(pd.findall(data)))
  758. Ld8.sort(reverse = True)
  759. #匹配出時間
  760. pt = re.compile(Ly8[0] + "-" + Lm8[0] + "-" + Ld8[0] + r'\_(\d+\.\d+)n', re.S)
  761. Lt8 = list(set(pt.findall(data)))
  762. Lt8.sort(reverse = True)
  763. except Exception as e:
  764. pass
  765. if tid == '1':
  766. nr = 'GTW009002001'
  767. elif tid == '2':
  768. nr = 'GTW009002002'
  769. elif tid == '3':
  770. nr = 'GTW009002003'
  771. elif tid == '4':
  772. nr = 'GTW009002004'
  773. elif tid == '5':
  774. nr = 'GTW009002005'
  775. elif tid == '6':
  776. nr = 'GTW009002006'
  777. elif tid == '7':
  778. nr = 'GTW009002007'
  779. elif tid == '8':
  780. nr = 'GTW009002008'
  781. elif tid == '9':
  782. nr = 'GTW009002009'
  783. elif tid == '10':
  784. nr = 'GTW009002010'
  785. elif tid == "11":
  786. nr = 'GTW009002011'
  787. elif tid == '12':
  788. nr = 'GTW009002012'
  789. elif tid == '13':
  790. nr = 'GTW009002013'
  791. elif tid == '14':
  792. nr = 'GTW009002014'
  793. elif tid == '15':
  794. nr = 'GTW009002015'
  795. elif tid == '16':
  796. nr = 'GTW009002016'
  797. elif tid == '17':
  798. nr = 'GTW009002017'
  799. elif tid == '18':
  800. nr = 'GTW009002018'
  801. elif tid == '19':
  802. nr = 'GTW009002019'
  803. try:
  804. orientation = Orientation.query.filter_by(nr=nr).order_by(text('datetime desc')).first()
  805. mode = orientation.mode
  806. except Exception as e:
  807. pass
  808. try:
  809. # 可見光(自動拍照)路徑
  810. path = 'http://60.250.156.234/cust/' + tid + '/nj' + str(mode)
  811. res = requests.get(path).text
  812. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.jpg)"', re.S)
  813. img = p.findall(res)[-1]
  814. imgPath = path + '/' + img
  815. # ndvi路徑
  816. path = 'http://60.250.156.234/cust/' + tid + '/ndvia' + str(mode)
  817. res = requests.get(path).text
  818. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.png)"', re.S)
  819. img = p.findall(res)[-1]
  820. ndviImgPath = path + '/' + img
  821. timeList = img.split('_')
  822. year = timeList[0].split('-')[0]
  823. month = timeList[0].split('-')[1]
  824. day = timeList[0].split('-')[2]
  825. time = timeList[1].split('.')[0] + '.' + timeList[1].split('.')[1]
  826. except Exception as e:
  827. ndviImgPath = '../static/img/ndvi.jpg'
  828. imgPath = '../static/img/PV.jpg'
  829. return render_template('ahistory_ndvi1.html', params=locals())
  830. else:
  831. dict = request.form.to_dict()
  832. #小兵編號
  833. nr = dict['nr']
  834. #手動~方位8
  835. ori = dict['ori']
  836. #方位名稱
  837. name = dict['n']
  838. #年
  839. year = dict['y']
  840. #月
  841. month = dict['m']
  842. #日
  843. day = dict['d']
  844. #表單名稱
  845. evt = dict['evt']
  846. #判斷方位的值
  847. if ori == '0':
  848. res = requests.get('http://60.250.156.234/cust/c' + nr + '.txt')
  849. else:
  850. res = requests.get('http://60.250.156.234/cust/c' + nr + '_' + ori +'.txt')
  851. res.encoding = 'utf-8'
  852. data = res.text
  853. y = []
  854. m = []
  855. d = []
  856. t = []
  857. if evt[-1] == 'n':
  858. # 匹配出年
  859. if name == 'all':
  860. p = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  861. else:
  862. p = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n\_' + name, re.S)
  863. y = list(set(p.findall(data)))
  864. y.sort(reverse=True)
  865. # 匹配出月
  866. if name == 'all':
  867. p = re.compile(y[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  868. else:
  869. p = re.compile(y[0] + r'\-(\d+)\-\d+\_\d+\.\d+n\_' + name, re.S)
  870. # 先轉成集合去重,在轉成列表做排序
  871. m = list(set(p.findall(data)))
  872. m.sort(reverse=True)
  873. # 匹配出日
  874. if name == 'all':
  875. p = re.compile(y[0] + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  876. else:
  877. p = re.compile(y[0] + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n\_' + name, re.S)
  878. # 先轉成集合去重,在轉成列表做排序
  879. d = list(set(p.findall(data)))
  880. d.sort(reverse=True)
  881. # 匹配出時間
  882. if name == 'all':
  883. p = re.compile(y[0] + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  884. else:
  885. p = re.compile(y[0] + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n\_' + name, re.S)
  886. # 先轉成集合去重,在轉成列表做排序
  887. t = list(set(p.findall(data)))
  888. t.sort(reverse=True)
  889. D = {"y": y, "m": m, "d": d, "t": t}
  890. return json.dumps(D)
  891. elif evt[-1] == 'y':
  892. #匹配出月
  893. p = re.compile(year + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  894. # 先轉成集合去重,在轉成列表做排序
  895. m = list(set(p.findall(data)))
  896. m.sort(reverse=True)
  897. # 匹配出日
  898. p = re.compile(year + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  899. # 先轉成集合去重,在轉成列表做排序
  900. d = list(set(p.findall(data)))
  901. d.sort(reverse=True)
  902. # 匹配出時間
  903. p = re.compile(year + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  904. # 先轉成集合去重,在轉成列表做排序
  905. t = list(set(p.findall(data)))
  906. t.sort(reverse=True)
  907. D = {"m":m, "d":d, "t":t}
  908. return json.dumps(D)
  909. elif evt[-1] == 'm':
  910. #匹配出日
  911. p = re.compile(year + "-" + month + r'\-(\d+)\_\d+\.\d+n', re.S)
  912. d = list(set(p.findall(data)))
  913. d.sort(reverse=True)
  914. #匹配出時間
  915. p = re.compile(year + "-" + month + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  916. t = list(set(p.findall(data)))
  917. t.sort(reverse=True)
  918. D = {"d":d, "t":t}
  919. return json.dumps(D)
  920. elif evt[-1] == 'd':
  921. #匹配出時間
  922. p = re.compile(year + "-" + month + "-" + day + r'\_(\d+\.\d+)n', re.S)
  923. # 先轉成集合去重,在轉成列表做排序
  924. t = list(set(p.findall(data)))
  925. t.sort(reverse=True)
  926. D = {"t":t}
  927. return json.dumps(D)
  928. # 毛豆車拍攝設定的主頁面
  929. @main.route('/cshoot_setting/<tid>', methods=['POST', 'GET'])
  930. def cshoot_setting_views(tid):
  931. if request.method == 'GET':
  932. if 'id' not in session and 'uname' not in session:
  933. return redirect('/')
  934. if tid == '1':
  935. nr = 'GTW009001001'
  936. dic = '1m'
  937. elif tid == '2':
  938. nr = 'GTW009001002'
  939. dic = '2m'
  940. elif tid == '3':
  941. nr = 'GTW009001003'
  942. dic = '3m'
  943. #讓前端頁面顯示小兵現在的位置以及最新照片
  944. try:
  945. orientation = Orientation.query.filter_by(nr=nr).order_by(text('datetime desc')).first()
  946. mode = orientation.mode
  947. begin_tilt_angle = orientation.tilt_angle
  948. begin_pan_angle = orientation.pan_angle
  949. begin_zoom = orientation.zoom
  950. except Exception as e:
  951. pass
  952. try:
  953. # 可見光(自動拍照)路徑
  954. path = 'http://60.250.156.234/cust/' + dic + '/nj' + str(mode)
  955. res = requests.get(path).text
  956. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.jpg)"', re.S)
  957. img = p.findall(res)[-1]
  958. begin_imgPath = path + '/' + img
  959. except Exception as e:
  960. begin_imgPath = '../static/img/PV.jpg'
  961. #讓前端頁面顯示小兵已設定好哪些方位
  962. nr = "GTW00900100" + tid
  963. jvtotime = JvtOTime.query.filter_by(nr=nr).group_by('mode')
  964. mode = []
  965. for jvt in jvtotime:
  966. mode.append(jvt.mode)
  967. dict = request.args.to_dict()
  968. #刪除小兵設定的方位
  969. try:
  970. if dict['delete']:
  971. nr = "GTW00900100" + dict['nr']
  972. mode = int(dict['mode'])
  973. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  974. db.session.delete(jvtotime)
  975. db.session.commit()
  976. return {"delete":"ok"}
  977. except Exception:
  978. pass
  979. # 讓前端頁面顯示小兵已設定好的方位資訊
  980. if dict:
  981. try:
  982. nr = "GTW00900100" + dict['nr']
  983. mode = int(dict['mode'])
  984. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  985. name = jvtotime.name
  986. tilt_angle = jvtotime.tilt_angle
  987. pan_angle = jvtotime.pan_angle
  988. zoom = str(jvtotime.zoom)
  989. time1 = jvtotime.time1
  990. time2 = jvtotime.time2
  991. time3 = jvtotime.time3
  992. time4 = jvtotime.time4
  993. time5 = jvtotime.time5
  994. time6 = jvtotime.time6
  995. time7 = jvtotime.time7
  996. time8 = jvtotime.time8
  997. dict = {"name": name, "tilt_angle": tilt_angle, "pan_angle": pan_angle, "zoom": zoom, "time1": time1,
  998. "time2": time2, "time3": time3, "time4": time4, "time5": time5, "time6": time6,
  999. "time7": time7, "time8": time8}
  1000. return json.dumps(dict)
  1001. except Exception:
  1002. dict = {"name": "", "tilt_angle": "0", "pan_angle": "0", "zoom": "0", "time1": "00000000",
  1003. "time2": "00000000", "time3": "00000000", "time4": "00000000", "time5": "00000000",
  1004. "time6": "00000000", "time7": "00000000", "time8": "00000000"}
  1005. return json.dumps(dict)
  1006. return render_template('cim.html', params=locals())
  1007. else:
  1008. dict = request.form.to_dict()
  1009. nr = "GTW00900100" + dict['nr']
  1010. mode = int(dict['mode'])
  1011. jvtotime = JvtOTime.query.filter_by(nr=nr, mode=mode).first()
  1012. if not jvtotime:
  1013. jvtotime = JvtOTime()
  1014. jvtotimehistory = JvtOTimeHistory()
  1015. orientation = Orientation()
  1016. if dict['nr'] == '1':
  1017. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:b7:52:9c'
  1018. elif dict['nr'] == '2':
  1019. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:c1:72:0c'
  1020. elif dict['nr'] == '3':
  1021. jvtotime.mac = jvtotimehistory.mac = 'b8:27:eb:84:e9:3f'
  1022. jvtotime.nr = jvtotimehistory.nr = orientation.nr = 'GTW00900100' + dict['nr']
  1023. jvtotime.name = jvtotimehistory.name = dict['ori_name']
  1024. jvtotime.mode = jvtotimehistory.mode = orientation.mode = int(dict['mode'])
  1025. jvtotime.tilt_angle = jvtotimehistory.tilt_angle = orientation.tilt_angle = dict['tilt_angle']
  1026. jvtotime.pan_angle = jvtotimehistory.pan_angle = orientation.pan_angle = dict['pan_angle']
  1027. jvtotime.zoom = jvtotimehistory.zoom = orientation.zoom = int(dict['zoom'])
  1028. jvtotime.time1 = jvtotimehistory.time1 = dict['time1']
  1029. jvtotime.time2 = jvtotimehistory.time2 = dict['time2']
  1030. jvtotime.time3 = jvtotimehistory.time3 = dict['time3']
  1031. jvtotime.time4 = jvtotimehistory.time4 = dict['time4']
  1032. jvtotime.time5 = jvtotimehistory.time5 = dict['time5']
  1033. jvtotime.time6 = jvtotimehistory.time6 = dict['time6']
  1034. jvtotime.time7 = jvtotimehistory.time7 = dict['time7']
  1035. jvtotime.time8 = jvtotimehistory.time8 = dict['time8']
  1036. jvtotime.datetime = jvtotimehistory.datetime = orientation.datetime = dt.now()
  1037. db.session.add(jvtotime)
  1038. db.session.add(jvtotimehistory)
  1039. db.session.add(orientation)
  1040. db.session.commit()
  1041. return {"status": "OK"}
  1042. # 毛豆車歷史資料的主頁面
  1043. @main.route('/cimg_history/<tid>', methods=['POST', 'GET'])
  1044. def cimg_history_views(tid):
  1045. if request.method == 'GET':
  1046. if 'id' not in session and 'uname' not in session:
  1047. return redirect('/')
  1048. # 手動拍攝訊息
  1049. res = requests.get('http://60.250.156.234/cust/c' + tid + 'm.txt')
  1050. data = res.text
  1051. # 判斷是否沒有此文件且為空頁面
  1052. if "404 Not Found" not in data and data:
  1053. # 如果頁面是空的,在正則匹配就會報錯,所以加上try捕捉異常
  1054. try:
  1055. # 匹配出年份
  1056. py = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  1057. # 先轉成集合去重,在轉成列表做排序
  1058. Ly = list(set(py.findall(data)))
  1059. Ly.sort(reverse=True)
  1060. # 匹配出月份
  1061. pm = re.compile(Ly[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  1062. Lm = list(set(pm.findall(data)))
  1063. Lm.sort(reverse=True)
  1064. # 匹配出天數
  1065. pd = re.compile(Ly[0] + "-" + Lm[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  1066. Ld = list(set(pd.findall(data)))
  1067. Ld.sort(reverse=True)
  1068. # 匹配出時間
  1069. pt = re.compile(Ly[0] + "-" + Lm[0] + "-" + Ld[0] + r'\_(\d+\.\d+)n', re.S)
  1070. Lt = list(set(pt.findall(data)))
  1071. Lt.sort(reverse=True)
  1072. except Exception as e:
  1073. pass
  1074. if tid == '1':
  1075. nr = 'GTW009001001'
  1076. dic = '1m'
  1077. elif tid == '2':
  1078. nr = 'GTW009001002'
  1079. dic = '2m'
  1080. elif tid == '3':
  1081. nr = 'GTW009001003'
  1082. dic = '3m'
  1083. try:
  1084. orientation = Orientation.query.filter_by(nr=nr).order_by(text('datetime desc')).first()
  1085. mode = orientation.mode
  1086. except Exception:
  1087. pass
  1088. try:
  1089. # 可見光(自動拍照)路徑
  1090. path = 'http://60.250.156.234/cust/' + dic + '/nj' + str(mode)
  1091. res = requests.get(path).text
  1092. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.jpg)"', re.S)
  1093. img = p.findall(res)[-1]
  1094. imgPath = path + '/' + img
  1095. # ndvi路徑
  1096. path = 'http://60.250.156.234/cust/' + tid + '/ndvia' + str(mode)
  1097. res = requests.get(path).text
  1098. p = re.compile(r'<a href="(\d+\-\d+\-\d+\_\d+\.\d+\.png)"', re.S)
  1099. img = p.findall(res)[-1]
  1100. ndviImgPath = path + '/' + img
  1101. timeList = img.split('_')
  1102. year = timeList[0].split('-')[0]
  1103. month = timeList[0].split('-')[1]
  1104. day = timeList[0].split('-')[2]
  1105. time = timeList[1].split('.')[0] + '.' + timeList[1].split('.')[1]
  1106. except Exception as e:
  1107. ndviImgPath = '../static/img/ndvi.jpg'
  1108. imgPath = '../static/img/PV.jpg'
  1109. return render_template('chistory_ndvi1.html', params=locals())
  1110. else:
  1111. dict = request.form.to_dict()
  1112. # 小兵編號
  1113. nr = dict['nr']
  1114. # 手動~方位8
  1115. ori = dict['ori']
  1116. #方位名稱
  1117. name = dict['n']
  1118. # 年
  1119. year = dict['y']
  1120. # 月
  1121. month = dict['m']
  1122. # 日
  1123. day = dict['d']
  1124. # 表單名稱
  1125. evt = dict['evt']
  1126. # 判斷方位的值
  1127. if ori == '0':
  1128. res = requests.get('http://60.250.156.234/cust/c' + nr + 'm.txt')
  1129. else:
  1130. res = requests.get('http://60.250.156.234/cust/c' + nr + '_' + ori + '.txt')
  1131. data = res.text
  1132. y = []
  1133. m = []
  1134. d = []
  1135. t = []
  1136. if evt[-1] == 'n':
  1137. # 匹配出年
  1138. if name == 'all':
  1139. p = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n', re.S)
  1140. else:
  1141. p = re.compile(r'(\d+)\-\d+\-\d+\_\d+\.\d+n\_' + name, re.S)
  1142. y = list(set(p.findall(data)))
  1143. y.sort(reverse=True)
  1144. # 匹配出月
  1145. if name == 'all':
  1146. p = re.compile(y[0] + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  1147. else:
  1148. p = re.compile(y[0] + r'\-(\d+)\-\d+\_\d+\.\d+n\_' + name, re.S)
  1149. # 先轉成集合去重,在轉成列表做排序
  1150. m = list(set(p.findall(data)))
  1151. m.sort(reverse=True)
  1152. # 匹配出日
  1153. if name == 'all':
  1154. p = re.compile(y[0] + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  1155. else:
  1156. p = re.compile(y[0] + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n\_' + name, re.S)
  1157. # 先轉成集合去重,在轉成列表做排序
  1158. d = list(set(p.findall(data)))
  1159. d.sort(reverse=True)
  1160. # 匹配出時間
  1161. if name == 'all':
  1162. p = re.compile(y[0] + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  1163. else:
  1164. p = re.compile(y[0] + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n\_' + name, re.S)
  1165. # 先轉成集合去重,在轉成列表做排序
  1166. t = list(set(p.findall(data)))
  1167. t.sort(reverse=True)
  1168. D = {"y": y, "m": m, "d": d, "t": t}
  1169. return json.dumps(D)
  1170. elif evt[-1] == 'y':
  1171. # 匹配出月
  1172. p = re.compile(year + r'\-(\d+)\-\d+\_\d+\.\d+n', re.S)
  1173. # 先轉成集合去重,在轉成列表做排序
  1174. m = list(set(p.findall(data)))
  1175. m.sort(reverse=True)
  1176. # 匹配出日
  1177. p = re.compile(year + "-" + m[0] + r'\-(\d+)\_\d+\.\d+n', re.S)
  1178. # 先轉成集合去重,在轉成列表做排序
  1179. d = list(set(p.findall(data)))
  1180. d.sort(reverse=True)
  1181. # 匹配出時間
  1182. p = re.compile(year + "-" + m[0] + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  1183. # 先轉成集合去重,在轉成列表做排序
  1184. t = list(set(p.findall(data)))
  1185. t.sort(reverse=True)
  1186. D = {"m": m, "d": d, "t": t}
  1187. return json.dumps(D)
  1188. elif evt[-1] == 'm':
  1189. # 匹配出日
  1190. p = re.compile(year + "-" + month + r'\-(\d+)\_\d+\.\d+n', re.S)
  1191. d = list(set(p.findall(data)))
  1192. d.sort(reverse=True)
  1193. # 匹配出時間
  1194. p = re.compile(year + "-" + month + "-" + d[0] + r'\_(\d+\.\d+)n', re.S)
  1195. t = list(set(p.findall(data)))
  1196. t.sort(reverse=True)
  1197. D = {"d": d, "t": t}
  1198. return json.dumps(D)
  1199. elif evt[-1] == 'd':
  1200. # 匹配出時間
  1201. p = re.compile(year + "-" + month + "-" + day + r'\_(\d+\.\d+)n', re.S)
  1202. # 先轉成集合去重,在轉成列表做排序
  1203. t = list(set(p.findall(data)))
  1204. t.sort(reverse=True)
  1205. D = {"t": t}
  1206. return json.dumps(D)
  1207. # 退出的訪問路徑
  1208. @main.route('/logout')
  1209. def logout_views():
  1210. if 'id' in session and 'uname' in session:
  1211. del session['id']
  1212. del session['uname']
  1213. return redirect('/')
  1214. # 影像串流的路徑
  1215. @main.route("/video_feed", methods=['POST', 'GET'])
  1216. def video_feed_views():
  1217. global s_sock
  1218. if request.method == 'GET':
  1219. #於10分鐘之後,自動關閉socket server
  1220. if s_sock == 0:
  1221. def socket_server_views():
  1222. global s_sock
  1223. # print("test")
  1224. # print(s_sock)
  1225. sl(600)
  1226. if s_sock != 0:
  1227. s_sock.close()
  1228. s_sock = 0
  1229. # print('s_sock is closed')
  1230. pool.submit(socket_server_views)
  1231. host = "60.250.156.230"
  1232. port = 8000
  1233. max_length = 65540
  1234. # max_length = 95540
  1235. s_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  1236. s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1237. s_sock.bind((host, port))
  1238. frame_info = None
  1239. buffer = None
  1240. frame = None
  1241. encodedImage = None
  1242. print("-> waiting for connection")
  1243. # 影像生成器函數,將影像以jpg格式傳給前端
  1244. def generate():
  1245. while True:
  1246. with lock:
  1247. global s_sock, frame_info, buffer, frame, encodedImage
  1248. if s_sock == 0:
  1249. break
  1250. data, address = s_sock.recvfrom(max_length)
  1251. if len(data) < 100:
  1252. frame_info = pickle.loads(data)
  1253. if frame_info:
  1254. nums_of_packs = frame_info["packs"]
  1255. for i in range(nums_of_packs):
  1256. if s_sock == 0:
  1257. break
  1258. data, address = s_sock.recvfrom(max_length)
  1259. if i == 0:
  1260. buffer = data
  1261. else:
  1262. buffer += data
  1263. frame = np.frombuffer(buffer, dtype=np.uint8)
  1264. frame = frame.reshape(frame.shape[0], 1)
  1265. frame = cv2.imdecode(frame, cv2.IMREAD_UNCHANGED)
  1266. #如果frame為None就跳過
  1267. if frame is None:
  1268. continue
  1269. frame = cv2.resize(frame, (640, 360), interpolation=cv2.INTER_AREA)
  1270. # encode the frame in JPEG format
  1271. (flag, encodedImage) = cv2.imencode(".jpg", frame)
  1272. # ensure the frame was successfully encoded
  1273. if not flag:
  1274. continue
  1275. # yield the output frame in the byte format
  1276. yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
  1277. bytearray(encodedImage) + b'\r\n')
  1278. # return the response generated along with the specific media
  1279. # type (mime type)
  1280. return Response(generate(), mimetype="multipart/x-mixed-replace; boundary=frame")
  1281. else:
  1282. if s_sock != 0:
  1283. s_sock.close()
  1284. s_sock = 0
  1285. # print('s_sock is closed')
  1286. return "s_sock is closed"
  1287. # print("test")
  1288. return "s_sock is closed"
  1289. #控制循環退出的開關
  1290. D = {'GTW009001001':0, 'GTW009001002':0, 'GTW009001003':0, 'GTW009002001':0, 'GTW009002002':0, 'GTW009002003':0, 'GTW009002004':0,
  1291. 'GTW009002005':0, 'GTW009002006':0, 'GTW009002007':0, 'GTW009002008':0, 'GTW009002009':0, 'GTW009002010':0, 'GTW009002011':0,
  1292. 'GTW009002012':0, 'GTW009002013':0, 'GTW009002014':0, 'GTW009002015':0, 'GTW009002016':0, 'GTW009002017':0, 'GTW009002018':0, 'GTW009002019':0}
  1293. #判斷小兵接收回傳訊息是否為這隻程式,還是另一個edamame_brake.py排程程式
  1294. d = {'GTW009001001_n':0, 'GTW009001002_n':0, 'GTW009001003_n':0, 'GTW009002001_n':0, 'GTW009002002_n':0, 'GTW009002003_n':0, 'GTW009002004_n':0,
  1295. 'GTW009002005_n':0, 'GTW009002006_n':0, 'GTW009002007_n':0, 'GTW009002008_n':0, 'GTW009002009_n':0, 'GTW009002010_n':0, 'GTW009002011_n':0,
  1296. 'GTW009002012_n':0, 'GTW009002013_n':0, 'GTW009002014_n':0, 'GTW009002015_n':0, 'GTW009002016_n':0, 'GTW009002017_n':0, 'GTW009002018_n':0, 'GTW009002019_n':0}
  1297. #mqtt發布
  1298. @main.route('/mqtt/<node_id>', methods=['GET','POST'])
  1299. def mqtt_views(node_id):
  1300. import json
  1301. dict = request.args.to_dict()
  1302. json = json.dumps(dict)
  1303. #判斷毛豆車和毛豆田的node_id
  1304. if node_id == 'GTW009001001':
  1305. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:b7:52:9c'
  1306. elif node_id == 'GTW009001002':
  1307. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:c1:72:0c'
  1308. elif node_id == 'GTW009001003':
  1309. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:84:e9:3f'
  1310. elif node_id == 'GTW009002001':
  1311. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:95:00:53'
  1312. elif node_id == 'GTW009002002':
  1313. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:e7:51:44'
  1314. elif node_id == 'GTW009002003':
  1315. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:ce:a5:35'
  1316. elif node_id == 'GTW009002004':
  1317. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:fc:9d:34'
  1318. elif node_id == 'GTW009002005':
  1319. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:86:00:c9'
  1320. elif node_id == 'GTW009002006':
  1321. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:df:4b:0f'
  1322. elif node_id == 'GTW009002007':
  1323. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:6a:5d:17'
  1324. elif node_id == 'GTW009002008':
  1325. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:d2:d0:8f'
  1326. elif node_id == 'GTW009002009':
  1327. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:57:3c:da'
  1328. elif node_id == 'GTW009002010':
  1329. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:bd:29:b1'
  1330. elif node_id == 'GTW009002011':
  1331. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:7c:f6:06'
  1332. elif node_id == 'GTW009002012':
  1333. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:59:9d:bd'
  1334. elif node_id == 'GTW009002013':
  1335. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:e7:21:e5'
  1336. elif node_id == 'GTW009002014':
  1337. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:34:9e:39'
  1338. elif node_id == 'GTW009002015':
  1339. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:e3:f1:f4'
  1340. elif node_id == 'GTW009002016':
  1341. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:f8:24:92'
  1342. elif node_id == 'GTW009002017':
  1343. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:9d:68:05'
  1344. elif node_id == 'GTW009002018':
  1345. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:4d:e4:34'
  1346. elif node_id == 'GTW009002019':
  1347. topic = 'AISKY/AppleFarm/MK-G/b8:27:eb:e7:16:28'
  1348. #假設MQTT命令為開啟影像串流,在3分鐘後自動發布關閉該影像串流
  1349. # if dict['command'] == 'a053':
  1350. # def close_video_views():
  1351. # import json
  1352. # sl(180)
  1353. # dict['command'] = 'a054'
  1354. # json = json.dumps(dict)
  1355. # print(json)
  1356. # mqtt.publish(topic, json)
  1357. # print('close video test')
  1358. #
  1359. # pool.submit(close_video_views)
  1360. num = node_id +'_n'
  1361. mqtt.publish(topic, json)
  1362. d[num] = 1
  1363. if dict['command'] != 'a053':
  1364. if node_id != "GTW009002019":
  1365. if dict['command'] == 'a051':
  1366. sl(600)
  1367. elif dict['command'] == 'a018' or dict['command'] == 'a016' or dict['command'] == 'a052':
  1368. sl(40)
  1369. else:
  1370. sl(10)
  1371. if D[node_id] == 0:
  1372. mqtt.publish(topic, json)
  1373. if dict['command'] == 'a051':
  1374. sl(600)
  1375. elif dict['command'] == 'a018' or dict['command'] == 'a016' or dict['command'] == 'a052':
  1376. sl(40)
  1377. else:
  1378. sl(10)
  1379. if D[node_id] == 0:
  1380. mqtt.publish(topic, json)
  1381. if dict['command'] == 'a051':
  1382. sl(600)
  1383. elif dict['command'] == 'a018' or dict['command'] == 'a016' or dict['command'] == 'a052':
  1384. sl(40)
  1385. else:
  1386. sl(10)
  1387. if D[node_id] == 0:
  1388. status = Status()
  1389. status.nr = node_id
  1390. status.status = 'fail'
  1391. status.datetime = dt.now()
  1392. db.session.add(status)
  1393. db.session.commit()
  1394. d[num] = 0
  1395. D[node_id] = 0
  1396. return "Publish done"
  1397. #處理mqtt訂閱的信息
  1398. @mqtt.on_message()
  1399. def handle_mqtt_message(client, userdata, message):
  1400. payload = message.payload.decode()
  1401. print(payload)
  1402. if payload:
  1403. p = json.loads(payload)
  1404. if d[p['node_id'] +'_n'] == 1:
  1405. if 'filename' in p:
  1406. img = ImageSignalLog()
  1407. img.nr = p['node_id']
  1408. img.command = p['command']
  1409. img.datetime = dt.now()
  1410. img.response = p['rqnn']
  1411. img.position = p['position']
  1412. img.time = p['time']
  1413. img.size_a = p['a']
  1414. img.size_b = p['b']
  1415. img.filename = p['filename']
  1416. db.session.add(img)
  1417. else:
  1418. sig = SignalLog()
  1419. sig.nr = p['node_id']
  1420. sig.command = p['command']
  1421. sig.datetime = dt.now()
  1422. sig.response = p['rqnn']
  1423. if 'tilt' in p:
  1424. sig.tilt_angle = p['tilt']
  1425. if 'pan' in p:
  1426. sig.pan_angle = p['pan']
  1427. if 'zoom' in p:
  1428. sig.zoom = p['zoom']
  1429. if 'position' in p:
  1430. sig.position = p['position']
  1431. db.session.add(sig)
  1432. db.session.commit()
  1433. D[p['node_id']] = 1
  1434. d[p['node_id'] +'_n'] = 0
  1435. # print("-------msg-------")
  1436. # print('name :', p['name'])
  1437. # print('email :', p['email'])