PyMindMonitor

Some constants and imports.


In [1]:
DATABASE = '/Users/sb/Development/projects/PyMindMonitor/mind_monitor/resources/eeg.db'

import sqlite3
import matplotlib.pyplot as plt
%matplotlib inline

#Indices into record
idx = {'session':0, 'timestamp':1, 'highAlpha':2, 'highBeta':3, 'highGamma':4, 'delta':5, 'theta':6, 
       'lowAlpha':7, 'lowBeta':8, 'lowGamma':9,
      'attention':10, 'meditation':11, 'poorSignalQuality':12}

Create connection and a cursor.


In [2]:
conn = sqlite3.connect(DATABASE)
cur = conn.cursor()

Retrieve a set of raw data.


In [3]:
# Set session id for evaluation:
session_id = 4

In [4]:
cur.execute('select * from raw_data where session=? order by timestamp', (session_id,))
raw_data = cur.fetchall()
#raw_data

In [5]:
t_base = None
if len(raw_data) > 0:
    t_base = raw_data[0][1]
    t_data = [x[1] - t_base for x in raw_data]
    r_data = [x[2] for x in raw_data]
    plt.figure(figsize=(15,6))
    plt.xlabel = 'time [sec]'
    plt.ylabel = 'raw data'
    plt.title = 'raw data for session {}'.format(session_id)
    plt.plot(t_data, r_data)
    plt.show()

Retrieve set of records.


In [6]:
cur.execute('select * from records where session=? order by timestamp', (session_id,))
records = cur.fetchall()
#records

In [7]:
if len(records) > 0:
    if t_base is None:
        t_base = records[0][1]
    t_data = [x[idx['timestamp']] - t_base for x in records]
    delta_data = [x[idx['delta']] for x in records]
    theta_data = [x[idx['theta']] for x in records]
    plt.figure(figsize=(15,12))
    plt.xlabel = 'time'
    plt.ylabel = 'raw data'
    plt.title = 'raw data for session {}'.format(session_id)
    
    plt.subplot(411)
    plt.plot(t_data, delta_data, label='delta')
    plt.plot(t_data, theta_data, label='theta')
    plt.legend(loc='best')
    
    highAlpha_data = [x[idx['highAlpha']] for x in records]
    highBeta_data = [x[idx['highBeta']] for x in records]
    highGamma_data = [x[idx['highGamma']] for x in records]

    plt.subplot(412)
    plt.plot(t_data, highAlpha_data, label='highAlpha')
    plt.plot(t_data, highBeta_data, label='highBeta')
    plt.plot(t_data, highGamma_data, label='highGamma')
    plt.legend(loc='best')

    lowAlpha_data = [x[idx['lowAlpha']] for x in records]
    lowBeta_data = [x[idx['lowBeta']] for x in records]
    lowGamma_data = [x[idx['lowGamma']] for x in records]

    plt.subplot(413)
    plt.plot(t_data, lowAlpha_data, label='lowAlpha')
    plt.plot(t_data, lowBeta_data, label='highBeta')
    plt.plot(t_data, lowGamma_data, label='lowGamma')
    plt.legend(loc='best')
    
    attention_data = [x[idx['attention']] for x in records]
    meditation_data = [x[idx['meditation']] for x in records]

    plt.subplot(414)
    plt.plot(t_data, attention_data, label='attention')
    plt.plot(t_data, meditation_data, label='meditation')
    plt.legend(loc='best')

    plt.xlabel = 'time [sec]'
    plt.ylabel = 'level'
    plt.show()
    t_data


Close connection.


In [8]:
import monitor_sqlite as msq
import monitor_plot as mpl


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-15cafbc3a1d6> in <module>()
----> 1 import monitor_sqlite as msq
      2 import monitor_plot as mpl

ImportError: No module named 'monitor_sqlite'

In [ ]:
#conn.close()