|
@@ -600,9 +600,26 @@ async def history(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
# current_user = Authorize.get_jwt_subject()
|
|
|
return templates.TemplateResponse(name='history.html', context={'request': request})
|
|
|
|
|
|
+@app.get('/history/', response_class=HTMLResponse)
|
|
|
+async def history(request: Request,company:str,factory:str,department:str,towerGroup:str, Authorize: AuthJWT = Depends()):
|
|
|
+ try:
|
|
|
+ Authorize.jwt_required()
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return RedirectResponse('/login')
|
|
|
+ #current_user = Authorize.get_jwt_subject()
|
|
|
+ tower_arr = get_tower(company,factory,department,towerGroup)
|
|
|
+ result = []
|
|
|
+ for tower in tower_arr:
|
|
|
+ tmp_arr = get_vibration_info(tower)
|
|
|
+ for arr in tmp_arr:
|
|
|
+ result.append(arr)
|
|
|
+
|
|
|
+ return json.dumps(result,ensure_ascii=False, cls = dateEncode)
|
|
|
|
|
|
@app.get('/device', response_class=HTMLResponse)
|
|
|
async def device(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
+
|
|
|
try:
|
|
|
Authorize.jwt_required()
|
|
|
except Exception as e:
|
|
@@ -614,16 +631,13 @@ async def device(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
print("start")
|
|
|
for row in db.query(statement):
|
|
|
print(row['id'],row['deviceName'],row['hostIP'],row['CompanyCode'],row['FactoryCode'],row['DepartmentCode'])
|
|
|
- a.append({row['id'],row['deviceName'],row['hostIP']})
|
|
|
- a.append({row['CompanyCode'],row['FactoryCode'],row['DepartmentCode']})
|
|
|
+ a.append((row['id'],row['deviceName'],row['hostIP'],row['CompanyCode'],row['FactoryCode'],row['DepartmentCode']))
|
|
|
print(a)
|
|
|
print("over3")
|
|
|
#result = json.dumps(b,ensure_ascii=False)
|
|
|
# current_user = Authorize.get_jwt_subject()
|
|
|
return templates.TemplateResponse(name='device.html', context={'request': request,'a':a})
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@app.get('/system', response_class=HTMLResponse)
|
|
|
async def system(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
try:
|
|
@@ -1306,6 +1320,20 @@ def get_frequency(vibration_id:str):
|
|
|
result['value'].append(row['MFValue'])
|
|
|
return result
|
|
|
|
|
|
+def get_vibration_info(deviceCode:str):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
|
|
|
+ cmd = 'SELECT * FROM vibration where device_id = "'+deviceCode+'"'
|
|
|
+
|
|
|
+ tmp = []
|
|
|
+ for row in db.query(cmd) :
|
|
|
+ result = {}
|
|
|
+ for col in db['vibration'].columns :
|
|
|
+ result[col] = row[col]
|
|
|
+ #print(result)
|
|
|
+ tmp.append(result)
|
|
|
+ #print(tmp)
|
|
|
+ return tmp
|
|
|
+
|
|
|
|
|
|
def add_data():
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
|
|
@@ -1338,4 +1366,6 @@ def add_tower():
|
|
|
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))
|
|
|
+ db['record_dcs'].insert(dict(time_stamp=loc_dt_format, MFValue=uniform(0,0.12),vibration_id = 1))
|
|
|
+
|
|
|
+
|