image
 
image
M059_Health.bas


' ========================================================================================================================
'                                 ____,__,  __,  ____,_,  _,  ____ ____,__, ,____,____,
'                                (-/_|(-|  (-|  (-|_,(-|\ |  (-|__|-/_|( |_/(-|_,(-|__)
'                                _/  |,_|__,_|__,_|__,_| \|,  _|__)/  |,_| \,_|__,_|  \,
'
'                                              Copyright � 2008 Allen Baker
'
' ------------------------------------------------------------------------------------------------------------------------
' File:       M059_Health
' Originator: Allen Baker (2008.11.23 16:23)
' LayoutRev:  1
' ========================================================================================================================



' ========================================================================================================================
' Description
'    This module contains routines for health- and fitness-related computations. For example, it provides a function for
'    computing a person's Basal Metabolic Rate.
' ========================================================================================================================



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the BMR of a person with the given characteristics
'
' The BMR formula uses the variables of height, weight, age and gender to calculate the Basal Metabolic Rate
' (BMR). This is more accurate than calculating calorie needs based on body weight alone. The only factor it
' omits is lean body mass and thus the ratio of muscle-to-fat a body has. Remember, leaner bodies need more
' calories than less leaner ones. Therefore, this equation will be very accurate in all but the very muscular
' (will underestimate calorie needs) and the very fat (will over-estimate calorie needs). Once you know your
' BMR, you can calculate your Daily Calorie Needs based on your activity level using the Harris Benedict
' Equation.
'
' Male   (English) BMR = 66  + ( 6.23 x weight in pounds ) + ( 12.7 x height in inches ) -
'                              (6.8 x age in years )
' Male   (Metric)  BMR = 66  + ( 13.7 x weight in kilos  ) + ( 5 x height in cm )        -
'                              ( 6.8 x age in years )
' Female (English) BMR = 655 + ( 4.35 x weight in pounds ) + ( 4.7  x height in inches ) -
'                              ( 4.7 x age in years )
' Female (Metric)  BMR = 655 + ( 9.6  x weight in kilos  ) + ( 1.8  x height in cm )     -
'                              ( 4.7 x age in years )
'
'
' Harris Benedict Formula
'
'    To determine your total daily calorie needs, multiply your BMR by the appropriate activity
'    factor, as follows:
'
'    If you are sedentary (little or no exercise) : Calorie-Calculation = BMR x 1.2
'
'    If you are lightly active (light exercise/sports 1-3 days/week) : Calorie-Calculation =
'    BMR x 1.375
'
'    If you are moderatetely active (moderate exercise/sports 3-5 days/week) :
'    Calorie-Calculation = BMR x 1.55
'
'    If you are very active (hard exercise/sports 6-7 days a week) : Calorie-Calculation = BMR
'    x 1.725
'
'    If you are extra active (very hard exercise/sports & physical job or 2x training) :
'    Calorie-Calculation = BMR x 1.9
'
'
' There are approximately 3500 calories in a pound of stored body fat. So, if you create a 3500-calorie
' deficit through diet, exercise or a combination of both, you will lose one pound of body weight. (On
' average 75% of this is fat, 25% lean tissue) If you create a 7000 calorie deficit you will lose two pounds
' and so on. The calorie deficit can be achieved either by calorie-restriction alone, or by a combination of
' fewer calories in (diet) and more calories out (exercise). This combination of diet and exercise is best
' for lasting weight loss. Indeed, sustained weight loss is difficult or impossible without increased regular
' exercise.
'
' If you want to lose fat, a useful guideline for lowering your calorie intake is to reduce your calories by
' at least 500, but not more than 1000 below your maintenance level. For people with only a small amount of
' weight to lose, 1000 calories will be too much of a deficit. As a guide to minimum calorie intake, the
' American College of Sports Medicine (ACSM) recommends that calorie levels never drop below 1200 calories
' per day for women or 1800 calories per day for men. Even these calorie levels are quite low.
'
' An alternative way of calculating a safe minimum calorie-intake level is by reference to your body weight
' or current body weight. Reducing calories by 15-20% below your daily calorie maintenance needs is a useful
' start. You may increase this depending on your weight loss goals.
' -----------------------------------------------------------------------------------------------------------
Public Function BMR(sex, weightLbs, heightInch, ageYrs)
   BMR = 0
   If ((sex = "M") Or (sex = "m")) Then
      BMR = 66 + (6.23 * weightLbs) + (12.7 * heightInch) - (6.8 * ageYrs)
   ElseIf ((sex = "F") Or (sex = "f")) Then
      BMR = 655 + (4.35 * weightLbs) + (4.7 * heightInch) - (4.7 * ageYrs)
   End If
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the maximum calories per day of a person with the given characteristics
' -----------------------------------------------------------------------------------------------------------
Public Function caloriesPerDay(sex, weightLbs, heightInch, ageYrs, activityFactor)
   caloriesPerDay = BMR(sex, weightLbs, heightInch, ageYrs) * activityFactor
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the maximum Weight Watchers points per day of a person with the given characteristics
' -----------------------------------------------------------------------------------------------------------
Public Function pointsPerDay(sex, weightLbs, heightInch, ageYrs, activityFactor)
   CalsPerDay = caloriesPerDay(sex, weightLbs, heightInch, ageYrs, activityFactor)
   pointsPerDay = CalsPerDay / 50
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the exercise average.  It is a rolling average of the daily exercise values.
' Exercise values are values in the range of 0 .. 8, where:
'
'   0 = no exercise
'
'   2 = exercising this hard every day would be equivalent to light exercise/sports 1-3 days/week
'
'   4 = exercising this hard every day would be equivalent to moderate exercise/sports 3-5 days/week
'
'   6 = exercising this hard every day would be equivalent to hard exercise/sports 6-7 days a week
'
'   8 = exercising this hard every day would be equivalent to very hard exercise/sports and physical job
'
' * Note:  This could easily be calculated by calling RollingAvg() directly in the spreadsheet but is done as
' a seperate function here mostly for the benefit of being able to capture the meaning of the value in this
' comment header.
' -----------------------------------------------------------------------------------------------------------
Public Function exerciseAvg(latestMeasurement, prevAvg, period)
   If (latestMeasurement < 0) Then
      latestMeasurement = 0
   ElseIf (latestMeasurement > 8) Then
      latestMeasurement = 8
   End If
   exerciseAvg = RollingAvg(latestMeasurement, prevAvg, period)
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' -----------------------------------------------------------------------------------------------------------
Public Function exerciseAvgWithGap(latestMeasurement, prevAvg, period, gap)
   If (latestMeasurement < 0) Then
      latestMeasurement = 0
   ElseIf (latestMeasurement > 8) Then
      latestMeasurement = 8
   End If
   exerciseAvgWithGap = RollingAvgWithGap(latestMeasurement, prevAvg, period, gap)
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function converts an exerciseAvg to an activity factor and returns the activity factor.  The activitty
' factor is a measure of how active a person is and ranges from 1.2 to 1.9 as follows:
'
'   1.200 = sedentary (little or no exercise)
'
'   1.375 = lightly active (light exercise/sports 1-3 days/week)
'
'   1.550 = moderately active (moderate exercise/sports 3-5 days/week)
'
'   1.725 = very active (hard exercise/sports 6-7 days a week)
'
'   1.900 = extra active (very hard exercise/sports and physical job)
'
' The activity factor is calculated using the point-intercept form of a line equation: y = mx + b  where m is
' the slope of the line, and b is y-intercept (the point at which the line intercepts the y axis (the value
' of y at x=0)).
'
' The exerciseAvg passed in is a value between 0 and 8 where 0 means absolutely no regular exercise and 8
' means pro football player levels of exercise every day.
' -----------------------------------------------------------------------------------------------------------
Public Function activityFactor(pExerciseAvg)
   activityFactor = ((0.175 / 2) * pExerciseAvg) + 1.2
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the number of reps at a given weight that yeilds the
' given work
' -----------------------------------------------------------------------------------------------------------
Public Function reps(pWeight, pWork)
   reps = Application.Floor(pWork / pWeight, 1)
End Function



' ===========================================================================================================
' ===========================================================================================================
' ===========================================================================================================
' This function returns the weight at a given number of reps that yeilds
' the given work
' -----------------------------------------------------------------------------------------------------------
Public Function wgt(pWork, pMinReps)
   wgt = min(Application.Floor(pWork / pMinReps, 10), 210)
End Function