import logging
import os
import yaml
from time import sleep

import matplotlib
matplotlib.use('WxAgg')
matplotlib.interactive(False)
from monitor.ComediObjects import ComediStreamer, ComediThread
import matplotlib.pyplot as plt
import numpy as np

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

with open(os.path.join('.', 'PhysioMonitor.yml'), 'r') as stream:
        config = yaml.safe_load(stream)


th = ComediThread(config)
th.start()
sleep(10)
th.stop()
logging.debug("end exec")

# fig = plt.figure()
# ax = fig.add_subplot(111)
# line = None
# fig.show()
#
#
# def frames():
#     yield np.random.random_sample((1, 1024))
#
#
# def init():
#     global line
#     line, = ax.plot([], [])
#     return line,
#
#
# def draw(data):
#     logging.debug('in draw(). received data %s', data.shape)
#     x = np.linspace(0, 1, num=data.shape[1])
#     global line
#     line.set_data(x, data)
#     return line,
#
# plt.show()
