statistics

This commit is contained in:
xyj 2024-02-20 11:37:55 +08:00
parent 2a3d01f56b
commit fab4050884
1 changed files with 13 additions and 6 deletions

19
xumu.py
View File

@ -354,17 +354,24 @@ 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)
# 获取设备总报警数
r = requests.post(baseHost + queryUri, headers=headers,
json={"sql": f"select count(iccid) from root.warning.{deviceId}"})
data = r.json()
values = data["values"]
total_count = 0
if len(values) != 0:
total_count = values[0][0]
# 获取设备当天报警数
now = datetime.now().date()
r = requests.post(baseHost + queryUri, headers=headers,
json={
"sql": f"select count(iccid) from root.warning.{deviceId} where time >= {now}T00:00:00"})
data = r.json()
values = data["values"]
today_count = 0
if len(values) != 0:
total_count = len(values[0])
today_count = values[0][0]
return_data = {"totoal_count": total_count, "today_count": today_count}
return BaseResponse(data=return_data)
except Exception as e: