Esempio n. 1
0
def create_module(user_id):
  """Create a new Analytics module and initialize it"""
  
  module_type = request.json["module_type"]
  device_type = request.json["device_type"]

  if len(modules) == 0:
    module_id = "module0"
  else:
    module_id = "module%s" % _num_of_modules()

  if user_id not in modules:
    modules[user_id] = {}
   
  if module_type == "motor_imagery":
    preproc_module = PreprocessingModule(user_id,
                                         module_id,
                                         device_type,
                                         _RMQ_ADDRESS,
                                         _RMQ_USER,
                                         _RMQ_PWD)
    preproc_module.initialize()
    thread = Thread(target=preproc_module.start)
    thread.start()
    modules[user_id][module_id] = preproc_module
    
    module_id = "module%s" %(len(modules))
    htm_mi_module = HTMMotorImageryModule(user_id, 
                                   module_id, 
                                   device_type,
                                   _RMQ_ADDRESS,
                                   _RMQ_USER,
                                   _RMQ_PWD)
    htm_mi_module.initialize()
    thread = Thread(target=htm_mi_module.start)
    thread.start()
    modules[user_id][module_id] = htm_mi_module
  if module_type not in _VALID_MODULES:
    return json.dumps("Wrong module type: %s. Valid modules: %s"
                      % (module_type, _VALID_MODULES))

  return json.dumps({"id":module_id}), 200
#!/usr/bin/env python2

from brainsquared.analytics.preprocessing_module import PreprocessingModule


_RMQ_ADDRESS = "rabbitmq.cloudbrain.rocks"
_RMQ_USER = "******"
_RMQ_PWD = "cloudbrain"
_WEBSERVER_PORT = 8080
_API_VERSION = "v0.1"

user_id = 'brainsquared'
module_id = 'module1'
device_type = 'openbci'

preproc_module = PreprocessingModule(user_id,
                                     module_id,
                                     device_type,
                                     _RMQ_ADDRESS,
                                     _RMQ_USER,
                                     _RMQ_PWD)

preproc_module.initialize()
preproc_module.start()