|
@@ -7,6 +7,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
from pydantic import BaseModel
|
|
|
+
|
|
|
# fastapi view function parameters
|
|
|
from typing import List, Optional
|
|
|
import json
|
|
@@ -155,7 +156,6 @@ async def register(item: P_Multiple):
|
|
|
|
|
|
return "OK"
|
|
|
|
|
|
-
|
|
|
@app.post('/register')
|
|
|
async def register(request: Request, form_data: OAuth2PasswordRequestForm = Depends()):
|
|
|
user = models.User(**await request.form())
|
|
@@ -365,8 +365,6 @@ async def tower(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
print(e)
|
|
|
return RedirectResponse('/login')
|
|
|
current_user = Authorize.get_jwt_subject()
|
|
|
- result = get_user_under_organization(current_user)
|
|
|
- result.append({'Data' : get_tower_info('dev001')})
|
|
|
return templates.TemplateResponse(name='tower.html', context={"request":request})
|
|
|
|
|
|
@app.get('/tower/org', response_class=HTMLResponse)
|
|
@@ -1236,13 +1234,54 @@ def get_tower_info(tower_id:str):
|
|
|
"""獲取水塔資料"""
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
|
|
|
cmd = 'SELECT * FROM `record_dcs` where device_id = "'+tower_id+'"'
|
|
|
+
|
|
|
+ days=0
|
|
|
+ dateFormatter = "%Y-%B-%d %H:%M:%S"
|
|
|
+ loc_dt = datetime.today()
|
|
|
+
|
|
|
result ={'DCS':{},'Fan':{},'Moter':{},'Device_info':{}}
|
|
|
for row in db.query(cmd) :
|
|
|
- result['DCS'][row['key']]=row['value']
|
|
|
+ dateString=row['time_stamp']
|
|
|
+ if days==0:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['DCS'][row['key']]=row['value']
|
|
|
+ elif row['key'] in result['DCS'].keys():
|
|
|
+ #days= (loc_dt-dateString).days
|
|
|
+ result['DCS'][row['key']]=row['value']
|
|
|
+ elif (loc_dt-dateString).days < days:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['DCS'][row['key']]=row['value']
|
|
|
+ elif (loc_dt-dateString).days == days:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['DCS'][row['key']]=row['value']
|
|
|
+ if result['DCS']=={}:
|
|
|
+ result['DCS']['hotTemp']=32.00
|
|
|
+ result['DCS']['coldTemp']=32.00
|
|
|
+ result['DCS']['waterFlow']=32.00
|
|
|
+ result['DCS']['fanMotorCur']=32.00
|
|
|
+ result['DCS']['fanMotorSpeedFreq']=32.00
|
|
|
+
|
|
|
+ days=0
|
|
|
|
|
|
cmd = 'SELECT * FROM `record_tower` where device_id = "'+tower_id+'"'
|
|
|
for row in db.query(cmd) :
|
|
|
- result['Fan'][row['key']]=row['value']
|
|
|
+ dateString=row['Createtime']
|
|
|
+ if dateString == None:
|
|
|
+ dateString=row['time_stamp']
|
|
|
+ if isinstance(dateString, datetime)==False:
|
|
|
+ dateFormatter = "%Y-%m-%d %H:%M:%S.%f"
|
|
|
+ dateString = datetime.strptime(dateString, dateFormatter)
|
|
|
+ if days==0:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['Fan'][row['key']]=row['value']
|
|
|
+ elif row['key'] in result['DCS'].keys():
|
|
|
+ result['Fan'][row['key']]=row['value']
|
|
|
+ elif (loc_dt-dateString).days < days:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['Fan'][row['key']]=row['value']
|
|
|
+ elif (loc_dt-dateString).days == days:
|
|
|
+ days= (loc_dt-dateString).days
|
|
|
+ result['Fan'][row['key']]=row['value']
|
|
|
|
|
|
result['Moter'] = []
|
|
|
cmd = 'SELECT * FROM `vibration` where device_id = "'+tower_id+'"'
|
|
@@ -1252,6 +1291,11 @@ def get_tower_info(tower_id:str):
|
|
|
tmp[col] = row[col]
|
|
|
result['Moter'].append(tmp)
|
|
|
tmp = {}
|
|
|
+ if result['Moter']== []:
|
|
|
+ result['Moter'].append({'DataValue':213,'CVindex':222})
|
|
|
+ result['Moter'].append({'DataValue':213,'CVindex':222})
|
|
|
+ result['Moter'].append({'DataValue':213,'CVindex':222})
|
|
|
+ result['Moter'].append({'DataValue':213,'CVindex':222})
|
|
|
|
|
|
cmd = 'SELECT * FROM `device` where id = "'+tower_id+'"'
|
|
|
for row in db.query(cmd):
|