def __init__(self, name, server):

        start = time.time()

        # configure cassandra cluster
        self.cluster = Cluster()
        self.session = self.cluster.connect('cloudbrain')

        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            for muse_port in MUSE_PORTS:

                # add subscriber
                subscriber_metric_name = '%s-muse-%s' % (publisher_metric_name,
                                                         muse_port)
                self.brew.add_subscriber(subscriber_metric_name, "string")

                # handle value
                handle_value = self.handle_value_factory(
                    publisher_metric_name, muse_port)
                self.brew.subscribe(subscriber_metric_name, handle_value)

        end = time.time()

        print 'configuration took %s s' % (end - start)
Esempio n. 2
0
    def __init__(self, name, server, paths):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)

        for spacebrew_name in paths:
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)

        self.number_of_packets = 0
        self.start_time = time.time()
    def __init__(self, muse_id=7777, server='127.0.0.1', port=9000):
        self.muse_id = muse_id
        self.server = server
        self.port = port

        name = 'muse-%s' % muse_id
        self.brew = SpacebrewApp(name, server=server)

        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            self.brew.add_publisher(publisher_metric_name, "string", '0')
            print publisher_metric_name
class SpacebrewServer(object):
    def __init__(self, muse_id=7777, server='127.0.0.1', port=9000):
        self.muse_id = muse_id
        self.server = server
        self.port = port

        name = 'muse-%s' % muse_id
        self.brew = SpacebrewApp(name, server=server)

        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            self.brew.add_publisher(publisher_metric_name, "string", '0')
            print publisher_metric_name



    def start(self):
        self.brew.start()
        while 1:
            for path in CASSANDRA_METRICS:

                spacebrew_name = calculate_spacebrew_name(path)
                num_arguments = CASSANDRA_METRICS[path]
                values = [0.1] * num_arguments
                #string value
                value = ','.join([str(v) for v in values])

                self.brew.publish(spacebrew_name, value)
                print spacebrew_name, value
                time.sleep(0.1)

    def stop(self):
        self.brew.stop()
    def __init__(self, name, server):

        start = time.time()

        # configure cassandra cluster
        self.cluster = Cluster()
        self.session = self.cluster.connect('cloudbrain')
        
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            for muse_port in MUSE_PORTS:

                # add subscriber
                subscriber_metric_name = '%s-muse-%s' % (publisher_metric_name, muse_port)
                self.brew.add_subscriber(subscriber_metric_name, "string")

                # handle value
                handle_value = self.handle_value_factory(publisher_metric_name, muse_port)
                self.brew.subscribe(subscriber_metric_name, handle_value)


        end = time.time()

        print 'configuration took %s s' % (end - start)
Esempio n. 6
0
    def __init__(self, muse_port, muse_id, server):

        self.muse_port = muse_port
        self.muse_id = muse_id

        # Configuring the Muse OSC client
        ServerThread.__init__(self, muse_port)

        logger.info('Muse %s connected to museIO on port %s' % (muse_id, muse_port))

        # configure the Spacebrew client
        self.brew = SpacebrewApp(muse_id, server=server)

        self.osc_paths = [
            '/muse/eeg',
            '/muse/eeg/quantization',
            # '/muse/eeg/dropped_samples',
            '/muse/acc',
            # '/muse/acc/dropped_samples',
            '/muse/batt',
            # '/muse/drlref',
            #'/muse/elements/raw_fft0',
            #'/muse/elements/raw_fft1',
            #'/muse/elements/raw_fft2',
            #'/muse/elements/raw_fft3',
            '/muse/elements/low_freqs_absolute',
            '/muse/elements/delta_absolute',
            '/muse/elements/theta_absolute',
            '/muse/elements/alpha_absolute',
            '/muse/elements/beta_absolute',
            '/muse/elements/gamma_absolute',
            #'/muse/elements/delta_relative',
            #'/muse/elements/theta_relative',
            #'/muse/elements/alpha_relative',
            #'/muse/elements/beta_relative',
            #'/muse/elements/gamma_relative',
            #'/muse/elements/delta_session_score',
            #'/muse/elements/theta_session_score',
            #'/muse/elements/alpha_session_score',
            #'/muse/elements/beta_session_score',
            #'/muse/elements/gamma_session_score',
            '/muse/elements/touching_forehead',
            '/muse/elements/horseshoe',
            '/muse/elements/is_good',
            '/muse/elements/blink',
            '/muse/elements/jaw_clench',
            '/muse/elements/experimental/concentration',
            '/muse/elements/experimental/mellow'
        ]

        for osc_path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(osc_path)
            self.brew.add_publisher(spacebrew_name, 'string')
            logger.debug('Spacebrew publisher %s added for muse with ID %s' % (spacebrew_name, self.muse_id))

        # Connect to spacebrew
        self.brew.start()

        logger.debug('Initialization completed for muse with ID %s' % self.muse_id)
class SpacebrewClient(object):
    def __init__(self, name, server):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        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 = self.calculate_spacebrew_name(path['address'])
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)

    def handle_value(self, value):
        print value
        # YOUR CODE HERE


    def start(self):
        self.brew.start()

    def calculate_spacebrew_name(self, osc_path):
        spacebrew_name = osc_path.split('/')[-1]
        return self.disambiguate_name_collisions(spacebrew_name, osc_path)


    def disambiguate_name_collisions(self, spacebrew_name, osc_path):
        if spacebrew_name == 'dropped_samples':
            return osc_path.split('/')[-2] + '_' + osc_path.split('/')[-1]
        else:
            return spacebrew_name
Esempio n. 8
0
    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 __init__(self, name, server):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        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 = self.calculate_spacebrew_name(path['address'])
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)
Esempio n. 10
0
class SpacebrewClient(object):
    def __init__(self, name, server, paths):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)

        for spacebrew_name in paths:
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)

        self.number_of_packets = 0
        self.start_time = time.time()

    def handle_value(self, value):
        self.number_of_packets += 1
        current_time = time.time()

        if (current_time - self.start_time) % 10 == 0:
            print "current time : %s" % current_time
            print "start time : %s" % self.start_time
            print "==> rate: %" % (self.number_of_packets /
                                   (current_time - self.start_time))

    def start(self):
        self.brew.start()
Esempio n. 11
0
class SpacebrewServer(ServerThread):
    def __init__(self, muse_port, muse_id, server):

        self.muse_port = muse_port
        self.muse_id = muse_id

        # Configuring the Muse OSC client
        ServerThread.__init__(self, muse_port)

        logger.info('Muse %s connected to museIO on port %s' % (muse_id, muse_port))

        # configure the Spacebrew client
        self.brew = SpacebrewApp(muse_id, server=server)

        self.osc_paths = [
            '/muse/eeg',
            '/muse/eeg/quantization',
            # '/muse/eeg/dropped_samples',
            '/muse/acc',
            # '/muse/acc/dropped_samples',
            '/muse/batt',
            # '/muse/drlref',
            #'/muse/elements/raw_fft0',
            #'/muse/elements/raw_fft1',
            #'/muse/elements/raw_fft2',
            #'/muse/elements/raw_fft3',
            '/muse/elements/low_freqs_absolute',
            '/muse/elements/delta_absolute',
            '/muse/elements/theta_absolute',
            '/muse/elements/alpha_absolute',
            '/muse/elements/beta_absolute',
            '/muse/elements/gamma_absolute',
            #'/muse/elements/delta_relative',
            #'/muse/elements/theta_relative',
            #'/muse/elements/alpha_relative',
            #'/muse/elements/beta_relative',
            #'/muse/elements/gamma_relative',
            #'/muse/elements/delta_session_score',
            #'/muse/elements/theta_session_score',
            #'/muse/elements/alpha_session_score',
            #'/muse/elements/beta_session_score',
            #'/muse/elements/gamma_session_score',
            '/muse/elements/touching_forehead',
            '/muse/elements/horseshoe',
            '/muse/elements/is_good',
            '/muse/elements/blink',
            '/muse/elements/jaw_clench',
            '/muse/elements/experimental/concentration',
            '/muse/elements/experimental/mellow'
        ]

        for osc_path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(osc_path)
            self.brew.add_publisher(spacebrew_name, 'string')
            logger.debug('Spacebrew publisher %s added for muse with ID %s' % (spacebrew_name, self.muse_id))

        # Connect to spacebrew
        self.brew.start()

        logger.debug('Initialization completed for muse with ID %s' % self.muse_id)

    def close(self):
        self.brew.stop()
        self.stop()
        logger.info('Connector stopped for muse with ID %s' % self.muse_id)


    # Handle all messages if the OSC path is in self.osc_paths
    @make_method(None, None)
    def fallback(self, path, args, types, src):
        if path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(path)
            value = ','.join([str(arg) for arg in args])
            self.brew.publish(spacebrew_name, value)
            # logger.debug('Muse with ID %s is publishing to spacebrew. Publisher name: %s. Data: %s' (self.muse_id, spacebrew_name, value))


    def calculate_spacebrew_name(self, osc_path):
        spacebrew_name = osc_path.split('/')[-1]
        return self.disambiguate_name_collisions(spacebrew_name, osc_path)


    def disambiguate_name_collisions(self, spacebrew_name, osc_path):
        if spacebrew_name == 'dropped_samples':
            return osc_path.split('/')[-2] + '_' + osc_path.split('/')[-1]
        else:
            return spacebrew_name
class CassandraSpacebrewClient(object):
    def __init__(self, name, server):

        start = time.time()

        # configure cassandra cluster
        self.cluster = Cluster()
        self.session = self.cluster.connect('cloudbrain')

        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            for muse_port in MUSE_PORTS:

                # add subscriber
                subscriber_metric_name = '%s-muse-%s' % (publisher_metric_name,
                                                         muse_port)
                self.brew.add_subscriber(subscriber_metric_name, "string")

                # handle value
                handle_value = self.handle_value_factory(
                    publisher_metric_name, muse_port)
                self.brew.subscribe(subscriber_metric_name, handle_value)

        end = time.time()

        print 'configuration took %s s' % (end - start)

    def handle_value_factory(self, metric, muse_port):
        def handle_value(csv_string):

            values = csv_string.split(',')
            # For metric 'eeg', the two last values are "timestamp in s"
            # and "timestamp remainder in ms". Those values are not in the
            # cassandra schema so they are discarded.
            if metric == 'eeg':
                values = values[:-2]

            # numerical values
            num_arguments = len(values)
            numerical_columns = ''.join(
                [", value_%s" % i for i in range(num_arguments)])

            # column values
            timestamp = int(time.time() * 1000)
            column_values = "'%s', '%s', %s" % (muse_port, timestamp,
                                                values[0])
            if len(values) > 1:
                for value in values[1:]:
                    column_values += ", %s" % value

            insert_template = "INSERT INTO %s (muse_id, timestamp%s) VALUES (%s);"
            insert_values = insert_template % (metric, numerical_columns,
                                               column_values)

            try:
                self.session.execute(insert_values)
            except:
                print "DEBUG: num_arguments: %s" % num_arguments
                print "DEBUG: values: %s" % values
                print "DEBUG: numerical_columns: %s" % numerical_columns
                print "DEBUG: insert_values: %s" % insert_values

        return handle_value

    def start(self):
        self.brew.start()
class CassandraSpacebrewClient(object):
    def __init__(self, name, server):

        start = time.time()

        # configure cassandra cluster
        self.cluster = Cluster()
        self.session = self.cluster.connect('cloudbrain')
        
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        for path in CASSANDRA_METRICS:
            publisher_metric_name = calculate_spacebrew_name(path)
            for muse_port in MUSE_PORTS:

                # add subscriber
                subscriber_metric_name = '%s-muse-%s' % (publisher_metric_name, muse_port)
                self.brew.add_subscriber(subscriber_metric_name, "string")

                # handle value
                handle_value = self.handle_value_factory(publisher_metric_name, muse_port)
                self.brew.subscribe(subscriber_metric_name, handle_value)


        end = time.time()

        print 'configuration took %s s' % (end - start)

    def handle_value_factory(self, metric, muse_port):

        def handle_value(csv_string):

            values = csv_string.split(',')
            # For metric 'eeg', the two last values are "timestamp in s"
            # and "timestamp remainder in ms". Those values are not in the
            # cassandra schema so they are discarded.
            if metric == 'eeg':
                values = values[:-2]

            # numerical values
            num_arguments = len(values)
            numerical_columns = ''.join([", value_%s" % i for i in range(num_arguments)])

            # column values
            timestamp = int(time.time() * 1000)
            column_values = "'%s', '%s', %s" % (muse_port, timestamp, values[0])
            if len(values) > 1:
                for value in values[1:]:
                    column_values += ", %s" % value

            insert_template = "INSERT INTO %s (muse_id, timestamp%s) VALUES (%s);"
            insert_values = insert_template % (metric, numerical_columns, column_values)

            try:
                self.session.execute(insert_values)
            except:
                print "DEBUG: num_arguments: %s" %num_arguments
                print "DEBUG: values: %s" %values
                print "DEBUG: numerical_columns: %s" %numerical_columns
                print "DEBUG: insert_values: %s" %insert_values
        return handle_value

    def start(self):
        self.brew.start()
Esempio n. 14
0
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, 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()
Esempio n. 15
0
    def __init__(self, muse_port, muse_id, server):

        self.muse_port = muse_port
        self.muse_id = muse_id

        # Configuring the Muse OSC client
        ServerThread.__init__(self, muse_port)

        logger.info('Muse %s connected to museIO on port %s' %
                    (muse_id, muse_port))

        # configure the Spacebrew client
        self.brew = SpacebrewApp(muse_id, server=server)

        self.osc_paths = [
            '/muse/eeg',
            '/muse/eeg/quantization',
            # '/muse/eeg/dropped_samples',
            '/muse/acc',
            # '/muse/acc/dropped_samples',
            '/muse/batt',
            # '/muse/drlref',
            #'/muse/elements/raw_fft0',
            #'/muse/elements/raw_fft1',
            #'/muse/elements/raw_fft2',
            #'/muse/elements/raw_fft3',
            '/muse/elements/low_freqs_absolute',
            '/muse/elements/delta_absolute',
            '/muse/elements/theta_absolute',
            '/muse/elements/alpha_absolute',
            '/muse/elements/beta_absolute',
            '/muse/elements/gamma_absolute',
            #'/muse/elements/delta_relative',
            #'/muse/elements/theta_relative',
            #'/muse/elements/alpha_relative',
            #'/muse/elements/beta_relative',
            #'/muse/elements/gamma_relative',
            #'/muse/elements/delta_session_score',
            #'/muse/elements/theta_session_score',
            #'/muse/elements/alpha_session_score',
            #'/muse/elements/beta_session_score',
            #'/muse/elements/gamma_session_score',
            '/muse/elements/touching_forehead',
            '/muse/elements/horseshoe',
            '/muse/elements/is_good',
            '/muse/elements/blink',
            '/muse/elements/jaw_clench',
            '/muse/elements/experimental/concentration',
            '/muse/elements/experimental/mellow'
        ]

        for osc_path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(osc_path)
            self.brew.add_publisher(spacebrew_name, 'string')
            logger.debug('Spacebrew publisher %s added for muse with ID %s' %
                         (spacebrew_name, self.muse_id))

        # Connect to spacebrew
        self.brew.start()

        logger.debug('Initialization completed for muse with ID %s' %
                     self.muse_id)
Esempio n. 16
0
class SpacebrewServer(ServerThread):
    def __init__(self, muse_port, muse_id, server):

        self.muse_port = muse_port
        self.muse_id = muse_id

        # Configuring the Muse OSC client
        ServerThread.__init__(self, muse_port)

        logger.info('Muse %s connected to museIO on port %s' %
                    (muse_id, muse_port))

        # configure the Spacebrew client
        self.brew = SpacebrewApp(muse_id, server=server)

        self.osc_paths = [
            '/muse/eeg',
            '/muse/eeg/quantization',
            # '/muse/eeg/dropped_samples',
            '/muse/acc',
            # '/muse/acc/dropped_samples',
            '/muse/batt',
            # '/muse/drlref',
            #'/muse/elements/raw_fft0',
            #'/muse/elements/raw_fft1',
            #'/muse/elements/raw_fft2',
            #'/muse/elements/raw_fft3',
            '/muse/elements/low_freqs_absolute',
            '/muse/elements/delta_absolute',
            '/muse/elements/theta_absolute',
            '/muse/elements/alpha_absolute',
            '/muse/elements/beta_absolute',
            '/muse/elements/gamma_absolute',
            #'/muse/elements/delta_relative',
            #'/muse/elements/theta_relative',
            #'/muse/elements/alpha_relative',
            #'/muse/elements/beta_relative',
            #'/muse/elements/gamma_relative',
            #'/muse/elements/delta_session_score',
            #'/muse/elements/theta_session_score',
            #'/muse/elements/alpha_session_score',
            #'/muse/elements/beta_session_score',
            #'/muse/elements/gamma_session_score',
            '/muse/elements/touching_forehead',
            '/muse/elements/horseshoe',
            '/muse/elements/is_good',
            '/muse/elements/blink',
            '/muse/elements/jaw_clench',
            '/muse/elements/experimental/concentration',
            '/muse/elements/experimental/mellow'
        ]

        for osc_path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(osc_path)
            self.brew.add_publisher(spacebrew_name, 'string')
            logger.debug('Spacebrew publisher %s added for muse with ID %s' %
                         (spacebrew_name, self.muse_id))

        # Connect to spacebrew
        self.brew.start()

        logger.debug('Initialization completed for muse with ID %s' %
                     self.muse_id)

    def close(self):
        self.brew.stop()
        self.stop()
        logger.info('Connector stopped for muse with ID %s' % self.muse_id)

    # Handle all messages if the OSC path is in self.osc_paths
    @make_method(None, None)
    def fallback(self, path, args, types, src):
        if path in self.osc_paths:
            spacebrew_name = self.calculate_spacebrew_name(path)
            value = ','.join([str(arg) for arg in args])
            self.brew.publish(spacebrew_name, value)
            # logger.debug('Muse with ID %s is publishing to spacebrew. Publisher name: %s. Data: %s' (self.muse_id, spacebrew_name, value))

    def calculate_spacebrew_name(self, osc_path):
        spacebrew_name = osc_path.split('/')[-1]
        return self.disambiguate_name_collisions(spacebrew_name, osc_path)

    def disambiguate_name_collisions(self, spacebrew_name, osc_path):
        if spacebrew_name == 'dropped_samples':
            return osc_path.split('/')[-2] + '_' + osc_path.split('/')[-1]
        else:
            return spacebrew_name
Esempio n. 17
0
    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)
Esempio n. 18
0
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, 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()
class SpacebrewClient(object):
    def __init__(self, name, server):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        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 = self.calculate_spacebrew_name(path['address'])
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)

    def handle_value(self, value):
        print value
        # YOUR CODE HERE

    def start(self):
        self.brew.start()

    def calculate_spacebrew_name(self, osc_path):
        spacebrew_name = osc_path.split('/')[-1]
        return self.disambiguate_name_collisions(spacebrew_name, osc_path)

    def disambiguate_name_collisions(self, spacebrew_name, osc_path):
        if spacebrew_name == 'dropped_samples':
            return osc_path.split('/')[-2] + '_' + osc_path.split('/')[-1]
        else:
            return spacebrew_name
    def __init__(self, name, server):
        # configure the spacebrew client
        self.brew = SpacebrewApp(name, server=server)
        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 = self.calculate_spacebrew_name(path['address'])
            self.brew.add_subscriber(spacebrew_name, "string")
            self.brew.subscribe(spacebrew_name, self.handle_value)