def getAndCompareAll(): # 从传感器中获取所有传感器数据 plantData = PlantData() for sensor in sensorList: sensor.read(plantData) if not RaspberryConfig._PLANTTYPE: print '该次检测无植物类型设定,不进行比较' return plantData # 持久化植物生长数据 DBUtil.addPlantData(plantData) # 与植物生长模型比较 # todo 从数据库中获取植物生长模型,目前根据植物种类获取 plantModel = getPlantModelByPlantType() compareResult = DataUtil.compare(plantData, plantModel) # 处理比较后的结果 doSthForCompareResult[compareResult.result_code]() detail = '' for key in compareResult.result: result = compareResult.result[key] detail += key + result.__str__() + '\r\n' result = '{} :本次读取植物环境数据为:{},结果为{}\r\n具体信息:{}'.format( Util.getCurrentTime(), plantData.__str__(), ResultEnum[compareResult.result_code], detail) print(result) print('-----------------------------') return result
def capturePic(filename=''): # 生成文件名(planttype+timestamp.jpg) if not filename: prifex = Util.getCurrentTime('%Y%m%d%H%M%S_') filename = prifex + RaspberryConfig._PLANTTYPE + PIC_SUFFIX piccamera.capture(filepath + filename) return filename
def recordVideo(time=10, filename=''): if not filename: prifex = Util.getCurrentTime('%Y%m%d%H%M%S_') filename = prifex + RaspberryConfig._PLANTTYPE + VIDEO_SUFFIX piccamera.resolution = (640, 480) piccamera.start_recording(filename) piccamera.wait_recording(time) piccamera.stop_recording()