# Path: lib/PikaSubscriber.py
# class PikaSubscriber(Subscriber):
# 
#   def __init__(self, device_name, device_id, rabbitmq_address, metrics):
#     super(PikaSubscriber, self).__init__(device_name, device_id, rabbitmq_address)
#     self.connection = None
#     self.channel = None
#     self.queues = {}
#     self.metrics = metrics
# 
# 
#   def connect(self):
#     credentials = pika.PlainCredentials('cloudbrain', 'cloudbrain')
#     self.connection = pika.BlockingConnection(pika.ConnectionParameters(
#       host=self.host, credentials=credentials))
#     self.channel = self.connection.channel()
# 
#     for metric_id,metric_info in self.metrics.iteritems():
#         # each metric has an internal id, and a name
#         #
#         # the internal id is used as a consumer_tag, or think of it as a hardcoded local variable
#         # for example, if i have 2 inputs [class_label, data], the 2 inputs are not interchangeable,
#         # and we must know which is which, so we use their ids to identify them
#         #
#         # the name is used to find the correct exchange in rabbitmq
#         key = "%s:%s:%s" %(self.device_id,self.device_name, metric_info['name'])
#         # declare the exchange serving this metric
#         self.channel.exchange_declare(exchange=key, exchange_type='direct')
# 
#         # declare queue and bind
#         # exclusive=True is important to make a queue that will be destroyed when client hangs up
#         # otherwise the queue would persist to the next session, with some old data still stuck in it
#         #
#         # Another thing, someone might look at this queue declaration and wonder: why didn't we pass in
#         # the queue name as a parameter like everywhere else?  The reason for this is that, by not passing in
#         # a name, we allow pika to use a randomly generated name for the queue
#         self.queues[metric_id] = self.channel.queue_declare(exclusive=True).method.queue
#         self.channel.queue_bind(exchange=key, queue=self.queues[metric_id], routing_key=key)
# 
#         print colors.GOLD + "[Subscriber Started] Queue --> [" + key + "] for input [" + metric_id + "]" + colors.ENDC
# 
# 
#   def disconnect(self):
#     self.connection.close_file()
# 
# 
#   def consume_messages(self, callback):
#     # loop through all queues connected and consume all
#     for queue_id,queue_name in self.queues.iteritems():
#         self.channel.basic_consume(callback,
#                       queue=queue_name,
#                       exclusive=True,
#                       no_ack=True,
#                       consumer_tag=queue_id)
# 
#     self.channel.start_consuming()
# 
# Path: lib/PikaPublisher.py
# class PikaPublisher(Publisher):
#   """
#   Publisher implementation for RabbitMQ via the Pika client
#   """
# 
#   def __init__(self, device_name, device_id, rabbitmq_address, metric_name):
#     super(PikaPublisher, self).__init__(device_name, device_id, rabbitmq_address)
#     self.connection = None
#     self.channel = None
#     self.metric_name = metric_name
# 
# 
#   def publish(self, buffer_content):
#     key = "%s:%s:%s" % (self.device_id, self.device_name, self.metric_name)
#     self.channel.basic_publish(exchange=key,
#                                routing_key=key,
#                                body=json.dumps(buffer_content),
#                                properties=pika.BasicProperties(
#                                  delivery_mode=2,  # this makes the message persistent
#                                ))
# 
#   def connect(self):
#     credentials = pika.PlainCredentials('cloudbrain', 'cloudbrain')
# 
#     self.connection = pika.BlockingConnection(pika.ConnectionParameters(
#       host=self.host, credentials=credentials))
#     self.channel = self.connection.channel()
# 
#     key = "%s:%s:%s" % (self.device_id, self.device_name, self.metric_name)
#     self.channel.exchange_declare(exchange=key,
#                                   type='direct')
# 
#   def disconnect(self):
#     self.connection.close_file()
# 
# Path: lib/devices.py
# def get_num_channels(device_name, metric):
#   metric_to_channels = map_metric_name_to_num_channels(device_name)
#   return metric_to_channels[metric]
# 
# Path: lib/constants.py
# class colors:
#     ENDC = '\033[0m'
#     UNDERLINE = '\033[4m'
#     BLINK = '\033[5m'
# 
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     FAIL = '\033[91m'
# 
#     BG_RASPBERRY = '\033[46m'
# 
#     DARK_RED = '\033[0;31m'
#     RED = '\033[91m'
#     ORANGE = '\033[1m'
#     YELLOW = '\033[93m'
#     GREEN = '\033[92m'
#     DARK_GREEN = '\033[0;32m'
#     CYAN = '\033[96m'
#     MAGENTA = '\033[0;35m'
#     RASPBERRY = '\033[0;36m'
#     DARK_PURPLE = '\033[0;34m'
# 
#     GOLD = '\033[0;33m'
#     SILVER = '\033[0;37m'
#     GRAY = '\033[90m'
# 
#     BOLD_RED = '\033[1;31m'
#     BOLD_ORANGE = '\033[1m'
#     BOLD_YELLOW = '\033[1;33m'
#     BOLD_GREEN = '\033[1;32m'
#     BOLD_CYAN = '\033[1;36m'
#     BOLD_BLUE  = '\033[1;34m'
#     BOLD_PURPLE = '\033[1;35m'
#     BOLD_GRAY  = '\033[1;30m'
# 
#     CYCLE = [YELLOW, GREEN, ORANGE,  RASPBERRY, DARK_RED, CYAN, RED, DARK_GREEN, MAGENTA, DARK_PURPLE]


from abc import ABCMeta, abstractmethod
from lib.PikaSubscriber import PikaSubscriber
from lib.PikaPublisher import PikaPublisher
from lib.devices import get_num_channels
from lib.constants import colors
__author__ = 'odrulea'

class ModuleAbstract(object):
    __metaclass__ = ABCMeta


# Path: lib/PikaSubscriber.py
# class PikaSubscriber(Subscriber):
# 
#   def __init__(self, device_name, device_id, rabbitmq_address, metrics):
#     super(PikaSubscriber, self).__init__(device_name, device_id, rabbitmq_address)
#     self.connection = None
#     self.channel = None
#     self.queues = {}
#     self.metrics = metrics
# 
# 
#   def connect(self):
#     credentials = pika.PlainCredentials('cloudbrain', 'cloudbrain')
#     self.connection = pika.BlockingConnection(pika.ConnectionParameters(
#       host=self.host, credentials=credentials))
#     self.channel = self.connection.channel()
# 
#     for metric_id,metric_info in self.metrics.iteritems():
#         # each metric has an internal id, and a name
#         #
#         # the internal id is used as a consumer_tag, or think of it as a hardcoded local variable
#         # for example, if i have 2 inputs [class_label, data], the 2 inputs are not interchangeable,
#         # and we must know which is which, so we use their ids to identify them
#         #
#         # the name is used to find the correct exchange in rabbitmq
#         key = "%s:%s:%s" %(self.device_id,self.device_name, metric_info['name'])
#         # declare the exchange serving this metric
#         self.channel.exchange_declare(exchange=key, exchange_type='direct')
# 
#         # declare queue and bind
#         # exclusive=True is important to make a queue that will be destroyed when client hangs up
#         # otherwise the queue would persist to the next session, with some old data still stuck in it
#         #
#         # Another thing, someone might look at this queue declaration and wonder: why didn't we pass in
#         # the queue name as a parameter like everywhere else?  The reason for this is that, by not passing in
#         # a name, we allow pika to use a randomly generated name for the queue
#         self.queues[metric_id] = self.channel.queue_declare(exclusive=True).method.queue
#         self.channel.queue_bind(exchange=key, queue=self.queues[metric_id], routing_key=key)
# 
#         print colors.GOLD + "[Subscriber Started] Queue --> [" + key + "] for input [" + metric_id + "]" + colors.ENDC
# 
# 
#   def disconnect(self):
#     self.connection.close_file()
# 
# 
#   def consume_messages(self, callback):
#     # loop through all queues connected and consume all
#     for queue_id,queue_name in self.queues.iteritems():
#         self.channel.basic_consume(callback,
#                       queue=queue_name,
#                       exclusive=True,
#                       no_ack=True,
#                       consumer_tag=queue_id)
# 
#     self.channel.start_consuming()
# 
# Path: lib/PikaPublisher.py
# class PikaPublisher(Publisher):
#   """
#   Publisher implementation for RabbitMQ via the Pika client
#   """
# 
#   def __init__(self, device_name, device_id, rabbitmq_address, metric_name):
#     super(PikaPublisher, self).__init__(device_name, device_id, rabbitmq_address)
#     self.connection = None
#     self.channel = None
#     self.metric_name = metric_name
# 
# 
#   def publish(self, buffer_content):
#     key = "%s:%s:%s" % (self.device_id, self.device_name, self.metric_name)
#     self.channel.basic_publish(exchange=key,
#                                routing_key=key,
#                                body=json.dumps(buffer_content),
#                                properties=pika.BasicProperties(
#                                  delivery_mode=2,  # this makes the message persistent
#                                ))
# 
#   def connect(self):
#     credentials = pika.PlainCredentials('cloudbrain', 'cloudbrain')
# 
#     self.connection = pika.BlockingConnection(pika.ConnectionParameters(
#       host=self.host, credentials=credentials))
#     self.channel = self.connection.channel()
# 
#     key = "%s:%s:%s" % (self.device_id, self.device_name, self.metric_name)
#     self.channel.exchange_declare(exchange=key,
#                                   type='direct')
# 
#   def disconnect(self):
#     self.connection.close_file()
# 
# Path: lib/devices.py
# def get_num_channels(device_name, metric):
#   metric_to_channels = map_metric_name_to_num_channels(device_name)
#   return metric_to_channels[metric]
# 
# Path: lib/constants.py
# class colors:
#     ENDC = '\033[0m'
#     UNDERLINE = '\033[4m'
#     BLINK = '\033[5m'
# 
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     FAIL = '\033[91m'
# 
#     BG_RASPBERRY = '\033[46m'
# 
#     DARK_RED = '\033[0;31m'
#     RED = '\033[91m'
#     ORANGE = '\033[1m'
#     YELLOW = '\033[93m'
#     GREEN = '\033[92m'
#     DARK_GREEN = '\033[0;32m'
#     CYAN = '\033[96m'
#     MAGENTA = '\033[0;35m'
#     RASPBERRY = '\033[0;36m'
#     DARK_PURPLE = '\033[0;34m'
# 
#     GOLD = '\033[0;33m'
#     SILVER = '\033[0;37m'
#     GRAY = '\033[90m'
# 
#     BOLD_RED = '\033[1;31m'
#     BOLD_ORANGE = '\033[1m'
#     BOLD_YELLOW = '\033[1;33m'
#     BOLD_GREEN = '\033[1;32m'
#     BOLD_CYAN = '\033[1;36m'
#     BOLD_BLUE  = '\033[1;34m'
#     BOLD_PURPLE = '\033[1;35m'
#     BOLD_GRAY  = '\033[1;30m'
# 
#     CYCLE = [YELLOW, GREEN, ORANGE,  RASPBERRY, DARK_RED, CYAN, RED, DARK_GREEN, MAGENTA, DARK_PURPLE]


# Path: Analysis/modules/ModuleAbstract.py
from abc import ABCMeta, abstractmethod
from lib.PikaSubscriber import PikaSubscriber
from lib.PikaPublisher import PikaPublisher
from lib.devices import get_num_channels
from lib.constants import colors

__author__ = 'odrulea'

class ModuleAbstract(object):
    __metaclass__ = ABCMeta


    MODULE_NAME = "Abstract"