|
@@ -149,3 +149,54 @@ class PestSelectView(GenericAPIView):
|
|
|
})
|
|
})
|
|
|
data["items"] = pest_image_data
|
|
data["items"] = pest_image_data
|
|
|
return Response(data)
|
|
return Response(data)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class RecentMonthPestCount(GenericAPIView):
|
|
|
|
|
+ authentication_classes = [MyJWTAuthentication]
|
|
|
|
|
+ permission_classes = [ModulePermission]
|
|
|
|
|
+
|
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
|
+ try:
|
|
|
|
|
+ data=request.query_params
|
|
|
|
|
+ start = data.get("start")
|
|
|
|
|
+ end = data.get("end")
|
|
|
|
|
+ device_id = data.get("device_id")
|
|
|
|
|
+ m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
|
|
|
|
|
+ device = m.find_one(wheres={"device_id": device_id}, options={"id": 1})
|
|
|
|
|
+ d_id = device.get("id")
|
|
|
|
|
+ sa_device_cbdphoto_b = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbdphoto_b')
|
|
|
|
|
+ data = sa_device_cbdphoto_b.find_many(
|
|
|
|
|
+ wheres={
|
|
|
|
|
+ "device_id": str(d_id),
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gte": int(start),
|
|
|
|
|
+ "$lte": int(end)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ options={
|
|
|
|
|
+ "id": 1,
|
|
|
|
|
+ "indentify_result": 1,
|
|
|
|
|
+ "addr": 1
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ # 17,1#158,5#365,5#260,7#20,1#46,2#160,6#3,1#21,1
|
|
|
|
|
+ result = {}
|
|
|
|
|
+ imgs = []
|
|
|
|
|
+ for i in data:
|
|
|
|
|
+ indentify_result = i.get("indentify_result")
|
|
|
|
|
+ addr = i.get("addr")
|
|
|
|
|
+ if indentify_result:
|
|
|
|
|
+ iden = indentify_result.split("#")
|
|
|
|
|
+ for p in iden:
|
|
|
|
|
+ pest, num = p.split(",")
|
|
|
|
|
+ if pest in result.keys():
|
|
|
|
|
+ result[pest] += int(num)
|
|
|
|
|
+ else:
|
|
|
|
|
+ result[pest] = int(num)
|
|
|
|
|
+ addr = addr.starts
|
|
|
|
|
+ imgs.append(addr if addr.startswith("http") else "https://bigdata-image.oss-cn-hangzhou.aliyuncs.com/Basics/cbd/" + addr)
|
|
|
|
|
+ return Response({"data": result, "imgs": imgs})
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ return Response({"data": [], "imgs": [], "msg": e.args})
|
|
|
|
|
+
|
|
|
|
|
+
|