views.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. from rest_framework.views import APIView
  2. from rest_framework.response import Response
  3. from django.core.cache import cache as default_cache
  4. import json
  5. import ast
  6. from django.conf import settings
  7. from .serializers import SearchEquipSerializer, DeviceDetailSerializer
  8. from utils.JWTAuthentication_diy import APIAuthentication
  9. from utils.permissions import QXZDeviceDetailPermission, ScdDeviceDetailPermission, CbdDeviceDetailPermission, BzyDeviceDetailPermission, XycbDeviceDetailPermission
  10. from utils.MyRateThrottle import DeviceDetailRateThrottle, QxzDeviceListRateThrottle, ScdDeviceListRateThrottle, CbdDeviceListRateThrottle, DevicePhotoRateThrottle, BzyDeviceListRateThrottle, XycbDeviceListRateThrottle
  11. from utils.utils import DeviceInfoUtils
  12. from utils.db_utils import MongoDBTools
  13. # Create your views here.
  14. class SearchEquip(APIView):
  15. def post(self, request):
  16. serializer = SearchEquipSerializer(data=request.data)
  17. serializer.is_valid(raise_exception=True)
  18. request_data = serializer.validated_data
  19. data = DeviceInfoUtils().get_equip_list(
  20. d_id=request_data.get("device_id"),
  21. isfullId=request_data.get("isfullId")
  22. )
  23. return Response(data)
  24. class QxzDeviceListView(APIView):
  25. authentication_classes = [APIAuthentication]
  26. throttle_classes = [QxzDeviceListRateThrottle]
  27. def get(self, request, *args, **kwargs):
  28. """获取气象站设备列表接口"""
  29. uid = request.user
  30. wheres = {
  31. "device_type_id":5,
  32. '$or': [
  33. {'owner_uid': uid},
  34. {'user_dealer': uid}
  35. ]
  36. }
  37. project = {
  38. 'device_id': '$device_id',
  39. 'uptime': '$uptime',
  40. 'device_status': '$device_status',
  41. 'lng': '$lng',
  42. 'lat': '$lat'
  43. }
  44. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  45. data = m.find_many(wheres=wheres, options=project)
  46. if data:
  47. total_counts = data.count()
  48. else:
  49. total_counts = 0
  50. result = {"total_counts":total_counts,"items":[]}
  51. qxz_list_cache = []
  52. for item in data:
  53. result["items"].append(item)
  54. qxz_list_cache.append(item["device_id"])
  55. default_cache.set(str(uid)+"_qxz_list", qxz_list_cache,60*5)
  56. return Response(result)
  57. class QxzDeviceDetailView(APIView):
  58. authentication_classes = [APIAuthentication]
  59. permission_classes = [QXZDeviceDetailPermission]
  60. throttle_classes = [DeviceDetailRateThrottle]
  61. def get(self, request, *args, **kwargs):
  62. serializer = DeviceDetailSerializer(data=request.query_params)
  63. serializer.is_valid(raise_exception=True)
  64. request_data = serializer.validated_data
  65. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  66. conf_wheres = {
  67. "device_id":device_id,
  68. }
  69. conf_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_conf')
  70. conf_data = conf_m.find_one(wheres=conf_wheres)
  71. if conf_data:
  72. conf_data.pop("id")
  73. conf_data.pop("device_id")
  74. conf_data.pop("uptime")
  75. conf_data = dict(sorted(conf_data.items(), key=lambda e:int(e[0].split("e")[1])))
  76. result = {"conf":conf_data,"items":[]}
  77. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_data')
  78. data_wheres = {
  79. "device_id": device_id,
  80. "uptime": {"$gt":start_time}
  81. }
  82. data = data_m.find_many(wheres=data_wheres)
  83. for item in data:
  84. item.pop("id")
  85. item.pop("device_id")
  86. uptime = item.pop("uptime")
  87. item = dict(sorted(item.items(), key=lambda e:int(e[0].split("e")[1])))
  88. item["uptime"] = uptime
  89. result["items"].append(item)
  90. return Response(result)
  91. class ScdDeviceListView(APIView):
  92. authentication_classes = [APIAuthentication]
  93. throttle_classes = [ScdDeviceListRateThrottle]
  94. def get(self, request, *args, **kwargs):
  95. """获取杀虫灯设备列表接口"""
  96. uid = request.user
  97. wheres = {
  98. "device_type_id":2,
  99. '$or': [
  100. {'owner_uid': uid},
  101. {'user_dealer': uid}
  102. ]
  103. }
  104. project = {
  105. 'id': '$id',
  106. 'device_id': '$device_id',
  107. 'uptime': '$uptime',
  108. 'device_status': '$device_status',
  109. 'lng': '$lng',
  110. 'lat': '$lat'
  111. }
  112. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  113. data = m.find_many(wheres=wheres, options=project)
  114. if data:
  115. total_counts = data.count()
  116. else:
  117. total_counts = 0
  118. result = {"total_counts":total_counts,"items":[]}
  119. scd_dict_cache = {}
  120. for item in data:
  121. d_id = item.pop("id")
  122. result["items"].append(item)
  123. scd_dict_cache[item["device_id"]] = d_id
  124. default_cache.set(str(uid)+"_scd_list", scd_dict_cache,60*5)
  125. return Response(result)
  126. class ScdDeviceDetailView(APIView):
  127. authentication_classes = [APIAuthentication]
  128. permission_classes = [ScdDeviceDetailPermission]
  129. throttle_classes = [DeviceDetailRateThrottle]
  130. def get(self, request, *args, **kwargs):
  131. serializer = DeviceDetailSerializer(data=request.query_params)
  132. serializer.is_valid(raise_exception=True)
  133. request_data = serializer.validated_data
  134. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  135. uid = request.user
  136. scd_dict_cache = default_cache.get(str(uid)+"_scd_list")
  137. if scd_dict_cache:
  138. d_id = scd_dict_cache[device_id]
  139. else:
  140. """避免缓存失效"""
  141. wheres = {
  142. 'device_type_id':2,
  143. '$or': [
  144. {'owner_uid': uid},
  145. {'user_dealer': uid}
  146. ]
  147. }
  148. project = {
  149. 'id': '$id',
  150. 'device_id': '$device_id'
  151. }
  152. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  153. data = m.find_many(wheres=wheres, options=project)
  154. scd_dict_cache = []
  155. for item in data:
  156. scd_dict_cache[item["device_id"]]=item["id"]
  157. default_cache.set(str(uid)+"_scd_list", scd_dict_cache,60*5)
  158. d_id = scd_dict_cache[device_id]
  159. result = []
  160. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_scd_data')
  161. data_wheres = {
  162. "device_id": d_id,
  163. "addtime": {"$gt":start_time}
  164. }
  165. data_project = {
  166. "addtime": "$addtime",
  167. "device_data": "$device_data"
  168. }
  169. data = data_m.find_many(wheres=data_wheres,options=data_project)
  170. for item in data:
  171. try:
  172. device_data = json.loads(item["device_data"])
  173. except:
  174. device_data = ast.literal_eval(item["device_data"])
  175. result.append({"uptime":item["addtime"],"item_data":device_data})
  176. return Response(result)
  177. class CbdDeviceListView(APIView):
  178. authentication_classes = [APIAuthentication]
  179. throttle_classes = [CbdDeviceListRateThrottle]
  180. def get(self, request, *args, **kwargs):
  181. """获取测报灯设备列表接口"""
  182. uid = request.user
  183. wheres = {
  184. "device_type_id":3,
  185. '$or': [
  186. {'owner_uid': uid},
  187. {'user_dealer': uid}
  188. ]
  189. }
  190. project = {
  191. 'id': '$id',
  192. 'device_id': '$device_id',
  193. 'disable': '$disable',
  194. 'uptime': '$uptime',
  195. 'device_status': '$device_status',
  196. 'lng': '$lng',
  197. 'lat': '$lat'
  198. }
  199. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  200. data = m.find_many(wheres=wheres, options=project)
  201. if data:
  202. total_counts = data.count()
  203. else:
  204. total_counts = 0
  205. result = {"total_counts":total_counts,"items":[]}
  206. cbd_dict_cache = {}
  207. for item in data:
  208. d_id = item.pop("id")
  209. disable = item.pop("disable")
  210. result["items"].append(item)
  211. cbd_dict_cache[item["device_id"]] = {"d_id":d_id,"disable":disable}
  212. default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
  213. return Response(result)
  214. class CbdDeviceDetailView(APIView):
  215. authentication_classes = [APIAuthentication]
  216. permission_classes = [CbdDeviceDetailPermission]
  217. throttle_classes = [DeviceDetailRateThrottle]
  218. def get(self, request, *args, **kwargs):
  219. serializer = DeviceDetailSerializer(data=request.query_params)
  220. serializer.is_valid(raise_exception=True)
  221. request_data = serializer.validated_data
  222. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  223. uid = request.user
  224. cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
  225. if cbd_dict_cache:
  226. d_id = cbd_dict_cache[device_id]["d_id"]
  227. else:
  228. """避免缓存失效"""
  229. wheres = {
  230. 'device_type_id':3,
  231. '$or': [
  232. {'owner_uid': uid},
  233. {'user_dealer': uid}
  234. ]
  235. }
  236. project = {
  237. 'id': '$id',
  238. 'device_id': '$device_id',
  239. 'disable': '$disable'
  240. }
  241. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  242. data = m.find_many(wheres=wheres, options=project)
  243. cbd_dict_cache = {}
  244. for item in data:
  245. cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
  246. default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
  247. d_id = cbd_dict_cache[device_id]["d_id"]
  248. result = []
  249. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbd_data')
  250. data_wheres = {
  251. "device_id": d_id,
  252. "addtime": {"$gt":start_time}
  253. }
  254. data_project = {
  255. "addtime": "$addtime",
  256. "device_data": "$device_data"
  257. }
  258. data = data_m.find_many(wheres=data_wheres,options=data_project)
  259. for item in data:
  260. try:
  261. device_data = json.loads(item["device_data"])
  262. except:
  263. device_data = ast.literal_eval(item["device_data"])
  264. result.append({"uptime":item["addtime"],"item_data":device_data})
  265. return Response(result)
  266. class CbdDevicePhotoView(APIView):
  267. authentication_classes = [APIAuthentication]
  268. permission_classes = [CbdDeviceDetailPermission]
  269. throttle_classes = [DevicePhotoRateThrottle]
  270. def get(self, request, *args, **kwargs):
  271. serializer = DeviceDetailSerializer(data=request.query_params)
  272. serializer.is_valid(raise_exception=True)
  273. request_data = serializer.validated_data
  274. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  275. uid = request.user
  276. cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
  277. if cbd_dict_cache:
  278. d_id = cbd_dict_cache[device_id]["d_id"]
  279. disable = cbd_dict_cache[device_id]["disable"]
  280. else:
  281. """避免缓存失效"""
  282. wheres = {
  283. 'device_type_id':3,
  284. '$or': [
  285. {'owner_uid': uid},
  286. {'user_dealer': uid}
  287. ]
  288. }
  289. project = {
  290. 'id': '$id',
  291. 'device_id': '$device_id',
  292. 'disable': '$disable'
  293. }
  294. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  295. data = m.find_many(wheres=wheres, options=project)
  296. cbd_dict_cache = {}
  297. for item in data:
  298. cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
  299. default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
  300. d_id = cbd_dict_cache[device_id]["d_id"]
  301. disable = cbd_dict_cache[device_id]["disable"]
  302. result = []
  303. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbd_photo')
  304. data_wheres = {
  305. "device_id": str(d_id),
  306. "addtime": {"$gt":start_time}
  307. }
  308. if disable == 1:
  309. data_project = {
  310. "addtime": "$addtime",
  311. "addr": "$addr",
  312. "indentify_photo":"$indentify_photo",
  313. "indentify_result":"$indentify_result"
  314. }
  315. else:
  316. data_project = {
  317. "addtime": "$addtime",
  318. "addr": "$addr"
  319. }
  320. data = data_m.find_many(wheres=data_wheres,options=data_project)
  321. for item in data:
  322. item_data = {}
  323. addr = item["addr"]
  324. if addr.startswith("http"):
  325. Image = addr
  326. elif addr.startswith("/"):
  327. Image = settings.CONFIG["image_url"]["image_forward"] + addr
  328. else:
  329. Image = settings.CONFIG["image_url"]["image_forward"] + "/" +addr
  330. item_data["uptime"] = item["addtime"]
  331. item_data["Image"] = Image
  332. if disable == 1:
  333. Result = item["indentify_result"] if item["indentify_result"] else "0"
  334. indentify_photo = item["indentify_photo"]
  335. if indentify_photo:
  336. if indentify_photo.startswith("http"):
  337. Result_image = indentify_photo
  338. elif indentify_photo.startswith("/"):
  339. Result_image = settings.CONFIG["image_url"]["result_image_forward"] + indentify_photo
  340. else:
  341. Result_image = settings.CONFIG["image_url"]["result_image_forward"] + "/" + indentify_photo
  342. else:
  343. Result_image = "0"
  344. item_data["Result_image"] = Result_image
  345. item_data["Result"] = Result
  346. result.append(item_data)
  347. return Response(result)
  348. class BzyDeviceListView(APIView):
  349. authentication_classes = [APIAuthentication]
  350. throttle_classes = [BzyDeviceListRateThrottle]
  351. def get(self, request, *args, **kwargs):
  352. """获取孢子仪设备列表接口"""
  353. uid = request.user
  354. wheres = {
  355. "device_type_id":7,
  356. '$or': [
  357. {'owner_uid': uid},
  358. {'user_dealer': uid}
  359. ]
  360. }
  361. project = {
  362. 'id': '$id',
  363. 'device_id': '$device_id',
  364. 'uptime': '$uptime',
  365. 'device_status': '$device_status',
  366. 'lng': '$lng',
  367. 'lat': '$lat'
  368. }
  369. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  370. data = m.find_many(wheres=wheres, options=project)
  371. if data:
  372. total_counts = data.count()
  373. else:
  374. total_counts = 0
  375. result = {"total_counts":total_counts,"items":[]}
  376. bzy_dict_cache = {}
  377. for item in data:
  378. d_id = item.pop("id")
  379. result["items"].append(item)
  380. bzy_dict_cache[item["device_id"]] = d_id
  381. default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
  382. return Response(result)
  383. class BzyDeviceDetailView(APIView):
  384. authentication_classes = [APIAuthentication]
  385. permission_classes = [BzyDeviceDetailPermission]
  386. throttle_classes = [DeviceDetailRateThrottle]
  387. def get(self, request, *args, **kwargs):
  388. serializer = DeviceDetailSerializer(data=request.query_params)
  389. serializer.is_valid(raise_exception=True)
  390. request_data = serializer.validated_data
  391. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  392. uid = request.user
  393. bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
  394. if bzy_dict_cache:
  395. d_id = bzy_dict_cache[device_id]
  396. else:
  397. """避免缓存失效"""
  398. wheres = {
  399. 'device_type_id':7,
  400. '$or': [
  401. {'owner_uid': uid},
  402. {'user_dealer': uid}
  403. ]
  404. }
  405. project = {
  406. 'id': '$id',
  407. 'device_id': '$device_id'
  408. }
  409. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  410. data = m.find_many(wheres=wheres, options=project)
  411. bzy_dict_cache = []
  412. for item in data:
  413. bzy_dict_cache[item["device_id"]]=item["id"]
  414. default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
  415. d_id = bzy_dict_cache[device_id]
  416. result = []
  417. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzy_data')
  418. data_wheres = {
  419. "device_id": d_id,
  420. "addtime": {"$gt":start_time}
  421. }
  422. data_project = {
  423. "addtime": "$addtime",
  424. "device_data": "$device_data"
  425. }
  426. data = data_m.find_many(wheres=data_wheres,options=data_project)
  427. for item in data:
  428. try:
  429. device_data = json.loads(item["device_data"])
  430. except:
  431. device_data = ast.literal_eval(item["device_data"])
  432. result.append({"uptime":item["addtime"],"item_data":device_data})
  433. return Response(result)
  434. class BzyDevicePhotoView(APIView):
  435. authentication_classes = [APIAuthentication]
  436. permission_classes = [BzyDeviceDetailPermission]
  437. throttle_classes = [DevicePhotoRateThrottle]
  438. def get(self, request, *args, **kwargs):
  439. serializer = DeviceDetailSerializer(data=request.query_params)
  440. serializer.is_valid(raise_exception=True)
  441. request_data = serializer.validated_data
  442. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  443. uid = request.user
  444. bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
  445. if bzy_dict_cache:
  446. d_id = bzy_dict_cache[device_id]
  447. else:
  448. """避免缓存失效"""
  449. wheres = {
  450. 'device_type_id':7,
  451. '$or': [
  452. {'owner_uid': uid},
  453. {'user_dealer': uid}
  454. ]
  455. }
  456. project = {
  457. 'id': '$id',
  458. 'device_id': '$device_id'
  459. }
  460. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  461. data = m.find_many(wheres=wheres, options=project)
  462. bzy_dict_cache = []
  463. for item in data:
  464. bzy_dict_cache[item["device_id"]]=item["id"]
  465. default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
  466. d_id = bzy_dict_cache[device_id]
  467. result = []
  468. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzyphoto')
  469. data_wheres = {
  470. "device_id": str(d_id),
  471. "addtime": {"$gt":start_time}
  472. }
  473. data_project = {
  474. "addtime": "$addtime",
  475. "addr": "$addr"
  476. }
  477. data = data_m.find_many(wheres=data_wheres,options=data_project)
  478. for item in data:
  479. if item["addr"].startswith("http"):
  480. Image = item["addr"]
  481. elif item["addr"].startswith("/"):
  482. Image = settings.CONFIG["image_url"]["bzy_img_forward"] + item["addr"]
  483. else:
  484. Image = settings.CONFIG["image_url"]["bzy_img_forward"] + "/" + item["addr"]
  485. result.append({"uptime":item["addtime"],"Image":Image})
  486. return Response(result)
  487. class XycbDeviceListView(APIView):
  488. authentication_classes = [APIAuthentication]
  489. throttle_classes = [XycbDeviceListRateThrottle]
  490. def get(self, request, *args, **kwargs):
  491. """获取性诱设备列表接口"""
  492. uid = request.user
  493. wheres = {
  494. "device_type_id":4,
  495. '$or': [
  496. {'owner_uid': uid},
  497. {'user_dealer': uid}
  498. ]
  499. }
  500. project = {
  501. 'id': '$id',
  502. 'device_id': '$device_id',
  503. 'uptime': '$uptime',
  504. 'device_status': '$device_status',
  505. 'lng': '$lng',
  506. 'lat': '$lat'
  507. }
  508. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  509. data = m.find_many(wheres=wheres, options=project)
  510. if data:
  511. total_counts = data.count()
  512. else:
  513. total_counts = 0
  514. result = {"total_counts":total_counts,"items":[]}
  515. xycb_dict_cache = {}
  516. for item in data:
  517. d_id = item.pop("id")
  518. result["items"].append(item)
  519. xycb_dict_cache[item["device_id"]] = d_id
  520. default_cache.set(str(uid)+"_xycb_list", xycb_dict_cache,60*5)
  521. return Response(result)
  522. class XycbDeviceDetailView(APIView):
  523. authentication_classes = [APIAuthentication]
  524. permission_classes = [XycbDeviceDetailPermission]
  525. throttle_classes = [DeviceDetailRateThrottle]
  526. def get(self, request, *args, **kwargs):
  527. serializer = DeviceDetailSerializer(data=request.query_params)
  528. serializer.is_valid(raise_exception=True)
  529. request_data = serializer.validated_data
  530. start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
  531. uid = request.user
  532. xycb_dict_cache = default_cache.get(str(uid)+"_xycb_list")
  533. if xycb_dict_cache:
  534. d_id = xycb_dict_cache[device_id]
  535. else:
  536. """避免缓存失效"""
  537. wheres = {
  538. 'device_type_id':4,
  539. '$or': [
  540. {'owner_uid': uid},
  541. {'user_dealer': uid}
  542. ]
  543. }
  544. project = {
  545. 'id': '$id',
  546. 'device_id': '$device_id'
  547. }
  548. m = MongoDBTools(db_name='smartfarming', table_name='sa_device')
  549. data = m.find_many(wheres=wheres, options=project)
  550. xycb_dict_cache = []
  551. for item in data:
  552. xycb_dict_cache[item["device_id"]]=item["id"]
  553. default_cache.set(str(uid)+"_scd_list", xycb_dict_cache,60*5)
  554. d_id = xycb_dict_cache[device_id]
  555. result = []
  556. data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xycb_data')
  557. data_wheres = {
  558. "device_id": d_id,
  559. "addtime": {"$gt":start_time}
  560. }
  561. data_project = {
  562. "addtime": "$addtime",
  563. "device_data": "$device_data"
  564. }
  565. data = data_m.find_many(wheres=data_wheres,options=data_project)
  566. for item in data:
  567. try:
  568. device_data = json.loads(item["device_data"])
  569. except:
  570. device_data = ast.literal_eval(item["device_data"])
  571. result.append({"uptime":item["addtime"],"item_data":device_data})
  572. return Response(result)