def __init__(self, ip, port): self.ip = ip self.port = port self.client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.client.bind((ip, port)) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.paths = [ '/muse/eeg', '/muse/acc', '/muse/elements/experimental/concentration', '/muse/elements/experimental/mellow' ] for path in self.paths: self.batches[path] = {}
class MuseClient(object): def __init__(self, ip, port): self.ip = ip self.port = port self.client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.client.bind((ip, port)) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.paths = [ '/muse/eeg', '/muse/acc', '/muse/elements/experimental/concentration', '/muse/elements/experimental/mellow' ] for path in self.paths: self.batches[path] = {} def listen(self): while 1: data, addr = self.client.recvfrom(1024) value = json.loads(data) path = value[0] if path in self.paths: row_key, column = convert_muse_data_to_cassandra_column( path, value) if len(self.batches[path]) < BATCH_MAX_SIZE: self.batches[path][row_key] = column # time stats timestamp = row_key.split('_')[1] #print "column added to batch for %s -- %s ms" % (path, timestamp) elif len(self.batches[path]) == BATCH_MAX_SIZE: self.muse_cassandra_repo.add_batch(self.batches[path]) self.batches[path] = {} # time stats timestamp = row_key.split('_')[1] print "column batch stored in cassandra for %s -- %s ms" % ( path, timestamp)
class MuseClient(object): def __init__(self, ip, port): self.ip = ip self.port = port self.client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.client.bind((ip, port)) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.paths = ['/muse/eeg', '/muse/acc', '/muse/elements/experimental/concentration', '/muse/elements/experimental/mellow'] for path in self.paths: self.batches[path] = {} def listen(self): while 1: data, addr = self.client.recvfrom(1024) value = json.loads(data) path = value[0] if path in self.paths: row_key, column = convert_muse_data_to_cassandra_column(path, value) if len(self.batches[path]) < BATCH_MAX_SIZE: self.batches[path][row_key] = column # time stats timestamp = row_key.split('_')[1] #print "column added to batch for %s -- %s ms" % (path, timestamp) elif len(self.batches[path]) == BATCH_MAX_SIZE: self.muse_cassandra_repo.add_batch(self.batches[path]) self.batches[path] = {} # time stats timestamp = row_key.split('_')[1] print "column batch stored in cassandra for %s -- %s ms" % (path, timestamp)
def __init__(self, ip, port): self.ip = ip self.port = port self.client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.client.bind((ip, port)) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.paths = ['/muse/eeg', '/muse/acc', '/muse/elements/experimental/concentration', '/muse/elements/experimental/mellow'] for path in self.paths: self.batches[path] = {}
def __init__(self, name, server): # get app name and server from query string self.name = name server = server # configure the spacebrew client self.brew = SpacebrewApp(name, server=server) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.osc_paths = [ {'address': "/muse/eeg", 'arguments': 4}, {'address': "/muse/eeg/quantization", 'arguments': 4}, {'address': "/muse/eeg/dropped_samples", 'arguments': 1}, {'address': "/muse/acc", 'arguments': 3}, {'address': "/muse/acc/dropped_samples", 'arguments': 1}, {'address': "/muse/batt", 'arguments': 4}, {'address': "/muse/drlref", 'arguments': 2}, {'address': "/muse/elements/low_freqs_absolute", 'arguments': 4}, {'address': "/muse/elements/delta_absolute", 'arguments': 4}, {'address': "/muse/elements/theta_absolute", 'arguments': 4}, {'address': "/muse/elements/alpha_absolute", 'arguments': 4}, {'address': "/muse/elements/beta_absolute", 'arguments': 4}, {'address': "/muse/elements/gamma_absolute", 'arguments': 4}, {'address': "/muse/elements/delta_relative", 'arguments': 4}, {'address': "/muse/elements/theta_relative", 'arguments': 4}, {'address': "/muse/elements/alpha_relative", 'arguments': 4}, {'address': "/muse/elements/beta_relative", 'arguments': 4}, {'address': "/muse/elements/gamma_relative", 'arguments': 4}, {'address': "/muse/elements/delta_session_score", 'arguments': 4}, {'address': "/muse/elements/theta_session_score", 'arguments': 4}, {'address': "/muse/elements/alpha_session_score", 'arguments': 4}, {'address': "/muse/elements/beta_session_score", 'arguments': 4}, {'address': "/muse/elements/gamma_session_score", 'arguments': 4}, {'address': "/muse/elements/touching_forehead", 'arguments': 1}, {'address': "/muse/elements/horseshoe", 'arguments': 4}, {'address': "/muse/elements/is_good", 'arguments': 4}, {'address': "/muse/elements/blink", 'arguments': 1}, {'address': "/muse/elements/jaw_clench", 'arguments': 1}, {'address': "/muse/elements/experimental/concentration", 'arguments': 1}, {'address': "/muse/elements/experimental/mellow", 'arguments': 1} ] for path in self.osc_paths: spacebrew_name = path['address'].split('/')[-1] self.brew.add_subscriber(spacebrew_name, "string") self.brew.subscribe(spacebrew_name, self.handle_value)
class SpacebrewClient(object): def __init__(self, name, server): # get app name and server from query string self.name = name server = server # configure the spacebrew client self.brew = SpacebrewApp(name, server=server) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.osc_paths = [ {'address': "/muse/eeg", 'arguments': 4}, {'address': "/muse/eeg/quantization", 'arguments': 4}, {'address': "/muse/eeg/dropped_samples", 'arguments': 1}, {'address': "/muse/acc", 'arguments': 3}, {'address': "/muse/acc/dropped_samples", 'arguments': 1}, {'address': "/muse/batt", 'arguments': 4}, {'address': "/muse/drlref", 'arguments': 2}, {'address': "/muse/elements/low_freqs_absolute", 'arguments': 4}, {'address': "/muse/elements/delta_absolute", 'arguments': 4}, {'address': "/muse/elements/theta_absolute", 'arguments': 4}, {'address': "/muse/elements/alpha_absolute", 'arguments': 4}, {'address': "/muse/elements/beta_absolute", 'arguments': 4}, {'address': "/muse/elements/gamma_absolute", 'arguments': 4}, {'address': "/muse/elements/delta_relative", 'arguments': 4}, {'address': "/muse/elements/theta_relative", 'arguments': 4}, {'address': "/muse/elements/alpha_relative", 'arguments': 4}, {'address': "/muse/elements/beta_relative", 'arguments': 4}, {'address': "/muse/elements/gamma_relative", 'arguments': 4}, {'address': "/muse/elements/delta_session_score", 'arguments': 4}, {'address': "/muse/elements/theta_session_score", 'arguments': 4}, {'address': "/muse/elements/alpha_session_score", 'arguments': 4}, {'address': "/muse/elements/beta_session_score", 'arguments': 4}, {'address': "/muse/elements/gamma_session_score", 'arguments': 4}, {'address': "/muse/elements/touching_forehead", 'arguments': 1}, {'address': "/muse/elements/horseshoe", 'arguments': 4}, {'address': "/muse/elements/is_good", 'arguments': 4}, {'address': "/muse/elements/blink", 'arguments': 1}, {'address': "/muse/elements/jaw_clench", 'arguments': 1}, {'address': "/muse/elements/experimental/concentration", 'arguments': 1}, {'address': "/muse/elements/experimental/mellow", 'arguments': 1} ] for path in self.osc_paths: spacebrew_name = path['address'].split('/')[-1] self.brew.add_subscriber(spacebrew_name, "string") self.brew.subscribe(spacebrew_name, self.handle_value) def handle_value(self, string_value): value = json.loads(string_value) path = value[0] if path in self.paths: row_key, column = convert_muse_data_to_cassandra_column(path, value) if len(self.batches[path]) < BATCH_MAX_SIZE: self.batches[path][row_key] = column # time stats timestamp = row_key.split('_')[1] print "column added to batch for %s -- %s ms" % (path, timestamp) elif len(self.batches[path]) == BATCH_MAX_SIZE: self.muse_cassandra_repo.add_batch(self.batches[path]) self.batches[path] = {} # time stats timestamp = row_key.split('_')[1] print "column batch stored in cassandra for %s -- %s ms" % (path, timestamp) def start(self): self.brew.start()
def __init__(self, name, server): # get app name and server from query string self.name = name server = server # configure the spacebrew client self.brew = SpacebrewApp(name, server=server) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.osc_paths = [{ 'address': "/muse/eeg", 'arguments': 4 }, { 'address': "/muse/eeg/quantization", 'arguments': 4 }, { 'address': "/muse/eeg/dropped_samples", 'arguments': 1 }, { 'address': "/muse/acc", 'arguments': 3 }, { 'address': "/muse/acc/dropped_samples", 'arguments': 1 }, { 'address': "/muse/batt", 'arguments': 4 }, { 'address': "/muse/drlref", 'arguments': 2 }, { 'address': "/muse/elements/low_freqs_absolute", 'arguments': 4 }, { 'address': "/muse/elements/delta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/theta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/alpha_absolute", 'arguments': 4 }, { 'address': "/muse/elements/beta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/gamma_absolute", 'arguments': 4 }, { 'address': "/muse/elements/delta_relative", 'arguments': 4 }, { 'address': "/muse/elements/theta_relative", 'arguments': 4 }, { 'address': "/muse/elements/alpha_relative", 'arguments': 4 }, { 'address': "/muse/elements/beta_relative", 'arguments': 4 }, { 'address': "/muse/elements/gamma_relative", 'arguments': 4 }, { 'address': "/muse/elements/delta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/theta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/alpha_session_score", 'arguments': 4 }, { 'address': "/muse/elements/beta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/gamma_session_score", 'arguments': 4 }, { 'address': "/muse/elements/touching_forehead", 'arguments': 1 }, { 'address': "/muse/elements/horseshoe", 'arguments': 4 }, { 'address': "/muse/elements/is_good", 'arguments': 4 }, { 'address': "/muse/elements/blink", 'arguments': 1 }, { 'address': "/muse/elements/jaw_clench", 'arguments': 1 }, { 'address': "/muse/elements/experimental/concentration", 'arguments': 1 }, { 'address': "/muse/elements/experimental/mellow", 'arguments': 1 }] for path in self.osc_paths: spacebrew_name = path['address'].split('/')[-1] self.brew.add_subscriber(spacebrew_name, "string") self.brew.subscribe(spacebrew_name, self.handle_value)
class SpacebrewClient(object): def __init__(self, name, server): # get app name and server from query string self.name = name server = server # configure the spacebrew client self.brew = SpacebrewApp(name, server=server) # cassandra self.muse_cassandra_repo = CassandraRepository(KEYSPACE, MUSE_COLUMN_FAMILY) self.batches = {} self.osc_paths = [{ 'address': "/muse/eeg", 'arguments': 4 }, { 'address': "/muse/eeg/quantization", 'arguments': 4 }, { 'address': "/muse/eeg/dropped_samples", 'arguments': 1 }, { 'address': "/muse/acc", 'arguments': 3 }, { 'address': "/muse/acc/dropped_samples", 'arguments': 1 }, { 'address': "/muse/batt", 'arguments': 4 }, { 'address': "/muse/drlref", 'arguments': 2 }, { 'address': "/muse/elements/low_freqs_absolute", 'arguments': 4 }, { 'address': "/muse/elements/delta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/theta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/alpha_absolute", 'arguments': 4 }, { 'address': "/muse/elements/beta_absolute", 'arguments': 4 }, { 'address': "/muse/elements/gamma_absolute", 'arguments': 4 }, { 'address': "/muse/elements/delta_relative", 'arguments': 4 }, { 'address': "/muse/elements/theta_relative", 'arguments': 4 }, { 'address': "/muse/elements/alpha_relative", 'arguments': 4 }, { 'address': "/muse/elements/beta_relative", 'arguments': 4 }, { 'address': "/muse/elements/gamma_relative", 'arguments': 4 }, { 'address': "/muse/elements/delta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/theta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/alpha_session_score", 'arguments': 4 }, { 'address': "/muse/elements/beta_session_score", 'arguments': 4 }, { 'address': "/muse/elements/gamma_session_score", 'arguments': 4 }, { 'address': "/muse/elements/touching_forehead", 'arguments': 1 }, { 'address': "/muse/elements/horseshoe", 'arguments': 4 }, { 'address': "/muse/elements/is_good", 'arguments': 4 }, { 'address': "/muse/elements/blink", 'arguments': 1 }, { 'address': "/muse/elements/jaw_clench", 'arguments': 1 }, { 'address': "/muse/elements/experimental/concentration", 'arguments': 1 }, { 'address': "/muse/elements/experimental/mellow", 'arguments': 1 }] for path in self.osc_paths: spacebrew_name = path['address'].split('/')[-1] self.brew.add_subscriber(spacebrew_name, "string") self.brew.subscribe(spacebrew_name, self.handle_value) def handle_value(self, string_value): value = json.loads(string_value) path = value[0] if path in self.paths: row_key, column = convert_muse_data_to_cassandra_column( path, value) if len(self.batches[path]) < BATCH_MAX_SIZE: self.batches[path][row_key] = column # time stats timestamp = row_key.split('_')[1] print "column added to batch for %s -- %s ms" % (path, timestamp) elif len(self.batches[path]) == BATCH_MAX_SIZE: self.muse_cassandra_repo.add_batch(self.batches[path]) self.batches[path] = {} # time stats timestamp = row_key.split('_')[1] print "column batch stored in cassandra for %s -- %s ms" % ( path, timestamp) def start(self): self.brew.start()