|
@@ -143,6 +143,54 @@ async def register(request: Request, form_data: OAuth2PasswordRequestForm = Depe
|
|
|
# 跳轉頁面至登入
|
|
|
return templates.TemplateResponse(name='login.html', context={'request': request})
|
|
|
|
|
|
+@app.get('/tower_add_data', response_class=HTMLResponse)
|
|
|
+async def login(request: Request):
|
|
|
+ return templates.TemplateResponse(name='tower_post.html', context={'request': request})
|
|
|
+
|
|
|
+@app.post('/tower_addData')
|
|
|
+async def register(request: Request,data : models.tower_data,key:str):
|
|
|
+ #data = models.tower_data(**await request.form())
|
|
|
+ if key!="21232f297a57a5a743894a0e4a801fc3":
|
|
|
+ return {'msg':'no access'}
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
|
|
|
+ cmd ="SELECT * FROM device"
|
|
|
+ cmd2={}
|
|
|
+ check = 0
|
|
|
+ for row in db.query(cmd):
|
|
|
+ if row['id']== data.device:
|
|
|
+ check = 1
|
|
|
+ if check :
|
|
|
+ for row in ['hotTemp','waterFlow','coldTemp','fanMotorCur','fanMotorSpeedFreq']:
|
|
|
+ cmd = "cmd2['cmd'] = \"UPDATE `record_dcs` SET `value` = \"+str(data.DCS_{}) +\" WHERE `device_id` = '\"+data.device+\"' AND `key` = '{}'\"".format(row,row)
|
|
|
+ exec(cmd)
|
|
|
+ print(cmd2['cmd'])
|
|
|
+ db.query(cmd2['cmd'])
|
|
|
+ for row in ['reducer','waterFlow','wetTemp','coldTempData1','coldTempData2','staticPressure']:
|
|
|
+ exec("cmd2['cmd'] = \"UPDATE `record_tower` SET `value` = \"+str(data.{}) +\" WHERE `device_id` = '\"+data.device+\"' AND `key` = '{}'\"".format(row,row))
|
|
|
+ print(cmd2)
|
|
|
+ db.query(cmd2['cmd'])
|
|
|
+ for row in ['ch01','ch02','ch03','ch04']:
|
|
|
+ exec("cmd2['cmd'] = \"UPDATE `vibration` SET `DataValue` = \"+str(data.DataValue_{})+\",`CVIndex` = \"+str(data.CVIndex_{}) +\" WHERE `device_id` = '\"+data.device+\"' AND `channelName` = '{}'\"".format(row,row,row))
|
|
|
+ print(cmd2)
|
|
|
+ db.query(cmd2['cmd'])
|
|
|
+ #exec("db['vibration'].update(dict(channelName={},device_id=data.device,DataValue=data.DataValue_{},CVIndex=data.CVIndex_{}),['channelName'],['device_id'])".format(row,row))
|
|
|
+
|
|
|
+ result={'msg':"success"}
|
|
|
+ else:
|
|
|
+ result = {'msg':"no device"}
|
|
|
+
|
|
|
+ return json.dumps(result,ensure_ascii=False)
|
|
|
+
|
|
|
+@app.get('/add_tower')
|
|
|
+async def home(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
+ return templates.TemplateResponse(name='add_tower.html', context={'request': request})
|
|
|
+
|
|
|
+@app.post('/add_tower')
|
|
|
+async def home(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
+ data=request.form()
|
|
|
+ print(data.device)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@app.get('/home', response_class=HTMLResponse)
|
|
|
async def home(request: Request, Authorize: AuthJWT = Depends()):
|
|
@@ -178,6 +226,18 @@ async def tower(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
result = get_user_under_organization(current_user)
|
|
|
return json.dumps(result,ensure_ascii=False)
|
|
|
|
|
|
+@app.get('/user_role', response_class=HTMLResponse)
|
|
|
+async def user_role(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
+ try:
|
|
|
+ Authorize.jwt_required()
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return RedirectResponse('/login')
|
|
|
+ current_user = Authorize.get_jwt_subject()
|
|
|
+ result = {'role':check_role_type(current_user)}
|
|
|
+ print(result)
|
|
|
+ return json.dumps(result,ensure_ascii=False)
|
|
|
+
|
|
|
|
|
|
@app.get('/tower', response_class=HTMLResponse)
|
|
|
async def tower(request: Request, Authorize: AuthJWT = Depends()):
|
|
@@ -227,7 +287,7 @@ async def member_authority(request:Request,tower_id: str,Authorize: AuthJWT = De
|
|
|
return RedirectResponse('/login')
|
|
|
|
|
|
result = get_tower_perform(tower_id)
|
|
|
- print(result)
|
|
|
+ #print(result)
|
|
|
return json.dumps(result,ensure_ascii=False, cls = dateEncode)
|
|
|
|
|
|
|
|
@@ -1092,8 +1152,11 @@ def check_tower_health(user_name:str):
|
|
|
cmd = 'SELECT CVIndex,threshold FROM `vibration` where device_id = "'+tower+'"'
|
|
|
health =1
|
|
|
for row in db.query(cmd) :
|
|
|
- if int(row['CVIndex']) < int(row['threshold']):
|
|
|
+ print(row['CVIndex'],row['threshold'])
|
|
|
+ if row['CVIndex'] < int(row['threshold']):
|
|
|
health = 0
|
|
|
+ print("heheh")
|
|
|
+ print(health)
|
|
|
result.append({'company':dic['company'], 'factory':dic['factory'], 'department':dic['department'], 'group': group, 'tower': tower, 'health': health})
|
|
|
return result
|
|
|
|
|
@@ -1164,6 +1227,21 @@ def add_data():
|
|
|
|
|
|
cmd = "TRUNCATE TABLE record_frequency"
|
|
|
db.query(cmd)
|
|
|
- for i in range(0,5000):
|
|
|
+ for i in range(0,1000):
|
|
|
+ print(i)
|
|
|
+ db['record_frequency'].insert(dict(time_stamp=loc_dt_format, MFHz=i, MFValue=uniform(0,0.12),vibration_id = 1))
|
|
|
+
|
|
|
+ cmd = "TRUNCATE TABLE record_frequency"
|
|
|
+ db.query(cmd)
|
|
|
+ for i in range(0,1000):
|
|
|
print(i)
|
|
|
- db['record_frequency'].insert(dict(time_stamp=loc_dt_format, MFHz=i, MFValue=uniform(0,0.12),vibration_id = 1))
|
|
|
+ db['record_frequency'].insert(dict(time_stamp=loc_dt_format, MFHz=i, MFValue=uniform(0,0.12),vibration_id = 1))
|
|
|
+
|
|
|
+def add_tower():
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
|
|
|
+
|
|
|
+ loc_dt = datetime.today()
|
|
|
+ loc_dt_format = loc_dt.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ for device in ['dev005','dev006','dev007','dev008','dev009']:
|
|
|
+ for key in ['hotTemp','waterFlow','coldTemp','fanMotorCur','fanMotorSpeedFreq']:
|
|
|
+ db['record_dcs'].insert(dict(time_stamp=loc_dt_format, MFValue=uniform(0,0.12),vibration_id = 1))
|