Inspiration
we were inspired by finding ways improve the use of technology with respect to mental illness
What it does
it sends information to the doctor via email to give them a daily summary of the patient's heart rate and to the patient via phone message to inform them when their heart rate goes over 110bpm
How I built it
we used the fitbit and libraries to upload data from the fitbit onto python. Using this data we created plots and coded these plots to be sent as emails. We also included a way to send information about the peaks of the heart rate to the patient so they know when there is an issue
Challenges I ran into
it was difficult to find a way to code for the email being sent since we were advised to use HTML but we found that we could simply use python with added libraries
Accomplishments that I'm proud of
we were able to complete the code to send messages to the patient
What I learned
we learnt that there are many more ways to use python than we thought
What's next for fitbit_heart_rate
we are trying to send an email with a plot of the heart rate against time to the patient's doctor code: import fitbit import gather_keys_oauth2 as Oauth2 import pandas as pd import datetime import matplotlib.pyplot as plt import numpy import sendgrid import os from sendgrid.helpers.mail import *
CLIENT_ID = '22DLJB' CLIENT_SECRET = '8e3e02e9ff08e020b1a921667cbb7b3f'
server = Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET) server.browser_authorize()
ACCESS_TOKEN = str(server.fitbit.client.session.token['access_token']) REFRESH_TOKEN = str(server.fitbit.client.session.token['refresh_token'])
auth2_client = fitbit.Fitbit(CLIENT_ID, CLIENT_SECRET, oauth2=True, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
yesterday = str((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y%m%d"))
yesterday2 = str((datetime.datetime.now() - datetime.timedelta(days=0)).strftime("%Y-%m-%d"))
today = str(datetime.datetime.now().strftime("%Y%m%d"))
fit_statsHR = auth2_client.intraday_time_series('activities/heart', base_date=yesterday2, detail_level='1sec')
fit_statsEX = auth2_client.intraday_time_series('activities/)
time_list = [] val_list = []
for i in fit_statsHR['activities-heart-intraday']['dataset']: val_list.append(i['value']) time_list.append(datetime.datetime.strptime(i['time'], '%H:%M:%S').time()) graphs = plt.plot(time_list,val_list)
plt.savefig('heart-rate.png') plt.ylabel('Heart Rate')
print(max(val_list)) if max(val_list) > 110 : client = nexmo.Client(key='2aa63187', secret='1yhUO6wgmjuMlQDb')
client.send_message({
'from': 'Nexmo',
'to': '447716339423',
'text': 'Your Heart Rate Peaked Past 110 Today. Please consult your GP for more information.',
})
sg = sendgrid.SendGridAPIClient(apikey = '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') from_email = Email("celineamadou@gmail.com") to_email = Email("camadou-douah1@sheffield.ac.uk") subject = "Patient's daily summary" content = Content("text/plain", "This is today's summary of the heart rate of your patient") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) png_path = 'python-fitbit-master' with open(png_path,'rb') as f: data = f.read() f.close()
encoded = base64.b64encode(data)
attachment = Attachment() attachment.set_content(png) attachment.set_type("application/png") attachment.set_filename("heart-rate.png") attachment.set_disposition("attachment")
print(response.status_code) print(response.body) print(response.headers)
Log in or sign up for Devpost to join the conversation.