From 9de9e40f8b183a20c88bcf3e13a60948505ef45e Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:29:18 -0500 Subject: [PATCH 1/8] Added coverage stuff --- .travis.yml | 4 +++- requirements.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 988eef1..e465cf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,9 @@ python: install: - pip install -r requirements.txt script: - - python -m unittest discover + - coverage -m unittest discover +after_success: + - coveralls branches: only: - dev diff --git a/requirements.txt b/requirements.txt index 6d6b456..383627b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ Flask==1.1.2 Flask-WTF==0.14.3 waitress==2.0.0 -flake8==3.9.0 \ No newline at end of file +flake8==3.9.0 +coverage==5.5 +coveralls==3.0.1 \ No newline at end of file From 3bf9a5759aafa4bd70c360905ee59fd98f44be67 Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:32:35 -0500 Subject: [PATCH 2/8] Fixed .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e465cf8..e421aef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: install: - pip install -r requirements.txt script: - - coverage -m unittest discover + - coverage run -m unittest discover after_success: - coveralls branches: From 5f56a5b12b23512e154056668e4cf98158f5eb29 Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:37:30 -0500 Subject: [PATCH 3/8] Added omit to coverage travisyml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e421aef..169ef0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,8 @@ python: install: - pip install -r requirements.txt script: - - coverage run -m unittest discover + - coverage run co-m unittest discover + - coverage report --omit=src/templates after_success: - coveralls branches: From f36d336aa809aa1a2fe51138f11f9c99dea290cc Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:40:18 -0500 Subject: [PATCH 4/8] Fix coverage stuff --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 169ef0c..5b85aa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,10 @@ python: install: - pip install -r requirements.txt script: - - coverage run co-m unittest discover + - coverage run -m unittest discover - coverage report --omit=src/templates after_success: - coveralls branches: only: - dev - - master From a4b8f69d9fc7d2c655bc6c5e5c6e9716d269904a Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:41:57 -0500 Subject: [PATCH 5/8] Added master back to branch list --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5b85aa3..859f062 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,4 @@ after_success: branches: only: - dev + - master \ No newline at end of file From aaa813de8b101a70426ac4480189d9d81de015fc Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 20:50:43 -0500 Subject: [PATCH 6/8] Added coveragerc --- .coveragerc | 5 +++++ .travis.yml | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..334b88e --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[run] +omit = + src/app.py + src/main.py + src/forms.py \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 859f062..2563d20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ install: - pip install -r requirements.txt script: - coverage run -m unittest discover - - coverage report --omit=src/templates after_success: - coveralls branches: From 11c98bd5711e62f3fe5b7fb92e37d9a16fee4c84 Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 21:08:59 -0500 Subject: [PATCH 7/8] Removed for failed test --- src/classes/bodymassindex.py | 104 ----------------------------------- 1 file changed, 104 deletions(-) delete mode 100644 src/classes/bodymassindex.py diff --git a/src/classes/bodymassindex.py b/src/classes/bodymassindex.py deleted file mode 100644 index 64461da..0000000 --- a/src/classes/bodymassindex.py +++ /dev/null @@ -1,104 +0,0 @@ -# CJ Nguyen -# 2/23/2021 - -# Class containing the data and functionality for computing body mass index -# (BMI) values and categories. Calculation for BMI sourced from -# http://extoxnet.orst.edu/faqs/dietcancer/web2/twohowto.html -from .bmi_categories import BodyMassIndexCategory - - -class BodyMassIndex: - """Class of which each instance represents BMI measurements for a single - person and offers functionality for calculating BMI values and - discerning BMI categories. - - Attributes ---------- weight: weight of the person height: height of the - person bmi_value: the body mass index value of a person rounded to the - tenths place. bmi_category: the body mass category of a person - - Methods ------- calculate_body_mass_index: calculates the body mass - index value using weight and height and sets the bmi_value and - bmi_category attributes. get_weight: returns the weight attribute of the - BodyMassIndex object get_height: returns the height attribute of the - BodyMassIndex object get_bmi_value: returns the bmi_value attribute of - the BodyMassIndex object get_bmi_category: returns the bmi_category - attribute of the BodyMassIndex object - - NOTE: Because of the nature of Python floats, rounding the tenths place - for the bmi_value attribute will sometimes result in unexpected output. - For example, round(52.15) will give 52.1 despite round(52.16) giving 52.2. - """ - - def __init__(self, weight=None, height=None): - """Creates an instance of a BodyMassIndex object. - :param height: height in inches - :type height: float - :param weight: weight in pounds - :type weight: float - """ - if weight is not None and height is not None: - try: - weight = float(weight) - height = float(height) - except ValueError: - raise (TypeError( - "Weight and height must be floating point integers.")) - if weight <= 0 or weight > 900: - raise (ValueError( - "Weight must be greater than 0 and less than or equal to " - "900 pounds.")) - if height <= 0 or height > 108: - # 108 is 9' in inches - raise (ValueError( - "Height must be greater than 0 and less than or equal to " - "108 inches.")) - - self.weight = weight - self.height = height - self.bmi_value = 0.0 - self.bmi_category = 0.0 - self.calculate_body_mass_index() - - def calculate_body_mass_index(self): - """Calculates the BMI value given the weight and height attributes - and sets the bmi_value and bmi_category accordingly - """ - self.bmi_value = round(self.weight * 0.45 / pow(self.height * .025, 2), - 1) - - if self.bmi_value < 18.5: - self.bmi_category = BodyMassIndexCategory.UNDERWEIGHT - elif self.bmi_value < 25.0: - self.bmi_category = BodyMassIndexCategory.NORMAL_WEIGHT - elif self.bmi_value < 30.0: - self.bmi_category = BodyMassIndexCategory.OVER_WEIGHT - else: - self.bmi_category = BodyMassIndexCategory.OBESE - - def get_weight(self): - """Returns the weight attribute""" - return self.weight - - def get_height(self): - """Returns the height attribute""" - return self.height - - def get_bmi_value(self): - """Returns the bmi_value attribute""" - return self.bmi_value - - def get_bmi_category(self): - """Returns the bmi_category attribute""" - return self.bmi_category - - def __eq__(self, other): - """Equivalency check override""" - if type(self) != type(other): - return False - else: - if not (not (self.weight != other.weight) and not ( - self.height != other.height) and not ( - self.bmi_value != other.bmi_value) and not ( - self.bmi_category != other.bmi_category)): - return False - return True From 8775c3d13d9c3e47b0b6f3565c5e95c596c9585e Mon Sep 17 00:00:00 2001 From: CJ Nguyen Date: Tue, 13 Apr 2021 21:12:48 -0500 Subject: [PATCH 8/8] Added bodymassindex.py back --- src/classes/bodymassindex.py | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/classes/bodymassindex.py diff --git a/src/classes/bodymassindex.py b/src/classes/bodymassindex.py new file mode 100644 index 0000000..64461da --- /dev/null +++ b/src/classes/bodymassindex.py @@ -0,0 +1,104 @@ +# CJ Nguyen +# 2/23/2021 + +# Class containing the data and functionality for computing body mass index +# (BMI) values and categories. Calculation for BMI sourced from +# http://extoxnet.orst.edu/faqs/dietcancer/web2/twohowto.html +from .bmi_categories import BodyMassIndexCategory + + +class BodyMassIndex: + """Class of which each instance represents BMI measurements for a single + person and offers functionality for calculating BMI values and + discerning BMI categories. + + Attributes ---------- weight: weight of the person height: height of the + person bmi_value: the body mass index value of a person rounded to the + tenths place. bmi_category: the body mass category of a person + + Methods ------- calculate_body_mass_index: calculates the body mass + index value using weight and height and sets the bmi_value and + bmi_category attributes. get_weight: returns the weight attribute of the + BodyMassIndex object get_height: returns the height attribute of the + BodyMassIndex object get_bmi_value: returns the bmi_value attribute of + the BodyMassIndex object get_bmi_category: returns the bmi_category + attribute of the BodyMassIndex object + + NOTE: Because of the nature of Python floats, rounding the tenths place + for the bmi_value attribute will sometimes result in unexpected output. + For example, round(52.15) will give 52.1 despite round(52.16) giving 52.2. + """ + + def __init__(self, weight=None, height=None): + """Creates an instance of a BodyMassIndex object. + :param height: height in inches + :type height: float + :param weight: weight in pounds + :type weight: float + """ + if weight is not None and height is not None: + try: + weight = float(weight) + height = float(height) + except ValueError: + raise (TypeError( + "Weight and height must be floating point integers.")) + if weight <= 0 or weight > 900: + raise (ValueError( + "Weight must be greater than 0 and less than or equal to " + "900 pounds.")) + if height <= 0 or height > 108: + # 108 is 9' in inches + raise (ValueError( + "Height must be greater than 0 and less than or equal to " + "108 inches.")) + + self.weight = weight + self.height = height + self.bmi_value = 0.0 + self.bmi_category = 0.0 + self.calculate_body_mass_index() + + def calculate_body_mass_index(self): + """Calculates the BMI value given the weight and height attributes + and sets the bmi_value and bmi_category accordingly + """ + self.bmi_value = round(self.weight * 0.45 / pow(self.height * .025, 2), + 1) + + if self.bmi_value < 18.5: + self.bmi_category = BodyMassIndexCategory.UNDERWEIGHT + elif self.bmi_value < 25.0: + self.bmi_category = BodyMassIndexCategory.NORMAL_WEIGHT + elif self.bmi_value < 30.0: + self.bmi_category = BodyMassIndexCategory.OVER_WEIGHT + else: + self.bmi_category = BodyMassIndexCategory.OBESE + + def get_weight(self): + """Returns the weight attribute""" + return self.weight + + def get_height(self): + """Returns the height attribute""" + return self.height + + def get_bmi_value(self): + """Returns the bmi_value attribute""" + return self.bmi_value + + def get_bmi_category(self): + """Returns the bmi_category attribute""" + return self.bmi_category + + def __eq__(self, other): + """Equivalency check override""" + if type(self) != type(other): + return False + else: + if not (not (self.weight != other.weight) and not ( + self.height != other.height) and not ( + self.bmi_value != other.bmi_value) and not ( + self.bmi_category != other.bmi_category)): + return False + return True