|
@@ -5,8 +5,8 @@ import pandas as pd
|
|
|
from fastapi import FastAPI, HTTPException
|
|
|
from fastapi.responses import JSONResponse
|
|
|
from pydantic import BaseModel, model_validator
|
|
|
-from typing import List
|
|
|
-
|
|
|
+from typing import List,Dict
|
|
|
+from sqlalchemy import create_engine, text
|
|
|
from Temp_Diag import MSET_Temp
|
|
|
|
|
|
app = FastAPI(root_path="/api/diag",title="Temperature Diagnosis API")
|
|
@@ -39,6 +39,12 @@ class TemperatureThresholdInput(TemperatureInput):
|
|
|
pageNo: int
|
|
|
pageSize: int
|
|
|
|
|
|
+class TemperatureDataQueryInput(BaseModel):
|
|
|
+ windCode: str
|
|
|
+ windTurbineNumber: str
|
|
|
+ timestamp: str
|
|
|
+
|
|
|
+
|
|
|
@app.on_event("startup")
|
|
|
def load_all_models():
|
|
|
for f in glob.glob("models/*/*/*.pkl"):
|
|
@@ -197,6 +203,55 @@ async def route_trend(inp: TemperatureInput):
|
|
|
"message": "success"
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+@app.post("/temperature/dataquery")
|
|
|
+async def query_data(inp: TemperatureDataQueryInput):
|
|
|
+ """
|
|
|
+ 查询指定风机在特定时间点前后各50个时间点的数据
|
|
|
+ 输入:
|
|
|
+ {
|
|
|
+ "windCode": "WOF091200030",
|
|
|
+ "windTurbineNumber": "WOG01355",
|
|
|
+ "timestamp": "2024-06-01 00:00:00"
|
|
|
+ }
|
|
|
+ 输出:
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "wind_turbine_number": "WOG01355",
|
|
|
+ "record_count": 101,
|
|
|
+ "records": [
|
|
|
+ {"时间戳": "2024-05-31 23:10:00", "主轴承温度": 65.2, ...},
|
|
|
+ {"时间戳": "2024-05-31 23:15:00", "主轴承温度": 65.5, ...},
|
|
|
+ ...
|
|
|
+ {"时间戳": "2024-06-01 00:50:00", "主轴承温度": 66.1, ...}
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "code": 200,
|
|
|
+ "message": "success"
|
|
|
+ }
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ analyzer = MSET_Temp(inp.windCode, [inp.windTurbineNumber], "", "")
|
|
|
+ result = analyzer.query_surrounding_data(inp.timestamp,minutes_around = 250)
|
|
|
+ if result['record_count'] == 0:
|
|
|
+ return JSONResponse(
|
|
|
+ content={"code": 405, "message": "未找到数据"},
|
|
|
+ status_code=200
|
|
|
+ )
|
|
|
+
|
|
|
+ return {
|
|
|
+ "data": {
|
|
|
+ "wind_turbine_number": inp.windTurbineNumber,
|
|
|
+ "records": result['records']
|
|
|
+ },
|
|
|
+ "code": 200,
|
|
|
+ "message": "success"
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
import uvicorn
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|