Deutsches Zentrum für Luft- und Raumfahrt e.V.
Twitter @onyame
Email andreas.schreiber@dlr.de
Deutsches Zentrum für Luft- und Raumfahrt e.V.
Twitter @a8t5n
Email alex.nguyen@t-online.de
Deutsches Zentrum für Luft- und Raumfahrt e.V.
Email simon.siegert@gmx.de
In [2]:
import sqlite3
db = sqlite3.connect("btle_backup_20082015_2118.sqlite")
In [3]:
import pandas as pd
df = pd.read_sql("SELECT * from devices", db,index_col='id')
In [135]:
df.tail()
Out[135]:
In [136]:
df['devicetype'] = df['devicetype'].str.replace('\(.*\)', '', case=False)
In [137]:
device_types = df.groupby('devicetype').size()
In [138]:
device_types
Out[138]:
In [139]:
import seaborn as sns
device_types.plot(kind='bar')
Out[139]:
In [140]:
devices = device_types.drop([u'Apple device ', u'Samsung device ', u'Unknown device'])
In [141]:
devices.plot(kind='bar')
Out[141]:
In [3]:
import fitbit_user
python-fitbit
: https://github.com/orcasgit/python-fitbit
In [2]:
from fitbit import Fitbit
In [15]:
from fitbit import FitbitOauthClient
client = FitbitOauthClient(fitbit_user.consumer_key_steps, fitbit_user.consumer_secret_steps)
request_token = client.fetch_request_token()
print request_token
In [16]:
import webbrowser
webbrowser.open(client.authorize_token_url())
Out[16]:
In [17]:
token = client.fetch_access_token('6****************************0', request_token)
print(token)
user_token = token["oauth_token"]
user_secret = token["oauth_token_secret"]
user_id = token["encoded_user_id"]
In [30]:
fitbit_client = Fitbit(fitbit_user.consumer_key_steps,
fitbit_user.consumer_secret_steps,
resource_owner_key = user_token,
resource_owner_secret = user_secret,
user_id=user_id)
In [31]:
user_profile = fitbit_client.user_profile_get(user_id=user_id)
In [32]:
user_profile
Out[32]:
In [35]:
activities_steps = fitbit_client.time_series('activities/steps', user_id=user_id, period='1y')
In [36]:
activities_steps
Out[36]:
In [37]:
steps_dict = {}
for step in activities_steps['activities-steps']:
steps_dict[step['dateTime']] = int(step['value'])
In [39]:
from pandas import Series
steps = Series(steps_dict, name='Steps')
In [59]:
steps.head()
Out[59]:
In [65]:
import numpy as np
cleaned_steps = steps.replace(0, np.nan)
In [66]:
cleaned_steps.tail()
Out[66]:
In [68]:
cleaned_steps = cleaned_steps.dropna()
In [69]:
cleaned_steps.tail()
Out[69]:
In [70]:
import matplotlib.pyplot as plt
plt.figure()
cleaned_steps.plot(label='Steps')
plt.legend(loc='best')
Out[70]:
In [74]:
cleaned_steps.hist(bins=10, color='darkseagreen')
plt.suptitle('Daily steps distribution (last year); 10 bins')
Out[74]:
In [78]:
cleaned_steps.hist(bins=100, color='darkseagreen')
plt.suptitle('Daily steps distribution (last year); 100 bins')
Out[78]:
In [84]:
band_daily_summary = pd.read_csv('data/Microsoft_Health_20140821_20150821.csv', index_col='Date')
In [87]:
band_daily_summary.tail()
Out[87]:
In [92]:
band_steps_summary = band_daily_summary['Steps']
band_steps = pd.DataFrame(band_steps_summary)
band_steps = band_steps.rename(columns = {'Steps':'Steps Microsoft Band'})
In [91]:
band_steps.tail()
Out[91]:
In [93]:
band_steps.plot()
Out[93]:
In [97]:
fitbit_steps = pd.DataFrame(cleaned_steps)
#df_steps_fitbit.rename(index={0:'Date'})
fitbit_steps.index.names = ['Date']
fitbit_steps = fitbit_steps.rename(columns = {'Steps':'Steps Fitbit'})
In [99]:
fitbit_steps.tail()
Out[99]:
In [101]:
steps_combined = pd.DataFrame.join(band_steps, fitbit_steps)
In [103]:
steps_combined.tail()
Out[103]:
In [104]:
steps_combined.plot()
Out[104]:
In [105]:
def differences(series):
diff = series['Steps Microsoft Band'] - series['Steps Fitbit']
if abs(diff) > 900:
return None
else:
return diff
In [106]:
steps_combined['Difference'] = steps_combined.apply(differences, axis=1)
In [108]:
steps_combined['Difference'].hist(bins=10)
plt.title("Microsoft Band vs. Fitbit One: Deviation of daily steps")
plt.ylabel('count')
plt.xlabel('Steps deviation compared with Fitbit One');
In [109]:
def percentage(series):
percent = 100.-100.*min(series['Steps Microsoft Band'], series['Steps Fitbit'])/max(series['Steps Microsoft Band'], series['Steps Fitbit'])
if percent > 15.:
return None
else:
return percent
In [110]:
steps_combined['Percentage'] = steps_combined.apply(percentage, axis=1)
In [115]:
steps_combined['Percentage'].hist(bins=20)
plt.title("Microsoft Band vs. Fitbit One: Deviation of daily steps")
plt.ylabel('count')
plt.xlabel('Steps deviation (%) compared with Fitbit One');
In [114]:
steps_combined
Out[114]:
$ bokeh-server
In [116]:
from bokeh.plotting import figure, output_server, output_notebook, cursession, show
In [117]:
from liblo import *
from thread import start_new_thread
In [119]:
# Where to listen for received OSC messages by Muse IO
MUSE_IO_PORT = 5008
# Values to display (x-axis)
DISPLAY_RANGE = 1200
delta0 = 0
delta1 = 2500
delta2 = 5000
delta3 = 7500
transmission_running = False
In [120]:
output_server("mindwaves")
output_notebook()
TOOLS = "wheel_zoom, box_zoom, reset, resize"
f = figure(background_fill = "#222222", tools = TOOLS)
# prevent rendering axis labels
f.xaxis.bounds = [0,0]
f.yaxis.bounds = [0,0]
# lines with DISPLAY_RANGE elements; set values to delta[0-3]
f.line(range(DISPLAY_RANGE), [delta3] * DISPLAY_RANGE, name = 'mind_wave', color = "#ef002a")
f.line(range(DISPLAY_RANGE), [delta2] * DISPLAY_RANGE, name = 'mind_wave', color = "#ff9400")
f.line(range(DISPLAY_RANGE), [delta1] * DISPLAY_RANGE, name = 'mind_wave', color = "#0b5fa5")
f.line(range(DISPLAY_RANGE), [delta0] * DISPLAY_RANGE, name = 'mind_wave', color = "#41db00")
Out[120]:
In [121]:
renderer = f.select(dict(name="mind_wave"))
l_ear_ds = renderer[0].data_source
l_forehead_ds = renderer[1].data_source
r_forehead_ds = renderer[2].data_source
r_ear_ds = renderer[3].data_source
In [122]:
class MuseServer(ServerThread):
# listen for messages on MUSE_IO_PORT
def __init__(self):
ServerThread.__init__(self, MUSE_IO_PORT)
# receive EEG data
@make_method('/muse/eeg', 'ffff')
def eeg_callback(self, path, args):
global l_ear_ds, l_forehead_ds, r_forehead_ds, r_ear_ds, transmission_running
l_ear, l_forehead, r_forehead, r_ear = args
l_ear_ds.data["y"].append(l_ear + delta3)
l_forehead_ds.data["y"].append(l_forehead + delta2)
r_forehead_ds.data["y"].append(r_forehead + delta1)
r_ear_ds.data["y"].append(r_ear + delta0)
# send data to bokeh-server only if there is no transmission running
if (transmission_running == False):
transmission_running = True
start_new_thread(start_transmission_process, ())
In [124]:
def start_transmission_process():
global l_ear_ds, l_forehead_ds, r_forehead_ds, r_ear_ds, transmission_running
# only keep "some" (DISPLAY_RANGE) values
l_ear_ds.data["y"][0:-DISPLAY_RANGE] = []
l_forehead_ds.data["y"][0:-DISPLAY_RANGE] = []
r_forehead_ds.data["y"][0:-DISPLAY_RANGE] = []
r_ear_ds.data["y"][0:-DISPLAY_RANGE] = []
# send data sources to bokeh-server
cursession().store_objects(l_ear_ds, l_forehead_ds, r_forehead_ds, r_ear_ds)
# finished transmission
transmission_running = False
In [147]:
server = MuseServer()
In [145]:
show(f)
server.start()
In [146]:
server.stop()
Python User Group Köln: http://pycologne.de
Quantified Self Meetup Köln: http://quantifiedself.cologne
In [2]:
% pylab inline