#!/usr/bin/env python # -*- coding: utf-8 -*- """ demeter web name:device.py 设备相关 author:rabin """ from __load__ import * class index_path(Load): """ @api {get} /device 获取网关首页信息 @apiVersion 1.0.0 @apiName getDevice @apiGroup Device @apiParam {String} id 网关id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Bool} info.status 网关状态 @apiSuccess {Number} info.power 电量 @apiSuccess {Object[]} device 设备数据 @apiSuccess {Number} device.id 设备ID @apiSuccess {String} device.name 设备名称 @apiSuccess {String} device.show 显示的数据 @apiSuccess {String} device.unit 设备的单位 @apiSuccess {Number} device.max 设备的上限 @apiSuccess {Number} device.min 设备的下限 @apiSuccess {Bool} device.status 设备状态 @apiSuccess {Object[]} pic 图像数据 @apiSuccess {Number} pic.id 图片ID @apiSuccess {String} pic.name 图片名称 @apiSuccess {String} pic.show 图片地址 @apiSuccess {String} pic.cdates 采集时间 @apiSuccess {String} pic.cdate 采集时间戳 @apiErrorExample 操作成功 {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "device": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100009, "name": "\u6e7f\u5ea6#100009", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253837, "state": true, "num": 30, "status": true, "min": 0, "show": "30", "id": "6d8a4c0e-4f85-524a-87f8-382c333c44da", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100000, "name": "\u6e7f\u5ea6#100000", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253836, "state": true, "num": 5, "status": true, "min": 0, "show": "5", "id": "d644b079-9d4d-521c-8e65-8940c96ba9a7", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "min": 0, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100004, "name": "\u6e7f\u5ea6#100004", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253834, "state": true, "num": 17, "status": true, "min": 0, "show": "17", "id": "62199416-cca0-5114-b900-a10f51e7e447", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100005, "name": "\u6e7f\u5ea6#100005", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253833, "state": true, "num": 7, "status": true, "min": 0, "show": "7", "id": "456daa98-a1f0-59e6-a337-7ca1fa7b2527", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100003, "name": "\u6e7f\u5ea6#100003", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253832, "state": true, "num": 39, "status": true, "min": 0, "show": "39", "id": "11bd4ad1-b4ff-5b1f-948a-935d859b408c", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100007, "name": "\u6e7f\u5ea6#100007", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253828, "state": true, "num": 43, "status": true, "min": 0, "show": "43", "id": "f8e3a42a-7fa3-575a-b99e-2dab4f992239", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100010, "name": "\u6e7f\u5ea6#100010", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253827, "state": true, "num": 20, "status": true, "min": 0, "show": "20", "id": "138876d7-1710-56fa-824b-10402cba17f8", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100002, "name": "\u6e7f\u5ea6#100002", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253826, "state": true, "num": 43, "status": true, "min": 0, "show": "43", "id": "eecfe61f-de83-588f-8cbd-41519d4ebef3", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100006, "name": "\u6e7f\u5ea6#100006", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253818, "state": true, "num": 4, "status": true, "min": 0, "show": "4", "id": "78bd90ac-6af3-5091-83e5-f3397063f743", "unit": "%RH"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100008, "name": "\u6e7f\u5ea6#100008", "type_id": 2, "max": 0, "farm_id": 1, "cdate": 1504253815, "state": true, "num": 37, "status": true, "min": 0, "show": "37", "id": "5fda8633-aed8-5a3b-8175-2c61e7553d91", "unit": "%RH"}], "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "pic": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 5, "hardware_id": 200001, "name": "pic.jpg", "type_id": null, "farm_id": 1, "cdate": 1504262668, "cdates": "2017-09-01 10:44:28", "state": true, "num": 0, "status": true, "show": "/camera/2017/09/01/01c323ac0208580601252e2ce9eb3286.jpg", "id": "2f612150-f670-54e9-9886-a044cfb18e20"}]}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def get(self): id = self.input('id', None) if id: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}) if self.data['device']: for key, value in enumerate(self.data['device']): type = self.service('common').one('device_type', id=value['type_id']) self.data['device'][key]['unit'] = type['unit'] set = self.service('common').one('device_set', device_id=value['id']) if set: self.data['device'][key]['max'] = set['max'] self.data['device'][key]['min'] = set['min'] else: self.data['device'][key]['max'] = 0 self.data['device'][key]['min'] = 0 self.data['pic'] = self.service('common').list('device_info', state=True, search={'hardware_type':5, 'gateway_id':id}) if self.data['pic']: for key, value in enumerate(self.data['pic']): self.data['pic'][key]['cdates'] = Demeter.date(value['cdate']) self.out('yes', self.data) else: self.out('no') class stat_path(Load): """ @api {get} /device/stat 获取数据统计 @apiVersion 1.0.0 @apiName getDeviceStat @apiGroup Device @apiParam {String} id 网关id @apiParam {String} device 设备id @apiParam {String} search_group 周期ID @apiParam {String} search_start 开始时间:2017-10-10 10:10:10 @apiParam {String} search_end 结束时间:2017-10-10 10:10:10 @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Object[]} data 设备选择 @apiSuccess {Number} data.id 设备ID @apiSuccess {String} data.name 设备名称 @apiSuccess {Object[]} group 周期选择 @apiSuccess {Number} group.id 周期ID @apiSuccess {String} group.name 周期名称 @apiSuccess {Object[]} cur_device 当前选择的设备 @apiSuccess {Number} cur_device.id 设备ID @apiSuccess {String} cur_device.name 设备名称 @apiSuccess {Object[]} data 设备数据,两条线 @apiSuccess {String} data.name 本条数据名 @apiSuccess {Object[]} data.data 本条数据的具体数据 @apiSuccess {String} data.data.time 数据时间 @apiSuccess {String} data.data.value 数据具体的值 @apiSuccess {Object[]} search 当前搜索的值 @apiSuccess {String} search.group 周期的值 @apiSuccess {String} search.start 开始时间 @apiSuccess {String} search.end 结束时间 @apiErrorExample 操作成功 {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "search": {"group": "1"}, "group": [{"id": "1", "name": "\u4e00\u5929"}, {"id": "7", "name": "\u4e00\u5468"}, {"id": "30", "name": "\u4e00\u4e2a\u6708"}, {"id": "180", "name": "\u534a\u5e74"}], "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "cur_device": {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": "", "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}, "device": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100009, "name": "\u6e7f\u5ea6#100009", "type_id": 2, "farm_id": 1, "cdate": 1504253837, "state": true, "num": 30, "status": true, "show": "30", "id": "6d8a4c0e-4f85-524a-87f8-382c333c44da"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100000, "name": "\u6e7f\u5ea6#100000", "type_id": 2, "farm_id": 1, "cdate": 1504253836, "state": true, "num": 5, "status": true, "show": "5", "id": "d644b079-9d4d-521c-8e65-8940c96ba9a7"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100004, "name": "\u6e7f\u5ea6#100004", "type_id": 2, "farm_id": 1, "cdate": 1504253834, "state": true, "num": 17, "status": true, "show": "17", "id": "62199416-cca0-5114-b900-a10f51e7e447"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100005, "name": "\u6e7f\u5ea6#100005", "type_id": 2, "farm_id": 1, "cdate": 1504253833, "state": true, "num": 7, "status": true, "show": "7", "id": "456daa98-a1f0-59e6-a337-7ca1fa7b2527"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100003, "name": "\u6e7f\u5ea6#100003", "type_id": 2, "farm_id": 1, "cdate": 1504253832, "state": true, "num": 39, "status": true, "show": "39", "id": "11bd4ad1-b4ff-5b1f-948a-935d859b408c"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100007, "name": "\u6e7f\u5ea6#100007", "type_id": 2, "farm_id": 1, "cdate": 1504253828, "state": true, "num": 43, "status": true, "show": "43", "id": "f8e3a42a-7fa3-575a-b99e-2dab4f992239"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100010, "name": "\u6e7f\u5ea6#100010", "type_id": 2, "farm_id": 1, "cdate": 1504253827, "state": true, "num": 20, "status": true, "show": "20", "id": "138876d7-1710-56fa-824b-10402cba17f8"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100002, "name": "\u6e7f\u5ea6#100002", "type_id": 2, "farm_id": 1, "cdate": 1504253826, "state": true, "num": 43, "status": true, "show": "43", "id": "eecfe61f-de83-588f-8cbd-41519d4ebef3"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100006, "name": "\u6e7f\u5ea6#100006", "type_id": 2, "farm_id": 1, "cdate": 1504253818, "state": true, "num": 4, "status": true, "show": "4", "id": "78bd90ac-6af3-5091-83e5-f3397063f743"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": null, "hardware_type": 2, "hardware_id": 100008, "name": "\u6e7f\u5ea6#100008", "type_id": 2, "farm_id": 1, "cdate": 1504253815, "state": true, "num": 37, "status": true, "show": "37", "id": "5fda8633-aed8-5a3b-8175-2c61e7553d91"}], "data": [{"data": {"rows": [["2017-09-01 11:15:00", 45], ["2017-09-01 11:20:00", 50], ["2017-09-01 11:25:00", 49], ["2017-09-01 11:30:00", 49], ["2017-09-01 11:35:00", 50], ["2017-09-01 11:40:00", 48], ["2017-09-01 11:45:00", 49], ["2017-09-01 11:50:00", 47], ["2017-09-01 11:55:00", 49], ["2017-09-01 12:00:00", 49], ["2017-09-01 12:05:00", 47], ["2017-09-01 12:10:00", 50], ["2017-09-01 12:15:00", 49], ["2017-09-01 12:20:00", 50], ["2017-09-01 12:25:00", 48], ["2017-09-01 12:30:00", 50], ["2017-09-01 12:35:00", 48], ["2017-09-01 12:40:00", 50], ["2017-09-01 12:45:00", 47], ["2017-09-01 12:50:00", 50], ["2017-09-01 12:55:00", 49], ["2017-09-01 13:00:00", 46], ["2017-09-01 13:05:00", 50], ["2017-09-01 13:10:00", 50], ["2017-09-01 13:15:00", 49], ["2017-09-01 13:20:00", 50], ["2017-09-01 13:25:00", 49], ["2017-09-01 13:30:00", 50], ["2017-09-01 13:35:00", 50], ["2017-09-01 13:40:00", 48], ["2017-09-01 13:45:00", 49], ["2017-09-01 13:50:00", 49], ["2017-09-01 13:55:00", 49], ["2017-09-01 14:00:00", 49], ["2017-09-01 14:05:00", 47], ["2017-09-01 14:10:00", 49], ["2017-09-01 14:15:00", 48], ["2017-09-01 14:20:00", 45], ["2017-09-01 14:25:00", 50], ["2017-09-01 14:30:00", 50], ["2017-09-01 14:35:00", 49], ["2017-09-01 14:40:00", 49], ["2017-09-01 14:45:00", 49], ["2017-09-01 14:50:00", 49], ["2017-09-01 14:55:00", 47], ["2017-09-01 15:00:00", 49], ["2017-09-01 15:05:00", 50], ["2017-09-01 15:10:00", 49], ["2017-09-01 15:15:00", 47], ["2017-09-01 15:25:00", 50], ["2017-09-01 15:30:00", 50], ["2017-09-01 15:35:00", 49], ["2017-09-01 15:40:00", 49], ["2017-09-01 15:45:00", 49], ["2017-09-01 15:50:00", 48], ["2017-09-01 15:55:00", 47], ["2017-09-01 16:05:00", 46], ["2017-09-01 16:10:00", 49], ["2017-09-01 16:15:00", 49]], "value": "[45, 50, 49, 49, 50, 48, 49, 47, 49, 49, 47, 50, 49, 50, 48, 50, 48, 50, 47, 50, 49, 46, 50, 50, 49, 50, 49, 50, 50, 48, 49, 49, 49, 49, 47, 49, 48, 45, 50, 50, 49, 49, 49, 49, 47, 49, 50, 49, 47, 50, 50, 49, 49, 49, 48, 47, 46, 49, 49]", "time": "[\"2017-09-01 11:15:00\", \"2017-09-01 11:20:00\", \"2017-09-01 11:25:00\", \"2017-09-01 11:30:00\", \"2017-09-01 11:35:00\", \"2017-09-01 11:40:00\", \"2017-09-01 11:45:00\", \"2017-09-01 11:50:00\", \"2017-09-01 11:55:00\", \"2017-09-01 12:00:00\", \"2017-09-01 12:05:00\", \"2017-09-01 12:10:00\", \"2017-09-01 12:15:00\", \"2017-09-01 12:20:00\", \"2017-09-01 12:25:00\", \"2017-09-01 12:30:00\", \"2017-09-01 12:35:00\", \"2017-09-01 12:40:00\", \"2017-09-01 12:45:00\", \"2017-09-01 12:50:00\", \"2017-09-01 12:55:00\", \"2017-09-01 13:00:00\", \"2017-09-01 13:05:00\", \"2017-09-01 13:10:00\", \"2017-09-01 13:15:00\", \"2017-09-01 13:20:00\", \"2017-09-01 13:25:00\", \"2017-09-01 13:30:00\", \"2017-09-01 13:35:00\", \"2017-09-01 13:40:00\", \"2017-09-01 13:45:00\", \"2017-09-01 13:50:00\", \"2017-09-01 13:55:00\", \"2017-09-01 14:00:00\", \"2017-09-01 14:05:00\", \"2017-09-01 14:10:00\", \"2017-09-01 14:15:00\", \"2017-09-01 14:20:00\", \"2017-09-01 14:25:00\", \"2017-09-01 14:30:00\", \"2017-09-01 14:35:00\", \"2017-09-01 14:40:00\", \"2017-09-01 14:45:00\", \"2017-09-01 14:50:00\", \"2017-09-01 14:55:00\", \"2017-09-01 15:00:00\", \"2017-09-01 15:05:00\", \"2017-09-01 15:10:00\", \"2017-09-01 15:15:00\", \"2017-09-01 15:25:00\", \"2017-09-01 15:30:00\", \"2017-09-01 15:35:00\", \"2017-09-01 15:40:00\", \"2017-09-01 15:45:00\", \"2017-09-01 15:50:00\", \"2017-09-01 15:55:00\", \"2017-09-01 16:05:00\", \"2017-09-01 16:10:00\", \"2017-09-01 16:15:00\"]"}, "name": "\u6700\u9ad8"}, {"data": {"rows": [["2017-09-01 11:15:00", 3], ["2017-09-01 11:20:00", 3], ["2017-09-01 11:25:00", 1], ["2017-09-01 11:30:00", 1], ["2017-09-01 11:35:00", 1], ["2017-09-01 11:40:00", 2], ["2017-09-01 11:45:00", 2], ["2017-09-01 11:50:00", 1], ["2017-09-01 11:55:00", 3], ["2017-09-01 12:00:00", 3], ["2017-09-01 12:05:00", 1], ["2017-09-01 12:10:00", 1], ["2017-09-01 12:15:00", 2], ["2017-09-01 12:20:00", 1], ["2017-09-01 12:25:00", 1], ["2017-09-01 12:30:00", 2], ["2017-09-01 12:35:00", 1], ["2017-09-01 12:40:00", 3], ["2017-09-01 12:45:00", 1], ["2017-09-01 12:50:00", 4], ["2017-09-01 12:55:00", 1], ["2017-09-01 13:00:00", 3], ["2017-09-01 13:05:00", 1], ["2017-09-01 13:10:00", 1], ["2017-09-01 13:15:00", 1], ["2017-09-01 13:20:00", 7], ["2017-09-01 13:25:00", 1], ["2017-09-01 13:30:00", 1], ["2017-09-01 13:35:00", 1], ["2017-09-01 13:40:00", 1], ["2017-09-01 13:45:00", 1], ["2017-09-01 13:50:00", 4], ["2017-09-01 13:55:00", 5], ["2017-09-01 14:00:00", 2], ["2017-09-01 14:05:00", 2], ["2017-09-01 14:10:00", 3], ["2017-09-01 14:15:00", 4], ["2017-09-01 14:20:00", 1], ["2017-09-01 14:25:00", 1], ["2017-09-01 14:30:00", 1], ["2017-09-01 14:35:00", 1], ["2017-09-01 14:40:00", 2], ["2017-09-01 14:45:00", 2], ["2017-09-01 14:50:00", 2], ["2017-09-01 14:55:00", 1], ["2017-09-01 15:00:00", 1], ["2017-09-01 15:05:00", 1], ["2017-09-01 15:10:00", 1], ["2017-09-01 15:15:00", 1], ["2017-09-01 15:25:00", 3], ["2017-09-01 15:30:00", 1], ["2017-09-01 15:35:00", 1], ["2017-09-01 15:40:00", 9], ["2017-09-01 15:45:00", 2], ["2017-09-01 15:50:00", 5], ["2017-09-01 15:55:00", 8], ["2017-09-01 16:05:00", 5], ["2017-09-01 16:10:00", 1], ["2017-09-01 16:15:00", 4]], "value": "[3, 3, 1, 1, 1, 2, 2, 1, 3, 3, 1, 1, 2, 1, 1, 2, 1, 3, 1, 4, 1, 3, 1, 1, 1, 7, 1, 1, 1, 1, 1, 4, 5, 2, 2, 3, 4, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 3, 1, 1, 9, 2, 5, 8, 5, 1, 4]", "time": "[\"2017-09-01 11:15:00\", \"2017-09-01 11:20:00\", \"2017-09-01 11:25:00\", \"2017-09-01 11:30:00\", \"2017-09-01 11:35:00\", \"2017-09-01 11:40:00\", \"2017-09-01 11:45:00\", \"2017-09-01 11:50:00\", \"2017-09-01 11:55:00\", \"2017-09-01 12:00:00\", \"2017-09-01 12:05:00\", \"2017-09-01 12:10:00\", \"2017-09-01 12:15:00\", \"2017-09-01 12:20:00\", \"2017-09-01 12:25:00\", \"2017-09-01 12:30:00\", \"2017-09-01 12:35:00\", \"2017-09-01 12:40:00\", \"2017-09-01 12:45:00\", \"2017-09-01 12:50:00\", \"2017-09-01 12:55:00\", \"2017-09-01 13:00:00\", \"2017-09-01 13:05:00\", \"2017-09-01 13:10:00\", \"2017-09-01 13:15:00\", \"2017-09-01 13:20:00\", \"2017-09-01 13:25:00\", \"2017-09-01 13:30:00\", \"2017-09-01 13:35:00\", \"2017-09-01 13:40:00\", \"2017-09-01 13:45:00\", \"2017-09-01 13:50:00\", \"2017-09-01 13:55:00\", \"2017-09-01 14:00:00\", \"2017-09-01 14:05:00\", \"2017-09-01 14:10:00\", \"2017-09-01 14:15:00\", \"2017-09-01 14:20:00\", \"2017-09-01 14:25:00\", \"2017-09-01 14:30:00\", \"2017-09-01 14:35:00\", \"2017-09-01 14:40:00\", \"2017-09-01 14:45:00\", \"2017-09-01 14:50:00\", \"2017-09-01 14:55:00\", \"2017-09-01 15:00:00\", \"2017-09-01 15:05:00\", \"2017-09-01 15:10:00\", \"2017-09-01 15:15:00\", \"2017-09-01 15:25:00\", \"2017-09-01 15:30:00\", \"2017-09-01 15:35:00\", \"2017-09-01 15:40:00\", \"2017-09-01 15:45:00\", \"2017-09-01 15:50:00\", \"2017-09-01 15:55:00\", \"2017-09-01 16:05:00\", \"2017-09-01 16:10:00\", \"2017-09-01 16:15:00\"]"}, "name": "\u6700\u4f4e"}]}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def get(self): id = self.input('id', None) device = self.input('device', None) if id and device: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['cur_device'] = self.service('common').one('device_info', id=device) if not self.data['cur_device']: self.out('no') return self.data['device'] = self.service('common').list('device_info', state=True, search={'hardware_type':2, 'gateway_id':id}) model = Demeter.model('data', 'tsdb') self.data['group'] = model.dateConfig() search_group = self.input('search_group') search_start = self.input('search_start') search_end = self.input('search_end') search = {} if search_group: search['group'] = search_group else: search['group'] = '1' if search_start: search['start'] = search_start if search_end: search['end'] = search_end method = 'maxmin' self.data['search'] = search self.data['data'] = model.getData(method, search, self.data['cur_device']) self.out('yes', self.data) else: self.out('no') class pic_path(Load): """ @api {get} /device/pic 获取图像记录 @apiVersion 1.0.0 @apiName getDevicePic @apiGroup Device @apiParam {String} page 页数 @apiParam {String} id 网关id @apiParam {String} search_date 拍照时间:2017-10-10 @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} info 网关状态基本信息 @apiSuccess {String} info.id 网关ID @apiSuccess {String} info.name 网关名称 @apiSuccess {Object[]} pic 图像数据 @apiSuccess {Number} pic.id 图片ID @apiSuccess {String} pic.name 图片名称 @apiSuccess {String} pic.show 图片地址 @apiSuccess {String} pic.cdates 采集时间 @apiSuccess {String} pic.cdate 采集时间戳 @apiSuccess {Object[]} search 当前搜索的值 @apiSuccess {String} search.date 拍照时间 @apiSuccess {String} url 网站url @apiSuccess {Object[]} page 分页信息 @apiSuccess {String} page.current 当前页 @apiSuccess {String} page.total 总页数 @apiSuccess {String} page.num 每页数据条数 @apiSuccess {String} page.totalNum 总数据条数 @apiErrorExample 操作成功 {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "url": "http://192.168.15.10:8088/", "pic": [{"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/01c323ac0208580601252e2ce9eb3286.jpg", "farm_id": 1, "cdate": 1504262668, "cdates": "2017-09-01 10:44:28", "state": true, "id": "5ea5d688-e092-5131-a382-686298da4f94", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/f5e1509cf0d6b1cb2f048a058dabd75b.jpg", "farm_id": 1, "cdate": 1504262666, "cdates": "2017-09-01 10:44:26", "state": true, "id": "bd36fa61-5210-57c5-b8b8-a81e5797ee85", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}, {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "pic": "/camera/2017/09/01/8f3a6d9d614cd280d2cb4a78f90d121a.jpg", "farm_id": 1, "cdate": 1504262665, "cdates": "2017-09-01 10:44:25", "state": true, "id": "162ac864-b2e9-5a7a-84cb-ac57e31ef99c", "device_id": "2f612150-f670-54e9-9886-a044cfb18e20"}], "search_date": null, "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 3}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def get(self): id = self.input('id', None) if id: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['url'] = self.request.protocol + "://" + self.request.host + '/' self.data['search_date'] = self.input('search_date') search = {} search['gateway_id'] = id if self.data['search_date']: search['cdate'] = Demeter.mktime(self.data['search_date']) self.data['pic'] = self.service('common').list('device_pic', state=True, search=search, page=True) if self.data['pic']: for key, value in enumerate(self.data['pic']): self.data['pic'][key]['cdates'] = Demeter.date(value['cdate']) self.out('yes', self.data) else: self.out('no') class msg_path(Load): """ @api {get} /device/msg 获取设备日志 @apiVersion 1.0.0 @apiName getDeviceMsg @apiGroup Device @apiParam {String} page 页数 @apiParam {String} id 网关id @apiParam {String} device 设备id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} msg 日志列表 @apiSuccess {Number} msg.id 日志ID @apiSuccess {String} msg.content 日志内容 @apiSuccess {String} msg.cdates 日志时间 @apiSuccess {String} msg.cdate 日志时间戳 @apiSuccess {Object[]} page 分页信息 @apiSuccess {String} page.current 当前页 @apiSuccess {String} page.total 总页数 @apiSuccess {String} page.num 每页数据条数 @apiSuccess {String} page.totalNum 总数据条数 @apiErrorExample 操作成功 {"status": 1, "msg": "yes", "code": 0, "data": {"info": {"status": true, "hardware_id": 10086, "name": "\u9ed8\u8ba4\u7f51\u5173", "farm_id": 1, "cdate": 1504233947, "state": true, "power_num": "", "power_status": "", "id": "ce37636b-3ce7-5de2-9160-0f3283f7d392"}, "msg": [], "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "cur_device": {"gateway_id": "ce37636b-3ce7-5de2-9160-0f3283f7d392", "hardware_station": "", "hardware_type": 2, "hardware_id": 100001, "name": "\u6e7f\u5ea6#100001", "type_id": 2, "farm_id": 1, "cdate": 1504253835, "state": true, "num": 4, "status": true, "show": "4", "id": "dc24428c-eafc-5715-b7d1-f3222d28c3bb"}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def get(self): id = self.input('id', None) device = self.input('device', None) if id and device: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['cur_device'] = self.service('common').one('device_info', id=device) if not self.data['cur_device']: self.out('no') return search = {} search['device_id'] = device self.data['msg'] = self.service('common').list('msg', state=True, search=search, page=True) if self.data['msg']: for key, value in enumerate(self.data['msg']): self.data['msg'][key]['cdates'] = Demeter.date(value['cdate']) self.out('yes', self.data) else: self.out('no') class set_path(Load): """ @api {get} /device/set 获取设备极限值信息 @apiVersion 1.0.0 @apiName getDeviceSet @apiGroup Device @apiParam {String} id 网关id @apiParam {String} device 设备id @apiSuccess {Object[]} setting 基本信息 @apiSuccess {String} setting.name 站点名 @apiSuccess {Number} setting.farm 当前的农场ID @apiSuccess {Object[]} device 设备数据 @apiSuccess {Number} device.id 设备ID @apiSuccess {String} device.name 设备名称 @apiSuccess {String} device.show 显示的数据 @apiSuccess {String} device.unit 设备的单位 @apiSuccess {Number} device.max 设备的上限 @apiSuccess {Number} device.min 设备的下限 @apiSuccess {Bool} device.status 设备状态 @apiErrorExample 操作成功 {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def get(self): id = self.input('id', None) device = self.input('device', None) if id and device: self.data['info'] = self.service('common').one('device_gateway', id=id) if not self.data['info']: self.out('no') return self.data['device'] = self.service('common').one('device_info', id=device) if not self.data['device']: self.out('no') return type = self.service('common').one('device_type', id=self.data['device']['type_id']) self.data['device']['unit'] = type['unit'] set = self.service('common').one('device_set', device_id=self.data['device']['id']) if set: self.data['device']['max'] = set['max'] self.data['device']['min'] = set['min'] else: self.data['device']['max'] = 0 self.data['device']['min'] = 0 self.out('yes', self.data) else: self.out('no') """ @api {post} /device/set 更新极限值设置 @apiVersion 1.0.0 @apiName updateDeviceSet @apiGroup Farm @apiParam {String} id 设备id @apiParam {String} update_max 最大上限 @apiParam {String} update_min 最小下限 @apiSuccess {Bool} status 状态 @apiSuccess {String} msg 描述 @apiSuccess {Number} code 状态码 @apiErrorExample 操作成功 {"status": 1, "msg": "操作成功", "code": 0, "data": {}} @apiErrorExample 操作失败 {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}} """ @auth def post(self): id = self.input('id', None) if not id: self.out('no') return device = self.service('common').one('device_info', id=id) if not self.data['device']: self.out('no') return update = {} update['max'] = self.input('update_max') update['min'] = self.input('update_min') if not update['max']: self.out(u'请输入最大上限') return if not update['min']: self.out(u'请输入最小下限') return data = self.service('common').one('device_info', id=id) if not data: state = self.service('common').update('device_info', None, update) else: state = self.service('common').update('device_info', data['id'], update) self.out('yes', {'id':state})