statistics

This commit is contained in:
xyj 2024-02-20 11:24:59 +08:00
parent 4ba135f885
commit 2a3d01f56b
1 changed files with 26 additions and 1 deletions

27
xumu.py
View File

@ -24,6 +24,7 @@ class BaseResponse(BaseModel):
async def video_query(username): async def video_query(username):
return BaseResponse(data=get_video_url(username)) return BaseResponse(data=get_video_url(username))
# 报警数据接口 # 报警数据接口
@app.get("/api/xumu/warning") @app.get("/api/xumu/warning")
async def get_warning(deviceId): async def get_warning(deviceId):
@ -228,6 +229,7 @@ async def register(request: Request):
except Exception as e: except Exception as e:
return BaseResponse(code=500, msg=str(e)) return BaseResponse(code=500, msg=str(e))
# 数据发布接口 # 数据发布接口
async def message_publish(data): async def message_publish(data):
try: try:
@ -328,7 +330,7 @@ async def process_data(request: Request):
return BaseResponse(code=500, msg=str(e)) return BaseResponse(code=500, msg=str(e))
# 监测数据最近7天的数据 # 报警数据最近7天的数据
@app.get("/api/xumu/warning/past_seven_days") @app.get("/api/xumu/warning/past_seven_days")
async def past_seven_days(deviceId): async def past_seven_days(deviceId):
try: try:
@ -346,5 +348,28 @@ async def past_seven_days(deviceId):
return BaseResponse(code=500, msg=str(e)) return BaseResponse(code=500, msg=str(e))
# 报警数据统计接口
@app.get("/api/xumu/warning/statistics")
async def warning_statistics(deviceId):
try:
if deviceId is None or deviceId == "" or len(deviceId) != 4:
return BaseResponse(code=500, msg="参数错误")
sql_for_count = f"select count(iccid) from root.warning.{deviceId}"
send_json = {
"sql": sql_for_count
}
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
data = r.json()
values = data["values"]
total_count = 0
today_count = 0
if len(values) != 0:
total_count = len(values[0])
return_data = {"totoal_count": total_count, "today_count": today_count}
return BaseResponse(data=return_data)
except Exception as e:
return BaseResponse(code=500, msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8002) uvicorn.run(app, host="0.0.0.0", port=8002)