Activités physiques : A propos de l'IMC
L'IMC (indice de masse corporelle) détermine le taux de gras.
Ce taux est un indicateur de votre surchage pondérale.
Formule de calcul de Masse corporelle:
| ( |
Poids en livres |
) |
* 703 |
| ______________ |
| Taille en pouce 2 |
Attention : Si vous êtes particulièrement musclé (Masse musculaire importante) l'indice IMC peut vous classer dans "obèse"
];
# $about_hb_height is for the height (in pixels) of the popup explanation
# window. You may **CHANGE** this to get a taller window. Note: it's
# probably a bad idea to make this bigger than 600.
$about_hb_height = "400";
# $about_hb_width is for the width (in pixels) of the popup explanation
# window. You may **CHANGE** this to get a wider window. It's probably
# a bad idea to make this bigger than 400.
$about_hb_width = "300";
#########################################################################
##### #
##### This is the end of the part where you must **CHANGE** #
##### things. Feel free to look through the code if you are #
##### interested in checking out such things, but don't change #
##### anything beyond this point unless you know what you're doing. #
##### Since this is a free script, there is no warranty, but if there #
##### were a warranty, you'd definitely void it if you modified stuff #
##### below this line. :-) #
##### #
#########################################################################
# First, we get the data submitted on the form into variables we can
# use.
# This line just makes it so everything printed by the script is printed
# immediately instead of being "buffered."
$| = 1;
# This line calles the parse_form_data subroutine, which grabs all the
# input from the form into an associative array so we can use the
# variables.
%data = &parse_form_data();
# And this line must be in any CGI script: it tells your web browser
# that HTML stuff is coming out. If you had a CGI script that showed
# an image, you might use "Content-type: image/gif", but you have to
# have a content-type (or MIME header) of some kind. If you were using
# the Perl CGI module with "use CGI;" then you could probably do something
# like "print header;" but oddly enough, a lot of servers don't have the
# CGI module, so we're taking no chances.
print "Content-type: text/html\n\n";
# If you remove this link, without replacing it with a similar
# HTML comment (as above in the License section) you are in violation
# of the license for this program. No, I don't have the resources to
# enforce this, and I know that some people will remove it anyway.
# But honestly, since you didn't have to pay for this, is the link
# really too much to ask? :)
$footer = "$footer";
#################################################################
# If it's one of the popup window links that people are clicking on,
# we're just going to print out whatever explanation there is, and exit.
if($data{'FA'} eq "AboutHB"){ &print_explanation($notes); }
if($data{'FA'} eq "AboutBMR"){ &print_explanation($bmr_notes); }
if($data{'FA'} eq "AboutBMI"){ &print_explanation($bmi_notes); }
if($data{'FA'} eq "AboutLifestyle"){ &print_explanation($lifestyle_notes); }
# If not, then we're going to print the whole form and so forth. First,
# print our HTML for the top of the page.
print $header;
# Now, figure out whether they chose kilos/centimeters or pounds/inches.
# They could also choose pounds/centimeters, or kilos/inches. We will
# convert if necessary. :-)
$kilos_or_pounds = $data{'wt'};
$centimeters_or_inches = $data{'ht'};
# This next set of things is just checking so that if they enter
# strange values (weight less than 0 or gender that is not "m" or "f",
# age over 120, etc) we just show a little red * next to the form
# field, and don't bother trying to calculate anything. :-)
# If weight is not a number at all, or if it is blank, or if it
# is less than or equal to zero, do the error.
$weight = $data{'weight'};
if($weight * 1 ne $weight || $weight eq "" || $weight <= 0){
$errweight = "
*";
$no_calc = 1;
}
# Same for height.
$height = $data{'height'};
if($height * 1 ne $height || $height eq "" || $height <=0 ){
$errheight = "
*";
$no_calc = 1;
}
# Same for age, except we also don't allow ages over 120.
# My apologies in advance to anyone over the age of 120
# attempting to use this calculator.
$age = $data{'age'};
if($age == 0 || $age eq "" || $age > 120 | $age < 0){
$errage = "
*";
$no_calc = 1;
}
# If gender is not "m" or "f", do an error.
$gender = $data{'gender'};
if($gender ne "m" && $gender ne "f"){
$errgender = "
*";
$no_calc = 1;
}
# If their lifestyle is "bed bound," or anything but the general
# lifestyle multiples, we just call it the same as the BMR.
# I don't think you're really supposed to do this with Harris-Benedict
# calculations, but I have, in the past, wanted to do the base calculation
# so therefore everyone gets to.
$lifestyle = $data{'lifestyle'};
if($lifestyle != 1.2 &&
$lifestyle != 1.375 &&
$lifestyle != 1.55 &&
$lifestyle != 1.725 &&
$lifestyle != 1.9){
$lifestyle = 1;
}
# Set a variable to tell us it's okay to do the calculations if we
# didn't hit one of our errors above.
if($no_calc != 1){ $do_calc = 1; }
# We're just going to do the formula in pounds and inches, regardless.
# So, if they entered it in kilos or centimeters, we need to convert.
# Since the answers are ratios, the numbers will be the same whichever
# we use.
if($kilos_or_pounds eq "k"){
$weight = &convert_to_pounds($weight);
}
else {
$weight = $weight;
}
if($centimeters_or_inches eq "c"){
$height = &convert_to_inches($height);
}
else {
$height = $height;
}
# There are two formulae for BMR: one for men and one for women. If they
# entered female, do the one for women. The sprintf() thing tells it
# to display as a number with no decimal places.
if($gender eq "f" && $do_calc == 1){
# This is the female version of the formula
$BMR = sprintf("%d", 655 + (4.35 * $weight) + (4.7 * $height) - (4.7 * $age));
}
# Otherwise, do the one for men.
elsif($gender eq "m" && $do_calc == 1){
# This is the male version of the formula
$BMR = sprintf("%d", 66 + (6.23 * $weight) + (12.7 * $height) - (6.8 * $age));
}
# If they're not male or female, or there was another error above,
# then it's No BMR for You!
else {
$BMR = 0;
}
# We're also going to do some little calcs for plus and minus 5 and 20% so
# people can see a range. sprintf("%d", some number) makes it chop off any
# decimal places and just show a whole number.
$HB_main = sprintf("%d",$BMR * $lifestyle);
$BMR_plus_20 = sprintf("%d", $BMR + ($BMR * 0.2));
$HB_plus_20 = sprintf("%d",$BMR_plus_20 * $lifestyle);
$BMR_plus_5 = sprintf("%d",$BMR + ($BMR * 0.05));
$HB_plus_5 = sprintf("%d",$BMR_plus_5 * $lifestyle);
$BMR_minus_20 = sprintf("%d",$BMR - ($BMR * 0.2));
$HB_minus_20 = sprintf("%d",$BMR_minus_20 * $lifestyle);
$BMR_minus_5 = sprintf("%d",$BMR - ($BMR * 0.05));
$HB_minus_5 = sprintf("%d",$BMR_minus_5 * $lifestyle);
$HB = qq[
| Métabolisme basal ] .
qq[(?)] .
qq[ | Besoins en calories ] .
qq[(?)] .
qq[ |
| - 20% = | $BMR_minus_20 |
- 20% = | $HB_minus_20 |
| - 5% = | $BMR_minus_5 |
- 5% = | $HB_minus_5 |
| Besoins par jour : | $BMR |
Besoins par jour : | $HB_main |
| + 5% = | $BMR_plus_5 |
+ 5%: | $HB_plus_5 |
| +20% = | $BMR_plus_20 |
+ 20% = | $HB_plus_20 |
];
# Now everything is in pounds and inches, since HB is relative anyway.
# Calculate BMI because the code was already stolen from SFEBMIcalc and
# what the heck -- give people more info!
if($weight > 0 && $height > 0){
$BMI = sprintf("%.02f", ( $weight / ($height * $height)) * 703);
}
else {
$BMI = "?";
}
# The get_form subroutine pretty much prints out the form, saves whatever
# they entered, etc.
print &get_form;
$about_hb_link = qq[
] .
qq[infos calculateur];
print qq[
|
];
print "$HB" if $HB;
print "Vos besoins en calories sont inconnus: calculez les!" if !$HB;
print qq[
|
];
print $about_hb_link;
print qq[
|
];
print $footer;
exit();
sub get_form {
$form = "
Calcul des besoins quotidiens en calories
(Basé sur la formule Harris-Benedict)
|
| Masse corporelle (IMC) |
Résultats |
| + de 29.9 |
Obésité |
| Entre 25.0 et 29.9 |
Surcharge pondérale |
| Entre 18.5 et 24.9 |
Poids normal |
| Moins de 18.5 |
Poids insuffisant |
| Votre IMC : |
$BMI |
| A propos de l'IMC |
|
| |
";
$form;
}
sub parse_form_data {
my($string,%data,@data);
# get data
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$_ = $string = $ENV{'QUERY_STRING'};
tr/\"~;/_/;
$string = $_;
}
else { read(STDIN, $string, $ENV{'CONTENT_LENGTH'});
$_ = $string;
$OK_CHARS='a-zA-Z0-9=&%\n\/_\-\.@';
tr/\"~;/_/;
$string = $_;
}
# split data into name=value pairs
@data = split(/&/, $string);
# split into name=value pairs in associative array
foreach (@data) {
split(/=/, $_);
$_[0] =~ s/\+/ /g; # plus to space
$_[0] =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
$data{"$_[0]"} = $_[1];
}
# translate special characters
foreach (keys %data) {
$data{"$_"} =~ s/\+/ /g; # plus to space
$data{"$_"} =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
}
%data; # return associative array of name=value
}
sub convert_to_pounds {
my($kilos) = $_[0];
my($pounds) = $kilos * 2.20462262;
$pounds;
}
sub convert_to_inches {
my($centimeters) = $_[0];
my($inches) = $centimeters * 0.393700787;
$inches;
}
sub print_explanation {
print "$_[0]";
exit();
}
|