Thursday, August 20, 2009

PyHealth

Introduction

Health is important to you and me, especially me :)

This PyHealth application calculates BMI (Body Mass Index) and BMR (Basal Metabolic Rate) in Python for S60. The BMI and BMR figures could tell indicate if you over-weight, under-weight or normal-weight and how many calories you burn everyday, respectively.


BMI

Body Mass Index (BMI) - The measure of body fat based on height and weight that applies to both adult male and female. Enter your weight and height using Metric measures and this application would calculate your BMI.

BMR

Basal Metabolic Rate (BMR) - The measurement of energy, in calories, required to keep the body functioning at rest. Metabolic rates increase with exertion, stress, fear, and illness. The BMR uses the variables of height, weight, age and gender to calculate itself. We all need a certain number of calories to function, so it's important not to reduce your calories below your BMR when you're trying to lose weight.

The following standard PyS60 modules are used when developing this application,
* appuifw module
* graphics module
* e32 module
* math module

The following functions are used in PyHealth,
* draw_screen: prepare the canvas

* BMI: for calculating BMI

* BMR : for calculating BMR
All the functions and parameters are defined in source code in detail.



Code Snippet

The source code for the PyHealth is given below

# importing the necessary modules
import e32
import appuifw
import graphics
import math

# define color code

BLACK=(0,0,0)
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
WHITE=(255,255,255)
running=1

#global variables
global x,y
x=10
y=50

# Set application title
appuifw.app.title=u"PyHealth"

# Define the exit function
def quit():
global running
running=0
app_lock.signal()


#define functions
def menu_about():
appuifw.note(u"PyHealth version 1.00" + "\n Developed by Nirpsis")


#Define a function that will be called when the canvas needs to be redrawn
def handle_redraw(rect):
canvas.blit(img)


#define the draw function
def draw_screen():
global canvas

#Create an instance of Canvas and set it as the application's body
canvas = appuifw.Canvas(redraw_callback=handle_redraw)
appuifw.app.body = canvas
appuifw.app.exit_key_handler = quit

global img
img = graphics.Image.new(canvas.size)

#Clear the image
img.clear(BLACK)

handle_redraw(None)


#define start function
def BMI():
global x,y
img.clear(BLACK)
data1,data2 = appuifw.multi_query(u" Your Weight(Kg)",u" Your Height(Cm)")
result = (float(data1)/((float(data2)*float(data2))/10000)) #Divide
a=result

if(a < fill =" BLUE,font="(u'Nokia" fill =" BLUE,font="(u'Nokia">18) and( a<24): fill =" BLUE,font="(u'Nokia" fill =" BLUE,font="(u'Nokia">24) and (a<30): fill =" BLUE,font="(u'Nokia" fill =" BLUE,font="(u'Nokia">30):
img.text((x,y), u"BMI: "+unicode(a), fill = BLUE,font=(u'Nokia Hindi S60',22,appuifw.STYLE_BOLD))
img.text((x,y+40),u"Comment: Obesity! NO junk food!", fill = BLUE,font=(u'Nokia Hindi S60',14,appuifw.STYLE_BOLD))
handle_redraw(None)


def BMR():
global x,y
img.clear(BLACK)
data1,data2 = appuifw.multi_query(u" Your Weight(Kg)",u" Your Height(Cm)")
list=[u'Female',u'Male']
#Selectionlist allows the user to select the list items
list1=appuifw.selection_list(choices=list,search_field=1)
data3= appuifw.query(u"Your Age","number")


if(list1==0):
result =(655 + ( 9.6 * float(data1) ) + ( 1.8 *float(data2) )-( 4.7 * float(data3) ))
a=result
if(a>1300) and(a < fill =" BLUE,font="(u'Nokia" fill =" BLUE,font="(u'Nokia">1500):
img.text((x,y), u"BMR: "+unicode(result), fill = BLUE,font=(u'Nokia Hindi S60',22,appuifw.STYLE_BOLD))
img.text((x,y+40), u"Comment: High BMR! Take proper Vitamins ", fill = BLUE,font=(u'Nokia Hindi S60',14,appuifw.STYLE_BOLD))

if(list1==1):

result= (66 + ( 13.7 * float(data1) ) + ( 5 *float(data2) ) - ( 6.8 *float(data3) ))
img.text((x,y), u"BMR: "+unicode(result), fill = BLUE,font=(u'Nokia Hindi S60',22,appuifw.STYLE_BOLD))
a=result
if(a>1600) and(a < fill =" BLUE,font="(u'Nokia" fill =" BLUE,font="(u'Nokia">1800):
img.text((x,y), u"BMR: "+unicode(result), fill = BLUE,font=(u'Nokia Hindi S60',22,appuifw.STYLE_BOLD))
img.text((x,y+40), u" Comment: High BMR!Take proper Vitamins ", fill = BLUE,font=(u'Nokia Hindi S60',14,appuifw.STYLE_BOLD))
#display result

draw_screen()
appuifw.app.menu = [(u"BMI",BMI),(u"BMR",BMR),(u"About", menu_about), (u"Exit", quit)]

app_lock = e32.Ao_lock()
#Wait for the user to request the exit

app_lock.wait()


Screenshots

Below are few of the Screenshots by PyHealth applicaion.













0 comments:

Post a Comment