statistics
This commit is contained in:
parent
2a3d01f56b
commit
fab4050884
19
xumu.py
19
xumu.py
|
@ -354,17 +354,24 @@ async def warning_statistics(deviceId):
|
||||||
try:
|
try:
|
||||||
if deviceId is None or deviceId == "" or len(deviceId) != 4:
|
if deviceId is None or deviceId == "" or len(deviceId) != 4:
|
||||||
return BaseResponse(code=500, msg="参数错误")
|
return BaseResponse(code=500, msg="参数错误")
|
||||||
sql_for_count = f"select count(iccid) from root.warning.{deviceId}"
|
# 获取设备总报警数
|
||||||
send_json = {
|
r = requests.post(baseHost + queryUri, headers=headers,
|
||||||
"sql": sql_for_count
|
json={"sql": f"select count(iccid) from root.warning.{deviceId}"})
|
||||||
}
|
|
||||||
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
|
|
||||||
data = r.json()
|
data = r.json()
|
||||||
values = data["values"]
|
values = data["values"]
|
||||||
total_count = 0
|
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
|
today_count = 0
|
||||||
if len(values) != 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_data = {"totoal_count": total_count, "today_count": today_count}
|
||||||
return BaseResponse(data=return_data)
|
return BaseResponse(data=return_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue