miacheng913 пре 3 година
родитељ
комит
230f3082f8
1 измењених фајлова са 38 додато и 5 уклоњено
  1. 38 5
      main.py

+ 38 - 5
main.py

@@ -26,7 +26,6 @@ from random import randint,uniform
 # authorize
 from passlib.context import CryptContext
 pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
-
 import jwt
 from fastapi_jwt_auth import AuthJWT
 from fastapi_jwt_auth.exceptions import AuthJWTException
@@ -272,6 +271,15 @@ async def vibration(request: Request, Authorize: AuthJWT = Depends()):
         return RedirectResponse('/login')
     return templates.TemplateResponse(name='vibration_test.html', context={'request': request})
 
+@app.get('/channel', response_class=HTMLResponse)
+async def vibration(request: Request, Authorize: AuthJWT = Depends()):
+    try:
+        Authorize.jwt_required()
+    except Exception as e:
+        print(e)
+        return RedirectResponse('/login')
+    return templates.TemplateResponse(name='channel.html', context={'request': request})
+
 @app.get('/channel/{tower_id}/{channel_id}', response_class=HTMLResponse)
 async def vibration(request: Request,tower_id:str,channel_id:str,Authorize: AuthJWT = Depends()):
     try:
@@ -308,6 +316,18 @@ async def vibration(request: Request,tower_id:str,channel_id:str,Authorize: Auth
     result = get_predect_data(find_vibration_id(tower_id,channel_id))
     return json.dumps(result,ensure_ascii=False, cls = dateEncode)
 
+@app.get('/channel_frequency/{tower_id}/{channel_id}', response_class=HTMLResponse)
+async def vibration(request: Request,tower_id:str,channel_id:str,Authorize: AuthJWT = Depends()):
+    try:
+        Authorize.jwt_required()
+    except Exception as e:
+        print(e)
+        return RedirectResponse('/login')
+    
+    #print(find_vibration_id(tower_id,channel_id))
+    result = get_frequency(find_vibration_id(tower_id,channel_id))
+    return json.dumps(result,ensure_ascii=False, cls = dateEncode)
+
 
 @app.get('/history', response_class=HTMLResponse)
 async def history(request: Request, Authorize: AuthJWT = Depends()):
@@ -967,14 +987,14 @@ def find_vibration_id(tower_id:str,channel_id:str):
 def get_channel_info(vibration_id):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
     cmd = 'SELECT * FROM  `record_diagnosis` where vibration_id = "'+vibration_id+'"'
-    result = {'CVIndex':'','threshold':''}
+    result = {}
     for row in db.query(cmd) :
         for col in db['record_diagnosis'].columns :
                 result[col] = row[col]
         cmd2='SELECT CVIndex,threshold FROM  `vibration` where id = "'+vibration_id+'"'
         for row2 in db.query(cmd2) :
-            result['CVIndex'] = row['CVIndex']
-            result['threshold'] = row['threshold']
+            result['CVIndex'] = row2['CVIndex']
+            result['threshold'] = row2['threshold']
     print(result)
     return result
 
@@ -1000,6 +1020,14 @@ def get_predect_data(vibration_id:str):
 
     return result
 
+def get_frequency(vibration_id:str):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
+    result = {'Hz':[],'value':[]}
+    cmd = 'SELECT * FROM record_frequency where vibration_id = "'+vibration_id+'"'
+    for row in db.query(cmd) :
+        result['Hz'].append(row['MFHz'])
+        result['value'].append(row['MFValue'])
+
 
 def add_data():
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/Water_tower?charset=utf8mb4')
@@ -1011,4 +1039,9 @@ def add_data():
         for i in range(0,7):
             time_del = timedelta(days=i)
             date=loc_dt-time_del
-            db['record_health'].insert(dict(time_stamp=date, CV_index=uniform(0.6, 0.8), Vrms=uniform(1,3),Grms = uniform(1,3),RPM=uniform(1,3),vibration_id = j))
+            db['record_health'].insert(dict(time_stamp=date, CV_index=uniform(0.6, 0.8), Vrms=uniform(1,3),Grms = uniform(1,3),RPM=uniform(1,3),vibration_id = j))
+
+    cmd = "TRUNCATE TABLE record_frequency"
+    db.query(cmd)
+    for i in range(0,5000):
+        db['record_frequency'].insert(dict(time_stamp=loc_dt_format, MFHz=j, MFValue=uniform(0,0.12),vibration_id = 1))