Siddharth Agarwala
Published

Open Source Rehabilitation Aid for Patients after Surgery

FCHacks 2020 Virtual competition Solution by Team Awesome

AdvancedWork in progress24 hours326
Open Source Rehabilitation Aid for Patients after Surgery

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Speaker
Can be anything that has a headphone jack. I used this one.
×1
USB sound card
×1

Story

Read more

Code

EmailDoc.py

Python
This emails the doctor and asks how the user is feeling. It also generates the body of the email.
import GleanUserData

import yagmail

import easygui

#This is commented out, as we are not currently using it with people other than us.
#The test email is GenericPatientFCHacks@gmail.com
#FROM = easygui.enterbox('enter your email:')


def EmailDoc(Exercise):
    #Prompt the user to type in how they are feeling.
    Feeling = easygui.enterbox("How are you feeling?")

    #Prompt the user to type in anything they would like the doctor to know
    NotesForDoc = easygui.enterbox("Is there anything you would like the doctor to know?")

    #Login to Gmail
    yagmail.register("GenericPatientFCHacks@gmail.com", "PythonRules1")

    #Log into the generic email that we have for this project
    yag = yagmail.SMTP("GenericPatientFCHacks@gmail.com")

    #This is a generic email we made for the Hackathon.
    To = "GenericDoctorFCHacks@gmail.com"

    #Creates 
    Subject = "Patient " + (GleanUserData.Name).rstrip("\n") + "'s status after " + GleanUserData.Surgery


    Message = [
        GleanUserData.Name + " has done " + str(Exercise) + " excercise sessions since the operation.",
        "He/She is feeling " + Feeling + ".",
        "He/She would like you to know: " + NotesForDoc
        
    ]

    #Actually send the email :D
    yag.send(To, Subject, Message)

GleanUserData.py

Python
This takes the User.txt file and turns the data into python-readable data.
# Write your code here :-)
User = open("/home/pi/Desktop/Hackathon/User.txt", "r")


#Creates a list of traits from the text file.
infolis = []

for line in User:
    infolis.append(line)

#This try statement is so that the code doen't break if anything goes wrong. It will simply remind the user that some of the data isformatted  incorrectly.
try:
    Height = int((infolis[0])[2:-3])

    Weight = int((infolis[1])[2:-3])

    Name = (infolis[2])[2:-1]

    Age = int((infolis[3])[2:-1])

    if "M" or "m" in infolis[4]:
        Gender = "Male"
    elif "F" or "d" in infolis[4]:
        Gender = "Female"
    else:
        Gender = "N/A"

    PreExisCond = (infolis[5])[3:-1].split(",")

    Surgery = infolis[6][3:]

except:
    print("misformated user data")

MainCode.py

Python
This runs the code that puts everything together.
import GleanUserData
import EmailDoc
import VideoPlayer


Excount = 0

#Loops and does flow control for the videoplayer and emailing functions stored in other python documents.
while True:
    if VideoPlayer.vidinteract() == False:
        EmailDoc.EmailDoc(Excount)
        break
    
    else:
        
        Excount += 1
        
    
    

VideoPlayer.py

Python
This Plays the youtube video and asks the person if they would like to exercise and for what duration.
import GleanUserData
import EmailDoc


import easygui

#Video Player librarys
import vlc
import pafy

import random


#links to the Youtube videos that we use in this project
vid1 = "https://www.youtube.com/watch?v=bj05-YdjF-A"

vid2 = "https://www.youtube.com/watch?v=ZbjzLG1jbvA "

vid3 = "https://www.youtube.com/watch?v=baRR17zPluQ"

vid4 = "https://www.youtube.com/watch?v=3fYBXCMYmso"

vid5 = "https://www.youtube.com/watch?v=T1UTVTlislY"






def vidinteract():
    
    #Prompts the user, would you like to exercise. Returns True/False
    a = easygui.ynbox("Would you like to exercise?", "Would you like to exercise?")
    


    if a == True:
        #This part of the code asks the user how long they can work out for.
        time = easygui.buttonbox("How long do you have to work out?", "time", ["Short", "Medium", "Long"])
        
        print (time)
        
        
        #If it is short, the video exercies go for arround 1 to 2 minutes.
        if time == "Short":
            #Picks random of two videos

            r = random.randint(1,2)
            if r == 1:
                
                #Picks a random exercies in the video to show.
                t = random.randint(1,9)
                timedict = {1:[72, 102], 2:[169, 217], 3:[230, 275], 4:[279, 300], 5:[354, 389], 6:[393, 431], 7:[435, 455], 8:[691, 830], 9:[855, 859]}
                

                #Video Playback starting
                video = pafy.new(vid1)
                best = video.getbest()
                playurl = best.url
                
                Instance = vlc.Instance()
                player = Instance.media_player_new()
                media = Instance.media_new(playurl)
                media.get_mrl()
                player.set_media(media)
                media.add_option('start-time=' + str(float(timedict[t][0])))
                media.add_option('run-time=' + str(float(timedict[t][1]-timedict[t][0])))
                player.play()
                
                
            elif r == 2:

                #Picks a random exercies in the video to show.
                t = random.randint(1,14)
                timedict = {1:[72, 102], 2:[103,132], 3:[133, 163], 4:[165, 193], 5:[195, 223], 6:[225,255], 7:[257, 284],8:[287, 314],9:[316, 343],10:[345, 372],11:[377, 402],12:[409, 432],13:[437, 463],14:[468, 493]}
                

                #Video Playback starting
                video = pafy.new(vid2)
                best = video.getbest()
                playurl = best.url
                
                Instance = vlc.Instance()
                player = Instance.media_player_new()
                media = Instance.media_new(playurl)
                media.get_mrl()
                player.set_media(media)
                media.add_option('start-time=' + str(float(timedict[t][0])))
                media.add_option('run-time=' + str(float(timedict[t][1]-timedict[t][0])))
                player.play()
                
        #If the user choses medium, then the exercises go for arround 8 minutes
        if time == "Medium":

            #Picks random out of 2 videos
            r = random.randint(1,2)
            if r == 1:
                #Video Playback starting
                video = pafy.new(vid3)
                best = video.getbest()
                media = vlc.MediaPlayer(best.url)
                Instance = vlc.Instance()
                player = Instance.media_player_new()
                media = Instance.media_new(playurl)
                media.get_mrl()
                player.set_media(media)
                player.play()
                
            elif r == 2:
                #Video Playback starting
                video = pafy.new(vid4)
                best = video.getbest()
                media = vlc.MediaPlayer(best.url)
                Instance = vlc.Instance()
                player = Instance.media_player_new()
                media = Instance.media_new(playurl)
                media.get_mrl()
                player.set_media(media)
                player.play()
        
        #The long exercise goes for 24 minutes.
        if time == "Long":
            #Video Playback starting
            video = pafy.new(vid5)
            best = video.getbest()
            media = vlc.MediaPlayer(best.url)
            Instance = vlc.Instance()
            player = Instance.media_player_new()
            media = Instance.media_new(playurl)
            media.get_mrl()
            player.set_media(media)
            player.play()
        
        
        
        
        
        
    else:
        return False

User.txt

Plain text
This is where the user inputs information about themselves.
h:65in
w:150lb
n:Joe
a:45
g:M
PC:Diabetes,Depression
RS:Appendectomy

Credits

Siddharth Agarwala

Siddharth Agarwala

2 projects • 1 follower

Comments