In [3]:
import xml.etree.ElementTree as et
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = 16, 8
In [4]:
path = "/home/sasdemo/apple_health_export/export.xml"
e = et.parse(path)
In [5]:
pd.Series([el.tag for el in e.iter()]).value_counts()
Out[5]:
In [6]:
pd.Series([atype.get('type') for atype in e.findall('Record')]).value_counts()
Out[6]:
In [7]:
#Extract the heartrate values, and get a timestamp from the xml
# there is likely a more efficient way, though this is very fast
def extractXMLData(xmlElement, xmlValue):
dt = []
v = []
for atype in e.findall(xmlElement):
if atype.get('type') == xmlValue:
dt.append(datetime.strptime(atype.get("startDate"),"%Y-%m-%d %H:%M:%S %z"))
v.append(atype.get("value"))
myd = pd.DataFrame({"Create":dt,xmlValue:v})
myd['Month'] = myd['Create'].apply(lambda x: x.strftime('%Y-%m'))
myd['Day'] = myd['Create'].apply(lambda x: x.strftime('%d'))
myd['Hour'] = myd['Create'].apply(lambda x: x.strftime('%H'))
return(myd)
In [11]:
myd = extractXMLData('Record',"HKQuantityTypeIdentifierHeartRate")
myd["HKQuantityTypeIdentifierHeartRate"] = myd.HKQuantityTypeIdentifierHeartRate.astype(float).astype(int)
myd.head()
Out[11]:
In [12]:
myd.boxplot(by='Month',column="HKQuantityTypeIdentifierHeartRate", return_type='axes')
Out[12]:
In [46]:
ax = myd[myd['Month']=='2017-05'].boxplot(by='Day',column="Value", return_type='axes')
In [51]:
myd[myd['Month']=='2017-05'].boxplot(by='Hour',column="Value")
Out[51]:
In [13]:
from swat import *
cashost='localhost'
casport=5570
casauth='~/.authinfo'
sess = CAS(cashost, casport, authinfo=casauth, caslib="casuser")
In [14]:
# Load necessary actionsets
sess.loadactionset(actionset="table")
Out[14]:
In [15]:
# list available caslibs
sess.caslibinfo()
Out[15]:
In [28]:
sess.droptable(name='AppleHeartrate')
upRes = sess.upload(data=myd,casout='AppleHeartrate')
sess.promote(name='AppleHeartrate')
ahr = upRes.casTable
In [24]:
sess.table.tableinfo()
Out[24]:
In [31]:
ahr.head()
Out[31]:
In [ ]: