|
@@ -10,7 +10,7 @@ from django.utils.encoding import escape_uri_path
|
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
|
from smartfarming.models.worm_forecast import MongoCBDphoto
|
|
from smartfarming.models.worm_forecast import MongoCBDphoto
|
|
|
-from smartfarming.models.device import MongoDevice
|
|
|
|
|
|
|
+from smartfarming.models.device import MongoDevice, MongoXYCBData, MongoSCDData
|
|
|
from smartfarming.models.weather import QXZdata_New, MongoQXZ_Conf
|
|
from smartfarming.models.weather import QXZdata_New, MongoQXZ_Conf
|
|
|
from smartfarming.api.views.forecast.all_dict import insect_dict
|
|
from smartfarming.api.views.forecast.all_dict import insect_dict
|
|
|
from kedong.decoration import kedong_deco, PortError
|
|
from kedong.decoration import kedong_deco, PortError
|
|
@@ -271,7 +271,7 @@ class QxzDataExport(ListView):
|
|
|
return response
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
-class cbd_export(ListView):
|
|
|
|
|
|
|
+class CbdExport(ListView):
|
|
|
"""
|
|
"""
|
|
|
设备数据导出接口
|
|
设备数据导出接口
|
|
|
device_id 设备号(str)
|
|
device_id 设备号(str)
|
|
@@ -281,187 +281,60 @@ class cbd_export(ListView):
|
|
|
device_type 设备类型
|
|
device_type 设备类型
|
|
|
"""
|
|
"""
|
|
|
def get(self,request):
|
|
def get(self,request):
|
|
|
- print("cbd_export,日志数据导出")
|
|
|
|
|
device_id = request.GET.get("device_id")
|
|
device_id = request.GET.get("device_id")
|
|
|
start_time = request.GET.get("start_time")
|
|
start_time = request.GET.get("start_time")
|
|
|
end_time = request.GET.get("end_time")
|
|
end_time = request.GET.get("end_time")
|
|
|
filename = request.GET.get("filename")
|
|
filename = request.GET.get("filename")
|
|
|
device_type = request.GET.get("device_type")
|
|
device_type = request.GET.get("device_type")
|
|
|
- username = request.GET.get("username")
|
|
|
|
|
- recent_request = REDIS.get(username)
|
|
|
|
|
- table_headers = request.GET.get("table_header", "")
|
|
|
|
|
- table_headers_lt = table_headers.split("|")
|
|
|
|
|
- if recent_request:
|
|
|
|
|
- seconds = int(time.time()) - int(recent_request)
|
|
|
|
|
- data = {"code":"400","type":"{}秒后重试或等待文件下载完毕".format(60-seconds)}
|
|
|
|
|
- data = json.dumps(data,ensure_ascii=False)
|
|
|
|
|
- return HttpResponse(data)
|
|
|
|
|
- else:
|
|
|
|
|
- REDIS.setex(username,60,int(time.time()))
|
|
|
|
|
|
|
+ # username = request.GET.get("username")
|
|
|
book = xlwt.Workbook()
|
|
book = xlwt.Workbook()
|
|
|
sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
|
try:
|
|
try:
|
|
|
- devices = Device.objects.get(id=device_id)
|
|
|
|
|
|
|
+ devices = MongoDevice.objects.get(id=device_id)
|
|
|
except:
|
|
except:
|
|
|
data = {"code":"401","type":"未找到该设备"}
|
|
data = {"code":"401","type":"未找到该设备"}
|
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
|
return HttpResponse(data)
|
|
return HttpResponse(data)
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- device_user = DeviceUser.objects.get(real_name=username)
|
|
|
|
|
- except:
|
|
|
|
|
- data = {"code":"402","type":"未找到该用户"}
|
|
|
|
|
- data = json.dumps(data,ensure_ascii=False)
|
|
|
|
|
- return HttpResponse(data)
|
|
|
|
|
|
|
|
|
|
- if device_type == "7":
|
|
|
|
|
- models = MongoBZYData
|
|
|
|
|
- elif device_type == "4":
|
|
|
|
|
- models = MongoXYCBData
|
|
|
|
|
|
|
+ if device_type == "4":
|
|
|
|
|
+ models = MongoXYCBData
|
|
|
elif device_type == "2":
|
|
elif device_type == "2":
|
|
|
- models = MongoSCDData
|
|
|
|
|
- elif device_type == "3":
|
|
|
|
|
- models = MongoCBDData
|
|
|
|
|
- elif device_type == "14":
|
|
|
|
|
- models = MongoSYCBData
|
|
|
|
|
- elif device_type == "12":
|
|
|
|
|
- models = MongoXCTData
|
|
|
|
|
- elif device_type == "8":
|
|
|
|
|
- models = MongoXYThreeData
|
|
|
|
|
-
|
|
|
|
|
|
|
+ models = MongoSCDData
|
|
|
else:
|
|
else:
|
|
|
data = {"code":"403","type":"暂不支持该设备类型"}
|
|
data = {"code":"403","type":"暂不支持该设备类型"}
|
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
|
return HttpResponse(data)
|
|
return HttpResponse(data)
|
|
|
|
|
|
|
|
if device_id:
|
|
if device_id:
|
|
|
- # device_data = DeviceData.objects.filter(device_id=device_id)
|
|
|
|
|
device_data = models.objects.filter(device_id=device_id).order_by("-id")
|
|
device_data = models.objects.filter(device_id=device_id).order_by("-id")
|
|
|
- print(device_data.count())
|
|
|
|
|
else:
|
|
else:
|
|
|
data = {"code":"400","type":"参数为空"}
|
|
data = {"code":"400","type":"参数为空"}
|
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
|
return HttpResponse(data)
|
|
return HttpResponse(data)
|
|
|
- user_type = device_user.user_type
|
|
|
|
|
-
|
|
|
|
|
- if user_type == 1:
|
|
|
|
|
- if start_time:
|
|
|
|
|
- device_data = device_data.filter(addtime__range=(int(start_time), int(end_time)))
|
|
|
|
|
- else:
|
|
|
|
|
- if devices.device_expire == "1":
|
|
|
|
|
- print("不是管理员")
|
|
|
|
|
- device_data = device_data.filter(addtime__lte=int(devices.device_expire_time))
|
|
|
|
|
-
|
|
|
|
|
- if end_time and int(end_time) > int(devices.device_expire_time):
|
|
|
|
|
- end_time = devices.device_expire_time
|
|
|
|
|
- device_data = device_data.filter(addtime__range=(int(start_time), int(end_time)))
|
|
|
|
|
- else:
|
|
|
|
|
- if start_time and end_time:
|
|
|
|
|
- device_data = device_data.filter(addtime__range=(int(start_time), int(end_time)))
|
|
|
|
|
-
|
|
|
|
|
- # if not myuser_type == 1 and devices.device_expire == "1":
|
|
|
|
|
- # print("不是管理员")
|
|
|
|
|
- # device_data = device_data.filter(addtime__lte=int(devices.device_expire_time))
|
|
|
|
|
- #
|
|
|
|
|
- # if end_time and int(end_time) > int(devices.device_expire_time):
|
|
|
|
|
- # end_time = devices.device_expire_time
|
|
|
|
|
- # device_data = device_data.filter(addtime__range=(int(start_time), int(end_time)))
|
|
|
|
|
- # else:
|
|
|
|
|
- #
|
|
|
|
|
- #
|
|
|
|
|
|
|
|
|
|
|
|
+ if start_time:
|
|
|
|
|
+ device_data = device_data.filter(addtime__range=(int(start_time), int(end_time)))
|
|
|
|
|
+
|
|
|
sta2 = []
|
|
sta2 = []
|
|
|
if device_data:
|
|
if device_data:
|
|
|
- for x in device_data:
|
|
|
|
|
|
|
+ for x in device_data:
|
|
|
times = time.localtime(x.addtime)
|
|
times = time.localtime(x.addtime)
|
|
|
times = time.strftime("%Y-%m-%d %H:%M:%S",times)
|
|
times = time.strftime("%Y-%m-%d %H:%M:%S",times)
|
|
|
- sta2.append({"data": ast.literal_eval(x.device_data),
|
|
|
|
|
|
|
+ sta2.append({"data": eval(x.device_data),
|
|
|
"upl_time":times})
|
|
"upl_time":times})
|
|
|
else:
|
|
else:
|
|
|
sheet.write(1+1,0,"暂无数据")
|
|
sheet.write(1+1,0,"暂无数据")
|
|
|
- # 测报灯
|
|
|
|
|
- if device_type == "3":
|
|
|
|
|
- title = ["设备ID","环境温度(℃)","环境湿度(%)","加热仓温度(℃)","雨控状态",
|
|
|
|
|
- "温控状态","光控状态","信号强度","电流mA","灯管状态", "电压V","上报时间","经度","纬度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- try:
|
|
|
|
|
- if sta2[x]["data"]["rps"] == "0":
|
|
|
|
|
- rps = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- rps = "雨控"
|
|
|
|
|
- if sta2[x]["data"]["tps"] == "0":
|
|
|
|
|
- tps = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- tps = "温控"
|
|
|
|
|
- if sta2[x]["data"]["lps"] == "0":
|
|
|
|
|
- lps = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- lps = "光控"
|
|
|
|
|
- try:
|
|
|
|
|
- lat = sta2[x]["data"]["lat"]
|
|
|
|
|
- lng = sta2[x]["data"]["lng"]
|
|
|
|
|
- except:
|
|
|
|
|
- lat = 0
|
|
|
|
|
- lng = 0
|
|
|
|
|
- try:
|
|
|
|
|
- ws = sta2[x]["data"]["ws"]
|
|
|
|
|
- if ws == "" or ws == "0":
|
|
|
|
|
- ws = True
|
|
|
|
|
- else:
|
|
|
|
|
- ws = False
|
|
|
|
|
- except:
|
|
|
|
|
- ws = False
|
|
|
|
|
- if ws:
|
|
|
|
|
- lamp = "待机"
|
|
|
|
|
- else:
|
|
|
|
|
- if sta2[x]["data"]["lamp"] == "0":
|
|
|
|
|
- lamp = "工作"
|
|
|
|
|
- else:
|
|
|
|
|
- lamp = "异常"
|
|
|
|
|
-
|
|
|
|
|
- sheet.write(x+1,0,devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
- sheet.write(x+1,1,sta2[x]["data"]["at"]) # 环境温度
|
|
|
|
|
- sheet.write(x+1,2,sta2[x]["data"]["ah"]) # 环境湿度
|
|
|
|
|
- sheet.write(x+1,3,sta2[x]["data"]["hrt"]) # 加热仓温度
|
|
|
|
|
- sheet.write(x+1,4,rps) # 雨控状态
|
|
|
|
|
- sheet.write(x+1,5,tps) # 温控状态
|
|
|
|
|
- sheet.write(x+1,6,lps) # 光控状态
|
|
|
|
|
- sheet.write(x+1,7,sta2[x]["data"]["csq"]) # 信号强度
|
|
|
|
|
- sheet.write(x+1,8,sta2[x]["data"]["current"]) # 电流
|
|
|
|
|
- sheet.write(x+1,9,lamp) # 灯管状态
|
|
|
|
|
- sheet.write(x+1,10,sta2[x]["data"]["vbat"]) # 电压
|
|
|
|
|
- sheet.write(x+1,11,sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
- sheet.write(x+1,12,lng) # 经度
|
|
|
|
|
- sheet.write(x+1,13,lat) # 纬度
|
|
|
|
|
- except:
|
|
|
|
|
- continue
|
|
|
|
|
- # 性诱性诱测报
|
|
|
|
|
- elif device_type == "4":
|
|
|
|
|
- print(f"+++++++++++++性诱测报+++++++++++++")
|
|
|
|
|
- t_dict = {
|
|
|
|
|
- "ds": "设备开关",
|
|
|
|
|
- "ws": "工作状态",
|
|
|
|
|
- "at": "环境温度(℃)",
|
|
|
|
|
- "ah": "环境湿度(%)",
|
|
|
|
|
- "cv": "充电电压(V)",
|
|
|
|
|
- "bv": "电池电压(V)",
|
|
|
|
|
- "cs": "充电状态",
|
|
|
|
|
- "bs": "电池状态",
|
|
|
|
|
- "infr_ct": "诱虫次数",
|
|
|
|
|
- "csq": "信号强度",
|
|
|
|
|
- "addtime": "上报时间"
|
|
|
|
|
- }
|
|
|
|
|
- title = []
|
|
|
|
|
- for k in table_headers_lt:
|
|
|
|
|
- title.append(t_dict.get(k))
|
|
|
|
|
- title.insert(0, "设备ID")
|
|
|
|
|
- # title = ["设备ID","设备开关","工作状态","环境温度(℃)","环境湿度(%)","红外计数","高压计数","充电电压(V)","电池电压(V)",
|
|
|
|
|
- # "充电状态","电池状态","信号强度","版本号","上报时间","经度","纬度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # 性诱性诱测报
|
|
|
|
|
+ if device_type == "4":
|
|
|
|
|
+ title = [
|
|
|
|
|
+ "设备ID", "设备开关", "工作状态", "环境温度(℃)", "环境湿度(%)",
|
|
|
|
|
+ "充电电压(V)", "电池电压(V)", "充电状态", "电池状态", "诱虫次数",
|
|
|
|
|
+ "信号强度", "上报时间"
|
|
|
|
|
+ ]
|
|
|
|
|
+ for i in range(len(title)): # 遍历列
|
|
|
|
|
+ sheet.write(0, i, title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
+ for x in range(len(sta2)): # 遍历列表
|
|
|
try:
|
|
try:
|
|
|
x_d = sta2[x]["data"]
|
|
x_d = sta2[x]["data"]
|
|
|
ds = "关机" if x_d["ds"] == 0 else "开机"
|
|
ds = "关机" if x_d["ds"] == 0 else "开机"
|
|
@@ -518,158 +391,42 @@ class cbd_export(ListView):
|
|
|
"上报时间": sta2[x]["upl_time"]
|
|
"上报时间": sta2[x]["upl_time"]
|
|
|
}
|
|
}
|
|
|
for i, v in enumerate(title):
|
|
for i, v in enumerate(title):
|
|
|
- sheet.write(x+1, i, table_value.get(v))
|
|
|
|
|
|
|
+ sheet.write(x + 1, i, table_value.get(v))
|
|
|
except:
|
|
except:
|
|
|
continue
|
|
continue
|
|
|
# 杀虫灯
|
|
# 杀虫灯
|
|
|
elif device_type == "2":
|
|
elif device_type == "2":
|
|
|
- title = ["设备ID","设备开关","工作状态","雨控状态","温控状态","倾倒状态","电击次数","定时时长(h)",
|
|
|
|
|
- "环境温度(℃)","环境湿度(%)","充电电压(V)","电池电压(V)","上报时间","经度","纬度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- print(sta2[x]["upl_time"])
|
|
|
|
|
|
|
+ title = ["设备ID", "设备开关", "工作状态", "雨控状态", "温控状态", "倾倒状态", "电击次数", "定时时长(h)",
|
|
|
|
|
+ "环境温度(℃)", "环境湿度(%)", "充电电压(V)", "电池电压(V)","信号强度", "上报时间", "经度", "纬度"]
|
|
|
|
|
+ for i in range(len(title)): # 遍历列
|
|
|
|
|
+ sheet.write(0, i, title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
+ for x in range(len(sta2)): # 遍历列表
|
|
|
try:
|
|
try:
|
|
|
- if int(sta2[x]["data"]["ds"]) == "0":
|
|
|
|
|
|
|
+ if int(sta2[x]["data"]["ds"]) == 0:
|
|
|
ds = "关机"
|
|
ds = "关机"
|
|
|
else:
|
|
else:
|
|
|
ds = "开机"
|
|
ds = "开机"
|
|
|
- if int(sta2[x]["data"]["ws"]) == "0":
|
|
|
|
|
|
|
+ if int(sta2[x]["data"]["ws"]) == 0:
|
|
|
ws = "待机"
|
|
ws = "待机"
|
|
|
- elif int(sta2[x]["data"]["ws"]) == "2":
|
|
|
|
|
|
|
+ elif int(sta2[x]["data"]["ws"]) == 2:
|
|
|
ws = "充电"
|
|
ws = "充电"
|
|
|
else:
|
|
else:
|
|
|
ws = "工作"
|
|
ws = "工作"
|
|
|
|
|
|
|
|
- if int(sta2[x]["data"]["rps"]) == "0":
|
|
|
|
|
|
|
+ if int(sta2[x]["data"]["rps"]) == 0:
|
|
|
rps = "正常"
|
|
rps = "正常"
|
|
|
else:
|
|
else:
|
|
|
rps = "雨控"
|
|
rps = "雨控"
|
|
|
|
|
|
|
|
- if int(sta2[x]["data"]["tps"]) == "0":
|
|
|
|
|
|
|
+ if int(sta2[x]["data"]["tps"]) == 0:
|
|
|
tps = "正常"
|
|
tps = "正常"
|
|
|
else:
|
|
else:
|
|
|
tps = "温控"
|
|
tps = "温控"
|
|
|
-
|
|
|
|
|
- if int(sta2[x]["data"]["dps"]) == "0":
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if int(sta2[x]["data"]["dps"]) == 0:
|
|
|
dps = "正常"
|
|
dps = "正常"
|
|
|
else:
|
|
else:
|
|
|
dps = "保护"
|
|
dps = "保护"
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- lat = sta2[x]["data"]["lat"]
|
|
|
|
|
- lng = sta2[x]["data"]["lng"]
|
|
|
|
|
- except:
|
|
|
|
|
- lat = 0
|
|
|
|
|
- lng = 0
|
|
|
|
|
- sheet.write(x+1,0,devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
- sheet.write(x+1,1,ds) # 设备开关
|
|
|
|
|
- sheet.write(x+1,2,ws) # 工作状态
|
|
|
|
|
- # sheet.write(x+1,3,tbs) # 灯管状态
|
|
|
|
|
- sheet.write(x+1,3,rps) # 雨控状态
|
|
|
|
|
- sheet.write(x+1,4,tps) # 温控状态
|
|
|
|
|
- sheet.write(x+1,5,dps) # 倾倒状态
|
|
|
|
|
- sheet.write(x+1,6,sta2[x]["data"]["ct"]) # 电击次数
|
|
|
|
|
- sheet.write(x+1,7,sta2[x]["data"]["tt"]) # 定时时长
|
|
|
|
|
- sheet.write(x+1,8,sta2[x]["data"]["at"]) # 环境温度
|
|
|
|
|
- sheet.write(x+1,9,sta2[x]["data"]["ah"]) # 环境湿度
|
|
|
|
|
- sheet.write(x+1,10,sta2[x]["data"]["cv"]) # 充电电压
|
|
|
|
|
- sheet.write(x+1,11,sta2[x]["data"]["bv"]) # 电池电压
|
|
|
|
|
- sheet.write(x+1,12,sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
- sheet.write(x+1,13,lng) # 经度
|
|
|
|
|
- sheet.write(x+1,14,lat) # 纬度
|
|
|
|
|
- except:
|
|
|
|
|
- continue
|
|
|
|
|
- # 孢子仪
|
|
|
|
|
- elif device_type == "7":
|
|
|
|
|
- title = ["设备ID","保温仓设定温度(℃)","保温仓当前温度(℃)","电池状态","雨控状态","摄像头状态", "电压(V)","信号强度",
|
|
|
|
|
- "环境温度(℃)","环境湿度(%)","设备版本","上报时间","经度","纬度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- try:
|
|
|
|
|
-
|
|
|
|
|
- if sta2[x]["data"]["batStatus"] == "0":
|
|
|
|
|
- bat_sta = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- bat_sta = "电量过低"
|
|
|
|
|
-
|
|
|
|
|
- if sta2[x]["data"]["rps"] == "0":
|
|
|
|
|
- rps = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- rps = "雨控"
|
|
|
|
|
-
|
|
|
|
|
- if sta2[x]["data"]["usb_sta"] == "0":
|
|
|
|
|
- usb_sta = "正常"
|
|
|
|
|
- else:
|
|
|
|
|
- usb_sta = "异常"
|
|
|
|
|
- try:
|
|
|
|
|
- lat = sta2[x]["data"]["lat"]
|
|
|
|
|
- lng = sta2[x]["data"]["lng"]
|
|
|
|
|
- except:
|
|
|
|
|
- lat = 0
|
|
|
|
|
- lng = 0
|
|
|
|
|
- except:
|
|
|
|
|
- continue
|
|
|
|
|
- sheet.write(x+1,0,devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
- sheet.write(x+1,1,sta2[x]["data"]["set_temp"]) # 保温仓设定温度
|
|
|
|
|
- sheet.write(x+1,2,sta2[x]["data"]["pre_temp"]) # 保温仓当前温度
|
|
|
|
|
- sheet.write(x+1,3,bat_sta) # 电池状态
|
|
|
|
|
- sheet.write(x+1,4,rps) # 雨控状态
|
|
|
|
|
- sheet.write(x+1,5,usb_sta) # 摄像头状态
|
|
|
|
|
- sheet.write(x+1,6,sta2[x]["data"]["vbat"]) # 电压
|
|
|
|
|
- # sheet.write(x+1,8,sta2[x]["data"]["alti"]) # 海拔高度
|
|
|
|
|
- sheet.write(x+1,7,sta2[x]["data"]["csq"]) # 信号强度
|
|
|
|
|
- sheet.write(x+1,8,sta2[x]["data"]["at"]) # 环境温度
|
|
|
|
|
- sheet.write(x+1,9,sta2[x]["data"]["ah"]) # 环境湿度
|
|
|
|
|
- sheet.write(x+1,10,sta2[x]["data"]["dver"]) # 设备版本
|
|
|
|
|
- sheet.write(x+1,11,sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
- sheet.write(x+1,12,lng) # 经度
|
|
|
|
|
- sheet.write(x+1,13,lat) # 纬度
|
|
|
|
|
- # 色诱
|
|
|
|
|
- elif device_type == "14":
|
|
|
|
|
- title = ["设备ID", "上报时间", "开机状态", "空气温度", "空气湿度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- if int(sta2[x]["data"]["ds"]) == 0:
|
|
|
|
|
- ds = "关机"
|
|
|
|
|
- else:
|
|
|
|
|
- ds = "开机"
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- at = str(int(sta2[x]["data"]["at"])/10)
|
|
|
|
|
- ah = str(int(sta2[x]["data"]["ah"])/10)
|
|
|
|
|
- except:
|
|
|
|
|
- at = sta2[x]["data"]["at"]
|
|
|
|
|
- ah = sta2[x]["data"]["ah"]
|
|
|
|
|
-
|
|
|
|
|
- sheet.write(x + 1, 0, devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
- sheet.write(x + 1, 1, sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
- sheet.write(x + 1, 2, ds) # 开机状态
|
|
|
|
|
- sheet.write(x + 1, 3, at) # 空气温度
|
|
|
|
|
- sheet.write(x + 1, 4, ah) # 空气湿度
|
|
|
|
|
- # 吸虫塔
|
|
|
|
|
- elif device_type == "12":
|
|
|
|
|
- title = ["设备ID","设备开关","SIM卡号","工作状态","环境温度(℃)","环境湿度(%)",
|
|
|
|
|
- "震动开关","信号强度","上报时间","经度","纬度"]
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- try:
|
|
|
|
|
- if sta2[x]["data"]["ds"] == "0":
|
|
|
|
|
- ds = "关机"
|
|
|
|
|
- else:
|
|
|
|
|
- ds = "开机"
|
|
|
|
|
-
|
|
|
|
|
- if sta2[x]["data"]["ws"] == "0":
|
|
|
|
|
- ws = "待机"
|
|
|
|
|
- else:
|
|
|
|
|
- ws = "工作"
|
|
|
|
|
- if sta2[x]["data"]["shake"] == "0":
|
|
|
|
|
- shake = "关"
|
|
|
|
|
- else:
|
|
|
|
|
- shake = "开"
|
|
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
lat = sta2[x]["data"]["lat"]
|
|
lat = sta2[x]["data"]["lat"]
|
|
@@ -677,107 +434,30 @@ class cbd_export(ListView):
|
|
|
except:
|
|
except:
|
|
|
lat = 0
|
|
lat = 0
|
|
|
lng = 0
|
|
lng = 0
|
|
|
-
|
|
|
|
|
- sheet.write(x+1,0,devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
- sheet.write(x+1,1,ds) # 设备开关:
|
|
|
|
|
- sheet.write(x+1,2,sta2[x]["data"]["iccid"]) # iccid
|
|
|
|
|
- sheet.write(x+1,3,ws) # 工作状态
|
|
|
|
|
- sheet.write(x+1,4,sta2[x]["data"]["at"]) # 环境温度
|
|
|
|
|
- sheet.write(x+1,5,sta2[x]["data"]["ah"]) # 环境湿度
|
|
|
|
|
- sheet.write(x+1,6,shake) # 震动开关:
|
|
|
|
|
- sheet.write(x+1,7,sta2[x]["data"]["csq"]) # 信号强度
|
|
|
|
|
- sheet.write(x+1,8,sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
- sheet.write(x+1,9,lng) # 经度
|
|
|
|
|
- sheet.write(x+1,10,lat) # 纬度
|
|
|
|
|
|
|
+ sheet.write(x + 1, 0, devices.device_id) # 将equip_id写入到第x+1行,第0列中
|
|
|
|
|
+ sheet.write(x + 1, 1, ds) # 设备开关
|
|
|
|
|
+ sheet.write(x + 1, 2, ws) # 工作状态
|
|
|
|
|
+ sheet.write(x + 1, 3, rps) # 雨控状态
|
|
|
|
|
+ sheet.write(x + 1, 4, tps) # 温控状态
|
|
|
|
|
+ sheet.write(x + 1, 5, dps) # 倾倒状态
|
|
|
|
|
+ sheet.write(x + 1, 6, sta2[x]["data"]["ct"]) # 电击次数
|
|
|
|
|
+ sheet.write(x + 1, 7, sta2[x]["data"]["tt"]) # 定时时长
|
|
|
|
|
+ sheet.write(x + 1, 8, sta2[x]["data"]["at"]) # 环境温度
|
|
|
|
|
+ sheet.write(x + 1, 9, sta2[x]["data"]["ah"]) # 环境湿度
|
|
|
|
|
+ sheet.write(x + 1, 10, sta2[x]["data"]["cv"]) # 充电电压
|
|
|
|
|
+ sheet.write(x + 1, 11, sta2[x]["data"]["bv"]) # 电池电压
|
|
|
|
|
+ sheet.write(x + 1, 12, sta2[x]["data"]["csq"]) # 信号强度
|
|
|
|
|
+ sheet.write(x + 1, 13, sta2[x]["upl_time"]) # 上报时间
|
|
|
|
|
+ sheet.write(x + 1, 14, lng) # 经度
|
|
|
|
|
+ sheet.write(x + 1, 15, lat) # 纬度
|
|
|
except:
|
|
except:
|
|
|
continue
|
|
continue
|
|
|
- # 性诱3.0
|
|
|
|
|
- elif device_type == "8":
|
|
|
|
|
- print(f"---------------性诱3.0--------------")
|
|
|
|
|
- t_dict = {
|
|
|
|
|
- "ds": "设备开关",
|
|
|
|
|
- "ws": "工作状态",
|
|
|
|
|
- "at": "环境温度(℃)",
|
|
|
|
|
- "ah": "环境湿度(%)",
|
|
|
|
|
- "cc": "电流(mA)",
|
|
|
|
|
- "cv": "充电电压(V)",
|
|
|
|
|
- "bv": "电池电压(V)",
|
|
|
|
|
- "bs": "电池状态",
|
|
|
|
|
- "volt_ct": "诱虫次数",
|
|
|
|
|
- "csq": "信号强度",
|
|
|
|
|
- "addtime": "上报时间"
|
|
|
|
|
- }
|
|
|
|
|
- title = []
|
|
|
|
|
- for k in table_headers_lt:
|
|
|
|
|
- title.append(t_dict.get(k))
|
|
|
|
|
- title.insert(0, "设备ID")
|
|
|
|
|
- for i in range(len(title)): # 遍历列
|
|
|
|
|
- sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
|
|
- for x in range(len(sta2)): # 遍历列表
|
|
|
|
|
- try:
|
|
|
|
|
- if sta2[x]["data"]["ds"] == "0":
|
|
|
|
|
- ds = "关机"
|
|
|
|
|
- else:
|
|
|
|
|
- ds = "开机"
|
|
|
|
|
- if sta2[x]["data"]["ws"] == "0":
|
|
|
|
|
- ws = "待机"
|
|
|
|
|
- else:
|
|
|
|
|
- ws = "工作"
|
|
|
|
|
- try:
|
|
|
|
|
- at = sta2[x]["data"]["at"]
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- at = "0"
|
|
|
|
|
- try:
|
|
|
|
|
- ah = sta2[x]["data"]["ah"]
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- ah = "0"
|
|
|
|
|
- if sta2[x]["data"]["bs"] == "0":
|
|
|
|
|
- bs = "正常"
|
|
|
|
|
- elif sta2[x]["data"]["bs"] == "1":
|
|
|
|
|
- bs = "欠压"
|
|
|
|
|
- else:
|
|
|
|
|
- bs = "过压"
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- lat = sta2[x]["data"]["lat"]
|
|
|
|
|
- lng = sta2[x]["data"]["lng"]
|
|
|
|
|
- except:
|
|
|
|
|
- lat = 0
|
|
|
|
|
- lng = 0
|
|
|
|
|
- table_value = {
|
|
|
|
|
- "设备ID": devices.device_id,
|
|
|
|
|
- "设备开关": ds,
|
|
|
|
|
- "工作状态": ws,
|
|
|
|
|
- "环境温度(℃)": at,
|
|
|
|
|
- "环境湿度(%)": ah,
|
|
|
|
|
- "电流(mA)": sta2[x]["data"]["cc"],
|
|
|
|
|
- "充电电压(V)": sta2[x]["data"]["cv"],
|
|
|
|
|
- "电池电压(V)": sta2[x]["data"].get("bv", "0"),
|
|
|
|
|
- "电池状态": "正常" if sta2[x]["data"].get("bs", "1") == "0" else "非正常",
|
|
|
|
|
- "诱虫次数": sta2[x]["data"]["volt_ct"],
|
|
|
|
|
- "信号强度": sta2[x]["data"]["csq"],
|
|
|
|
|
- "上报时间": sta2[x]["upl_time"]
|
|
|
|
|
- }
|
|
|
|
|
- for i, v in enumerate(title):
|
|
|
|
|
- sheet.write(x+1, i, table_value.get(v))
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- print(e)
|
|
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- else:
|
|
|
|
|
- data = {"code":"400","type":"参数为空"}
|
|
|
|
|
- data = json.dumps(data,ensure_ascii=False)
|
|
|
|
|
- return HttpResponse(data)
|
|
|
|
|
sheet.col(0).width = 256 * 18
|
|
sheet.col(0).width = 256 * 18
|
|
|
- sheet.col(1).width = 256 * 15
|
|
|
|
|
- sheet.col(2).width = 256 * 15
|
|
|
|
|
- sheet.col(3).width = 256 * 15
|
|
|
|
|
- sheet.col(4).width = 256 * 15
|
|
|
|
|
- sheet.col(5).width = 256 * 15
|
|
|
|
|
- sheet.col(6).width = 256 * 15
|
|
|
|
|
- sheet.col(7).width = 256 * 15
|
|
|
|
|
- sheet.col(8).width = 256 * 15
|
|
|
|
|
- sheet.col(9).width = 256 * 15
|
|
|
|
|
|
|
+ sheet.col(2).width = 256 * 11
|
|
|
|
|
+ sheet.col(3).width = 256 * 11
|
|
|
|
|
+ sheet.col(4).width = 256 * 13
|
|
|
|
|
+ sheet.col(8).width = 256 * 11
|
|
|
|
|
+ sheet.col(9).width = 256 * 11
|
|
|
sheet.col(10).width = 256 * 20
|
|
sheet.col(10).width = 256 * 20
|
|
|
# 写出到IO
|
|
# 写出到IO
|
|
|
output = BytesIO()
|
|
output = BytesIO()
|
|
@@ -787,5 +467,4 @@ class cbd_export(ListView):
|
|
|
response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
response['Content-Disposition'] = 'attachment;filename={}.xls'.format(escape_uri_path(filename))
|
|
response['Content-Disposition'] = 'attachment;filename={}.xls'.format(escape_uri_path(filename))
|
|
|
response.write(output.getvalue())
|
|
response.write(output.getvalue())
|
|
|
- REDIS.delete(username)
|
|
|
|
|
return response
|
|
return response
|