def img_upload(self, device_mac, device_pos, created_at, meta): if device_mac == "": return False if device_pos == "": return False dev = Device() pos = Position_Image() #print "upload_img",device_mac,device_pos device_id = dev.get_device_by_mac(device_mac) position_id = pos.get_position_id(device_id, device_pos) print "upload", device_id, position_id upload_path = os.path.join(get_pwd_dir(), CAPTURED_DIR) filename = meta['filename'] filename = os.path.basename(filename) print filename, '----', upload_path filepath = os.path.join(upload_path, filename) with open(filepath, 'wb') as up: up.write(meta['body']) img = Image() img.path = filename img.position_id = position_id img.created_at = created_at img_id = img.create() r = redis.Redis() r.set('image_path_%s_%s' % (device_mac, device_pos), img.path) print img_id if not img_id: return False return True
def post(self): jdatas = json.loads(self.request.body) for jdata in jdatas: device_mac = jdata['mac'] data_content = jdata['data_content'] #insert the new data to redis r = redis.Redis() r.set("col_datas_%s" % (device_mac), data_content) #get the last table in redis and if there is not a record in redis and get the newest record in the table map index = r.get("last_data_table_index") if not index: index = Data_Table_Map.get_last_table_index() print "last index:", index dtm = Data_Table_Map.find_first("where `index`=?", int(index)) #print "add last index table!:----------",dtm.index if dtm == None: Data_Table_Map.add_table(index) #parse the data #insert into the table #if the line of table more than 20w records then create a new table and update table map in the database date = data_content['date'] content = data_content['content'] dev = Device() dev = dev.get_device_by_mac(device_mac) DataParser.get_instance().parse_dev(index, dev.id, dev.dev_type, content) self.write('ok')
def updateDevices(self, path): del self._devices[:] with open(path, 'r') as f: #'../Web/appserver/config/default.json' ln = f.read() devices = json.loads(ln) for device in devices: self._devices.append(Device(**device))
def start(self): hosts = [] if not ParseHostXml.parseHostXml(self._hostPath, hosts): self._logger.error("service : parse host xml file failed.") return -1 for host in hosts: channel = Channel(host) collectResult = CollectResult() collectResult.setHostName(host.getHostName()) collectResult.setIpAddress(host.getIpAddress()) deviceInfo = Device() errCode = self.__getDeviceInfo(channel, host, deviceInfo) if errCode != NAGIOS_ERROR_SUCCESS: self._logger.error( "service : get device info failed. host name:%s" % host.getHostName()) collectResult.setService({ service: errCode for service in (host.getCollectBasic() if ( COLLECT_MODE_CMD_PLUGIN == self._mode ) else host.getCollectExtension()) }) else: collectResult.setService( self.collect(channel, host, deviceInfo)) ProcessService.start(self._mode, self._targetPath, collectResult) return 0
def step_impl(context): context.room_2.device_list = [Device(21, c.INFINITY, False)] context.event_manager = EventObserver(context.room_2, context.mock_clientMqtt_2) context.event_manager.mqtt_manager.publish_urgent_msg_to_server = MagicMock() context.room_2.attach_observer(context.event_manager) context.dpop_to_test = DpopRoom(context.room_2, context.mock_clientMqtt_2)
def get(address): device_manager = app.config['DEVICE_MANAGER'] device_state = find_device_state_by_address(address, device_manager) if device_state is not None: response = device_state['device'].to_json_response(time.time()) else: response = Device( address=address, error_code='Device is not found').to_json_response(time.time()) return jsonify(response)
def __init__(self): self._dispatcher = DeviceDispatcher() if len(sys.argv) < 2: raise ValueError('parameter must be dispatcher virtual device ID') self._device = Device(sys.argv[1], SignalSource='queue') if (not self._device.SignalSource == ''): self._signalSource = SignalSourceFactory.createInstance( self._device.SignalSource) self._signalSource.set_signal_received(self.on_signal_received)
def __init__(self, properties: SimulationProperties): self.__stats = Stats(properties.num_sources, properties.num_devices) self.__generators = [ Generator(i, l, self.__stats) for i, l in enumerate(properties.source_lambdas) ] self.__devices = [ Device(i, t, self.__stats) for i, t in enumerate(properties.device_taus) ] self.__buffer = Buffer(properties.buffer_capacity, self.__stats) self.__max_requests = properties.max_requests self.__global_time = 0
def step_impl(context): context.room_2.device_list = [Device(11, 40, False)] context.room_2.tau = 80 context.dpop_to_test = DpopRoom(context.room_2, context.mock_clientMqtt_2) assert_that( not context.dpop_to_test.monitored_area.device_list[0]. is_in_critic_state, 'device not in critical state') assert_that( context.dpop_to_test.monitored_area.device_list[0].end_of_prog > 30, 'device end its program too soon') assert_that(context.dpop_to_test.monitored_area.tau < 180, 'previous intervention is too recent')
def get_all(): # get query parameter scan = int(request.args.get('scan')) device_manager = app.config['DEVICE_MANAGER'] devices = list( map(lambda device_state: device_state['device'], device_manager)) logging.info(devices) if scan == 1: scanner = MetaWearScanner() addresses = scanner.scan() devices += [ Device(address=address, status='stopped') for address in addresses ] response = Device.to_json_responses(*devices, timestamp=time.time()) return jsonify(response), 200
def step_impl(context): context.dpop_to_test.monitored_area.tau = 181 context.dpop_to_test.monitored_area.device_list = [ Device(1, 240, False), Device(2, 240, False), Device(3, 240, False), Device(4, 240, False), Device(5, 240, False), Device(6, 240, False) ]
def _stop(address, device_manager): device_state = find_device_state_by_address(address, device_manager) if device_state is not None: stop_signal = device_state['stop_signal'] state = device_state['state'] p = device_state['process'] device = device_state['device'] stop_signal.set() while state.value != 'stopped': pass p.terminate() device.status = state.value remove_device_state_by_address(address, device_manager) logging.info('Stop a sensor: ' + address) else: device = Device(address=address, error_code='Device not found') logging.info('Sensor is not found') return device
def add_or_update_device(self): id_device = str(self.id) + str(len(self.device_list) + 1) critic_state = random() < 0.05 self.device_list.append( Device(int(id_device), randint(c.MIN_TAU_VALUE, c.INFINITY), critic_state))
from model.device import Device from model.device_observed import Device_Observed from model.image import Image from model.position import Position_Image from model.data import Data, Data_Table_Map from model.user import User import sys def connect_db(): import transwarp.db as dbutil dbutil.create_engine('sonic513', 'sonic513', 'co2_monitor', port=3306) if __name__=="__main__": connect_db() dev = Device() dev.create_table() usr = User() usr.create_table() doed = Device_Observed() doed.create_table() dtm = Data_Table_Map() dtm.create_table() #img = Image() #img.create_table() #pos_image = Position_Image() #pos_image.create_table() #data = Data() #data.create_table()
def getLightDevice(self, deviceID): device = Device(ID=deviceID) return device
# coding=utf-8 from model.device import Device import sys def connect_db(): import transwarp.db as dbutil dbutil.create_engine('sonic513', 'sonic513', 'tobacco_monitor', port=3306) if __name__ == "__main__": connect_db() location = sys.argv[1] mac = sys.argv[2] dev_type = sys.argv[3] dev = Device(location=location, mac=mac, dev_type=dev_type) id = dev.create() if id: print "add dev %s OK!" % mac else: print "add dev error!"
def __init__(self): self.device_model = Device()
def step_impl(context): context.dpop_to_test.monitored_area.device_list = [ Device(1, 30, False), Device(2, 241, True) ]
def step_impl(context): context.dpop_to_test.monitored_area.device_list = [Device(1, 29, False)] context.dpop_to_test.monitored_area.tau = 60