From e84917a598274824abc74b67094e87346f8309b7 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Fri, 24 Nov 2023 20:29:07 -0500 Subject: [PATCH 1/5] beautify email, summarize past week calorie intake and burnout, show net calories --- application.py | 87 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/application.py b/application.py index b7ab340a..1586ccc0 100644 --- a/application.py +++ b/application.py @@ -12,6 +12,8 @@ from flask_mail import Mail from flask_pymongo import PyMongo from tabulate import tabulate +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm, WorkoutForm from service import history as history_service import openai @@ -484,14 +486,23 @@ def send_email(): # Output: Calorie History Received on specified email # ########################## email = session.get('email') - data = list( - mongo.db.calories.find({'email': email}, - {'date', 'email', 'calories'})) - print(data) + data = list(mongo.db.calories.find({'email': email}, {'date', 'email', 'calories'})) + workout_data = list(mongo.db.workout.find({'email': email}, {'date', 'email', 'burnout'})) + print(data, workout_data) + + one_week_ago = datetime.now() - timedelta(days=7) + + filtered_data = [a for a in data if datetime.strptime(a['date'], '%Y-%m-%d') >= one_week_ago] + filtered_workout_data = [a for a in workout_data if datetime.strptime(a['date'], '%Y-%m-%d') >= one_week_ago] + table = [['Date', 'Email ID', 'Calories']] - for a in data: + + for a in filtered_data: tmp = [a['date'], a['email'], a['calories']] table.append(tmp) + for a in filtered_workout_data: + tmp = [a['date'], a['email'], int(a['burnout'])*(-1)] + table.append(tmp) friend_email = str(request.form.get('share')).strip() friend_email = str(friend_email).split(',') @@ -499,14 +510,72 @@ def send_email(): #Storing sender's email address and password sender_email = "calorieapp508@gmail.com" sender_password = c.email_password + sharing_email = table[1][1] + + positive_calories = [row for row in table[1:] if int(row[2]) > 0] + negative_calories = [row for row in table[1:] if int(row[2]) < 0] + + net_calories = sum(int(row[2]) for row in table[1:]) + + html_table = """ + + + +

Your friend with email {} wants to share their past week's calorie history with you!

+ + +

Calories Gained

+ + + + + + {} +
DateCalories
+ + +

Calories Lost

+ + + + + + {} +
DateCalories
+ + +

Net Calories: {}

+ + + """ + + positive_rows = "" + for row in positive_calories: + positive_rows += "" + for item in [row[0]] + [row[2]]: + positive_rows += "{}".format(item) + positive_rows += "" + + negative_rows = "" + for row in negative_calories: + negative_rows += "" + for item in [row[0]] + [row[2]]: + negative_rows += "{}".format(item) + negative_rows += "" + + formatted_html = html_table.format(sharing_email, positive_rows, negative_rows, net_calories) #Logging in with sender details server.login(sender_email, sender_password) - message = 'Subject: Calorie History\n\n Your Friend wants to share their calorie history with you!\n {}'.format( - tabulate(table)) + message = MIMEMultipart() + message["Subject"] = "Calorie History" + message["From"] = sender_email + + html_content = MIMEText(formatted_html, "html") + message.attach(html_content) for e in friend_email: print(e) - server.sendmail(sender_email, e, message) + server.sendmail(sender_email, e, message.as_string()) server.quit() @@ -895,4 +964,4 @@ def hrx(): # 'ContentType': 'application/json'} if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True) \ No newline at end of file From 7cabd2a1ffb7bc1f4a561ac7b482310396d986a2 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Fri, 24 Nov 2023 20:36:22 -0500 Subject: [PATCH 2/5] beautify email, summarize recent week's +ve -ve calories --- application.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/application.py b/application.py index fa5fde69..27772e14 100644 --- a/application.py +++ b/application.py @@ -502,12 +502,12 @@ def refresh(): @app.route("/send_email", methods=['GET', 'POST']) def send_email(): - # ############################ - # send_email() function shares Calorie History with friend's email - # route "/send_email" will redirect to send_email() function which redirects to friends.html page. - # Input: Email - # Output: Calorie History Received on specified email - # ########################## + ''' + send_email() function shares Calorie History with friend's email + route "/send_email" will redirect to send_email() function which redirects to friends.html page. + Input: Email + Output: Latest Week Calorie History received on specified email + ''' # ##########################''' email = session.get('email') data = list(mongo.db.calories.find({'email': email}, {'date', 'email', 'calories'})) workout_data = list(mongo.db.workout.find({'email': email}, {'date', 'email', 'burnout'})) @@ -530,6 +530,7 @@ def send_email(): friend_email = str(request.form.get('share')).strip() friend_email = str(friend_email).split(',') server = smtplib.SMTP_SSL("smtp.gmail.com", 465) + #Storing sender's email address and password sender_email = "calorieapp508@gmail.com" sender_password = c.email_password From 93a27f13949c11b41cf4f6f8671fef423158e696 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Fri, 24 Nov 2023 20:50:23 -0500 Subject: [PATCH 3/5] add bmi db --- model/WHO_obesityByCountry_2016.csv | 196 ++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 model/WHO_obesityByCountry_2016.csv diff --git a/model/WHO_obesityByCountry_2016.csv b/model/WHO_obesityByCountry_2016.csv new file mode 100644 index 00000000..2291ebf3 --- /dev/null +++ b/model/WHO_obesityByCountry_2016.csv @@ -0,0 +1,196 @@ +"","Both.sexes","Male","Female" +"Afghanistan",4.5,2.7,6.2 +"Albania",22.3,21.9,22.8 +"Algeria",26.6,19.4,34 +"Andorra",28,27.9,28.1 +"Angola",6.8,3.5,10 +"Antigua and Barbuda",19.1,11.7,26.3 +"Argentina",28.5,27.4,29.6 +"Armenia",20.9,17.2,24.5 +"Australia",30.4,30.7,30.1 +"Austria",21.9,23.4,20.6 +"Azerbaijan",19.9,15.7,23.9 +"Bahamas",32.1,24.8,39 +"Bahrain",28.7,24.9,36.1 +"Bangladesh",3.4,2.2,4.6 +"Barbados",24.8,15.6,33.8 +"Belarus",26.6,23.5,29.1 +"Belgium",24.5,25.1,23.9 +"Belize",22.4,15.4,29.4 +"Benin",8.2,4.2,12.2 +"Bhutan",5.8,4.5,7.4 +"Bolivia (Plurinational State of)",18.7,13.4,23.9 +"Bosnia and Herzegovina",19.4,18.1,20.6 +"Botswana",16.1,7,25.5 +"Brazil",22.3,18.5,25.9 +"Brunei Darussalam",14.7,13,16.4 +"Bulgaria",27.4,27.5,27.4 +"Burkina Faso",4.5,2.2,6.8 +"Burundi",4.4,1.8,7 +"Cabo Verde",10.6,6.3,14.9 +"Cambodia",3.5,2.5,4.5 +"Cameroon",9.5,5.2,13.9 +"Canada",31.3,31.2,31.5 +"Central African Republic",6.3,3.2,9.3 +"Chad",4.8,2.6,7 +"Chile",28.8,25.5,32.1 +"China",6.6,6.2,7.1 +"Colombia",22.1,17.3,26.7 +"Comoros",6.9,3,10.8 +"Congo",8.4,4.9,11.8 +"Cook Islands",55.3,52,58.6 +"Costa Rica",25.7,21,30.4 +"Côte d'Ivoire",9,5.2,13.1 +"Croatia",27.1,26,28.2 +"Cuba",26.7,20.4,33 +"Cyprus",22.6,22.4,22.8 +"Czechia",28.5,28.5,28.6 +"Democratic People's Republic of Korea",7.1,6.4,7.8 +"Democratic Republic of the Congo",5.6,3.1,8 +"Denmark",21.3,23.7,18.9 +"Djibouti",12.2,7.9,16.5 +"Dominica",28.2,20,36 +"Dominican Republic",26.9,20.4,33.2 +"Ecuador",19.3,14.4,24.1 +"Egypt",31.1,22,40 +"El Salvador",22.7,17.1,27.4 +"Equatorial Guinea",7.4,3.6,11.4 +"Eritrea",4.1,1.8,6.3 +"Estonia",23.8,21.9,25.3 +"Eswatini",13.5,4.4,22.2 +"Ethiopia",3.6,1.6,5.6 +"Fiji",30,24.9,35.3 +"Finland",24.9,25.7,24.2 +"France",23.2,23.5,23 +"Gabon",13.4,8.6,18.2 +"Gambia",8.7,4.8,12.4 +"Georgia",23.3,20,26 +"Germany",25.7,26.6,24.9 +"Ghana",9.7,4.1,15 +"Greece",27.4,26,28.7 +"Grenada",20.2,12.6,27.6 +"Guatemala",18.8,13.1,23.8 +"Guinea",6.6,3.3,9.9 +"Guinea-Bissau",8.2,4.5,11.8 +"Guyana",19.2,12.2,26.1 +"Haiti",20.5,16.4,24.3 +"Honduras",19.4,14.1,24.5 +"Hungary",28.6,29.9,27.5 +"Iceland",23.1,25.3,20.9 +"India",3.8,2.7,4.9 +"Indonesia",6.9,4.9,9 +"Iran (Islamic Republic of)",25.5,19.1,31.8 +"Iraq",27.4,21,33.8 +"Ireland",26.9,26.5,27.3 +"Israel",26.7,26.1,27.2 +"Italy",22.9,22.5,23.3 +"Jamaica",24.4,15,33.2 +"Japan",4.4,4.6,4.1 +"Jordan",33.4,26.6,40.4 +"Kazakhstan",21.3,18.8,23.4 +"Kenya",6,2.5,9.4 +"Kiribati",45.6,41.2,50 +"Kuwait",37,33,43.9 +"Kyrgyzstan",15.4,13.1,17.5 +"Lao People's Democratic Republic",4.5,3.2,5.7 +"Latvia",25.7,22.9,28 +"Lebanon",31.3,27.4,35.3 +"Lesotho",13.5,3.7,22.8 +"Liberia",8.6,4.9,12.3 +"Libya",31.8,24.5,38.7 +"Lithuania",28.4,25.3,30.9 +"Luxembourg",24.2,26,22.4 +"Madagascar",4.5,2.6,6.3 +"Malawi",4.7,1.9,7.5 +"Malaysia",15.3,12.9,17.6 +"Maldives",7.9,5.4,10.3 +"Mali",7.1,3.9,10.4 +"Malta",31,30.9,31.2 +"Marshall Islands",52.4,47.9,56.9 +"Mauritania",11.3,6,16.6 +"Mauritius",11.5,5.9,16.8 +"Mexico",28.4,23.7,32.6 +"Micronesia (Federated States of)",41.6,36.1,47.3 +"Monaco",NA,NA,NA +"Mongolia",19.6,16.7,22.4 +"Montenegro",24.9,24.5,25.2 +"Morocco",25.6,19,31.9 +"Mozambique",6,2.8,8.9 +"Myanmar",5.7,4,7.3 +"Namibia",15,6.5,22.7 +"Nauru",60.7,58.5,63 +"Nepal",3.8,2.5,4.8 +"Netherlands",23.1,22.7,23.4 +"New Zealand",32,31,32.9 +"Nicaragua",21.8,16.5,26.8 +"Niger",4.7,2.3,7.2 +"Nigeria",7.8,4.1,11.5 +"Niue",49.3,44.2,54.5 +"Norway",25,25.1,24.8 +"Oman",22.9,19.5,30.8 +"Pakistan",7.8,5.5,10.1 +"Palau",54.9,51.3,58.4 +"Panama",22.5,17.6,27.5 +"Papua New Guinea",19.4,15.2,23.7 +"Paraguay",19,16.1,21.9 +"Peru",19.1,14.7,23.5 +"Philippines",6,5,7 +"Poland",25.6,25.4,25.7 +"Portugal",23.2,22.1,24.2 +"Qatar",33.9,31.9,41.8 +"Republic of Korea",4.9,4.6,5.3 +"Republic of Moldova",20.1,16.9,23 +"Romania",24.5,24.9,24.2 +"Russian Federation",25.7,19.4,30.8 +"Rwanda",4.8,1.6,7.7 +"Saint Kitts and Nevis",23.1,15.4,30.5 +"Saint Lucia",19.8,12,27.2 +"Saint Vincent and the Grenadines",23.8,16.7,31 +"Samoa",45.5,38.2,53.2 +"San Marino",NA,NA,NA +"Sao Tome and Principe",10.6,6.3,14.8 +"Saudi Arabia",35,31,41.2 +"Senegal",7.4,3.3,11 +"Serbia",23.5,22.5,24.5 +"Seychelles",14.6,8.1,21.4 +"Sierra Leone",7.5,3.4,11.6 +"Singapore",6.6,6.2,7 +"Slovakia",22.4,22.5,22.3 +"Slovenia",22.5,21.4,23.6 +"Solomon Islands",20.5,16.3,24.7 +"Somalia",6.9,3.4,10.3 +"South Africa",27,14.5,38.5 +"South Sudan",NA,NA,NA +"Spain",27.1,27.1,27.2 +"Sri Lanka",5.4,3,7.7 +"Sudan",NA,NA,NA +"Sudan (former)",7.4,3.4,10.7 +"Suriname",26.5,19,33.9 +"Sweden",22.1,24.2,20 +"Switzerland",21.2,23.7,18.8 +"Syrian Arab Republic",25.8,19.3,32.4 +"Tajikistan",12.6,10.4,14.6 +"Thailand",10.8,7.5,13.8 +"Republic of North Macedonia",23.9,23.8,23.9 +"Timor-Leste",2.9,2.1,3.8 +"Togo",7.1,3.4,10.7 +"Tonga",45.9,39,52.6 +"Trinidad and Tobago",19.7,11.4,27.7 +"Tunisia",27.3,19.3,34.9 +"Turkey",32.2,24.2,39.7 +"Turkmenistan",17.5,15,19.9 +"Tuvalu",51,46.4,55.6 +"Uganda",4.1,1.5,6.8 +"Ukraine",26.1,23.2,28.4 +"United Arab Emirates",29.9,26.7,38.8 +"United Kingdom of Great Britain and Northern Ireland",29.5,28.6,30.4 +"United Republic of Tanzania",7.1,3.4,10.7 +"United States of America",37.3,36.5,38.2 +"Uruguay",28.9,25.3,32.1 +"Uzbekistan",15.3,12.9,17.7 +"Vanuatu",23.5,18.8,28.1 +"Venezuela (Bolivarian Republic of)",25.2,22.1,28.3 +"Viet Nam",2.1,1.6,2.6 +"Yemen",14.1,9.9,18.2 +"Zambia",6.5,3,10 +"Zimbabwe",12.3,3.7,20.5 From d6a7121b99602f22f5a909976af51577691323a2 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Sat, 25 Nov 2023 11:43:10 -0500 Subject: [PATCH 4/5] bmi countries etl --- insert_food_bmi_data.py | 38 +++ insert_food_data.py | 14 - model/WHO_obesityByCountry_2016.csv | 392 ++++++++++++++-------------- templates/bmi_cal.html | 38 +++ 4 files changed, 272 insertions(+), 210 deletions(-) create mode 100644 insert_food_bmi_data.py delete mode 100644 insert_food_data.py diff --git a/insert_food_bmi_data.py b/insert_food_bmi_data.py new file mode 100644 index 00000000..50355f42 --- /dev/null +++ b/insert_food_bmi_data.py @@ -0,0 +1,38 @@ +from apps import App +import pandas as pd + +app = App() +mongo = app.mongo + +# Clear existing data in the 'food' and 'obesity' collections +mongo.db.food.delete_many({}) +mongo.db.obesity.delete_many({}) + +# Food Data +f = open('food_data/calories.csv', 'r', encoding="ISO-8859-1") +l = f.readlines() + +for i in range(1, len(l)): + l[i] = l[i][1:len(l[i]) - 2] + +for i in range(1, len(l)): + temp = l[i].split(",") + mongo.db.food.insert_one({'food': temp[0], 'calories': temp[1]}) + +# BMI data +df = pd.read_csv('model/WHO_obesityByCountry_2016.csv') + +for index, row in df.iterrows(): + country_name = row['Country'] + both_sexes = row['Both.sexes'] + male = row['Male'] + female = row['Female'] + + mongo.db.obesity.insert_one({ + 'country_name': country_name, + 'both_sexes': both_sexes, + 'male': male, + 'female': female + }) + +print("Data inserted into MongoDB.") \ No newline at end of file diff --git a/insert_food_data.py b/insert_food_data.py deleted file mode 100644 index e9a60b0d..00000000 --- a/insert_food_data.py +++ /dev/null @@ -1,14 +0,0 @@ -from apps import App - -app = App() -mongo = app.mongo - -f = open('food_data/calories.csv', 'r', encoding="ISO-8859-1") -l = f.readlines() - -for i in range(1, len(l)): - l[i] = l[i][1:len(l[i]) - 2] - -for i in range(1, len(l)): - temp = l[i].split(",") - mongo.db.food.insert_one({'food': temp[0], 'calories': temp[1]}) diff --git a/model/WHO_obesityByCountry_2016.csv b/model/WHO_obesityByCountry_2016.csv index 2291ebf3..be61c5fe 100644 --- a/model/WHO_obesityByCountry_2016.csv +++ b/model/WHO_obesityByCountry_2016.csv @@ -1,196 +1,196 @@ -"","Both.sexes","Male","Female" -"Afghanistan",4.5,2.7,6.2 -"Albania",22.3,21.9,22.8 -"Algeria",26.6,19.4,34 -"Andorra",28,27.9,28.1 -"Angola",6.8,3.5,10 -"Antigua and Barbuda",19.1,11.7,26.3 -"Argentina",28.5,27.4,29.6 -"Armenia",20.9,17.2,24.5 -"Australia",30.4,30.7,30.1 -"Austria",21.9,23.4,20.6 -"Azerbaijan",19.9,15.7,23.9 -"Bahamas",32.1,24.8,39 -"Bahrain",28.7,24.9,36.1 -"Bangladesh",3.4,2.2,4.6 -"Barbados",24.8,15.6,33.8 -"Belarus",26.6,23.5,29.1 -"Belgium",24.5,25.1,23.9 -"Belize",22.4,15.4,29.4 -"Benin",8.2,4.2,12.2 -"Bhutan",5.8,4.5,7.4 -"Bolivia (Plurinational State of)",18.7,13.4,23.9 -"Bosnia and Herzegovina",19.4,18.1,20.6 -"Botswana",16.1,7,25.5 -"Brazil",22.3,18.5,25.9 -"Brunei Darussalam",14.7,13,16.4 -"Bulgaria",27.4,27.5,27.4 -"Burkina Faso",4.5,2.2,6.8 -"Burundi",4.4,1.8,7 -"Cabo Verde",10.6,6.3,14.9 -"Cambodia",3.5,2.5,4.5 -"Cameroon",9.5,5.2,13.9 -"Canada",31.3,31.2,31.5 -"Central African Republic",6.3,3.2,9.3 -"Chad",4.8,2.6,7 -"Chile",28.8,25.5,32.1 -"China",6.6,6.2,7.1 -"Colombia",22.1,17.3,26.7 -"Comoros",6.9,3,10.8 -"Congo",8.4,4.9,11.8 -"Cook Islands",55.3,52,58.6 -"Costa Rica",25.7,21,30.4 -"Côte d'Ivoire",9,5.2,13.1 -"Croatia",27.1,26,28.2 -"Cuba",26.7,20.4,33 -"Cyprus",22.6,22.4,22.8 -"Czechia",28.5,28.5,28.6 -"Democratic People's Republic of Korea",7.1,6.4,7.8 -"Democratic Republic of the Congo",5.6,3.1,8 -"Denmark",21.3,23.7,18.9 -"Djibouti",12.2,7.9,16.5 -"Dominica",28.2,20,36 -"Dominican Republic",26.9,20.4,33.2 -"Ecuador",19.3,14.4,24.1 -"Egypt",31.1,22,40 -"El Salvador",22.7,17.1,27.4 -"Equatorial Guinea",7.4,3.6,11.4 -"Eritrea",4.1,1.8,6.3 -"Estonia",23.8,21.9,25.3 -"Eswatini",13.5,4.4,22.2 -"Ethiopia",3.6,1.6,5.6 -"Fiji",30,24.9,35.3 -"Finland",24.9,25.7,24.2 -"France",23.2,23.5,23 -"Gabon",13.4,8.6,18.2 -"Gambia",8.7,4.8,12.4 -"Georgia",23.3,20,26 -"Germany",25.7,26.6,24.9 -"Ghana",9.7,4.1,15 -"Greece",27.4,26,28.7 -"Grenada",20.2,12.6,27.6 -"Guatemala",18.8,13.1,23.8 -"Guinea",6.6,3.3,9.9 -"Guinea-Bissau",8.2,4.5,11.8 -"Guyana",19.2,12.2,26.1 -"Haiti",20.5,16.4,24.3 -"Honduras",19.4,14.1,24.5 -"Hungary",28.6,29.9,27.5 -"Iceland",23.1,25.3,20.9 -"India",3.8,2.7,4.9 -"Indonesia",6.9,4.9,9 -"Iran (Islamic Republic of)",25.5,19.1,31.8 -"Iraq",27.4,21,33.8 -"Ireland",26.9,26.5,27.3 -"Israel",26.7,26.1,27.2 -"Italy",22.9,22.5,23.3 -"Jamaica",24.4,15,33.2 -"Japan",4.4,4.6,4.1 -"Jordan",33.4,26.6,40.4 -"Kazakhstan",21.3,18.8,23.4 -"Kenya",6,2.5,9.4 -"Kiribati",45.6,41.2,50 -"Kuwait",37,33,43.9 -"Kyrgyzstan",15.4,13.1,17.5 -"Lao People's Democratic Republic",4.5,3.2,5.7 -"Latvia",25.7,22.9,28 -"Lebanon",31.3,27.4,35.3 -"Lesotho",13.5,3.7,22.8 -"Liberia",8.6,4.9,12.3 -"Libya",31.8,24.5,38.7 -"Lithuania",28.4,25.3,30.9 -"Luxembourg",24.2,26,22.4 -"Madagascar",4.5,2.6,6.3 -"Malawi",4.7,1.9,7.5 -"Malaysia",15.3,12.9,17.6 -"Maldives",7.9,5.4,10.3 -"Mali",7.1,3.9,10.4 -"Malta",31,30.9,31.2 -"Marshall Islands",52.4,47.9,56.9 -"Mauritania",11.3,6,16.6 -"Mauritius",11.5,5.9,16.8 -"Mexico",28.4,23.7,32.6 -"Micronesia (Federated States of)",41.6,36.1,47.3 -"Monaco",NA,NA,NA -"Mongolia",19.6,16.7,22.4 -"Montenegro",24.9,24.5,25.2 -"Morocco",25.6,19,31.9 -"Mozambique",6,2.8,8.9 -"Myanmar",5.7,4,7.3 -"Namibia",15,6.5,22.7 -"Nauru",60.7,58.5,63 -"Nepal",3.8,2.5,4.8 -"Netherlands",23.1,22.7,23.4 -"New Zealand",32,31,32.9 -"Nicaragua",21.8,16.5,26.8 -"Niger",4.7,2.3,7.2 -"Nigeria",7.8,4.1,11.5 -"Niue",49.3,44.2,54.5 -"Norway",25,25.1,24.8 -"Oman",22.9,19.5,30.8 -"Pakistan",7.8,5.5,10.1 -"Palau",54.9,51.3,58.4 -"Panama",22.5,17.6,27.5 -"Papua New Guinea",19.4,15.2,23.7 -"Paraguay",19,16.1,21.9 -"Peru",19.1,14.7,23.5 -"Philippines",6,5,7 -"Poland",25.6,25.4,25.7 -"Portugal",23.2,22.1,24.2 -"Qatar",33.9,31.9,41.8 -"Republic of Korea",4.9,4.6,5.3 -"Republic of Moldova",20.1,16.9,23 -"Romania",24.5,24.9,24.2 -"Russian Federation",25.7,19.4,30.8 -"Rwanda",4.8,1.6,7.7 -"Saint Kitts and Nevis",23.1,15.4,30.5 -"Saint Lucia",19.8,12,27.2 -"Saint Vincent and the Grenadines",23.8,16.7,31 -"Samoa",45.5,38.2,53.2 -"San Marino",NA,NA,NA -"Sao Tome and Principe",10.6,6.3,14.8 -"Saudi Arabia",35,31,41.2 -"Senegal",7.4,3.3,11 -"Serbia",23.5,22.5,24.5 -"Seychelles",14.6,8.1,21.4 -"Sierra Leone",7.5,3.4,11.6 -"Singapore",6.6,6.2,7 -"Slovakia",22.4,22.5,22.3 -"Slovenia",22.5,21.4,23.6 -"Solomon Islands",20.5,16.3,24.7 -"Somalia",6.9,3.4,10.3 -"South Africa",27,14.5,38.5 -"South Sudan",NA,NA,NA -"Spain",27.1,27.1,27.2 -"Sri Lanka",5.4,3,7.7 -"Sudan",NA,NA,NA -"Sudan (former)",7.4,3.4,10.7 -"Suriname",26.5,19,33.9 -"Sweden",22.1,24.2,20 -"Switzerland",21.2,23.7,18.8 -"Syrian Arab Republic",25.8,19.3,32.4 -"Tajikistan",12.6,10.4,14.6 -"Thailand",10.8,7.5,13.8 -"Republic of North Macedonia",23.9,23.8,23.9 -"Timor-Leste",2.9,2.1,3.8 -"Togo",7.1,3.4,10.7 -"Tonga",45.9,39,52.6 -"Trinidad and Tobago",19.7,11.4,27.7 -"Tunisia",27.3,19.3,34.9 -"Turkey",32.2,24.2,39.7 -"Turkmenistan",17.5,15,19.9 -"Tuvalu",51,46.4,55.6 -"Uganda",4.1,1.5,6.8 -"Ukraine",26.1,23.2,28.4 -"United Arab Emirates",29.9,26.7,38.8 -"United Kingdom of Great Britain and Northern Ireland",29.5,28.6,30.4 -"United Republic of Tanzania",7.1,3.4,10.7 -"United States of America",37.3,36.5,38.2 -"Uruguay",28.9,25.3,32.1 -"Uzbekistan",15.3,12.9,17.7 -"Vanuatu",23.5,18.8,28.1 -"Venezuela (Bolivarian Republic of)",25.2,22.1,28.3 -"Viet Nam",2.1,1.6,2.6 -"Yemen",14.1,9.9,18.2 -"Zambia",6.5,3,10 -"Zimbabwe",12.3,3.7,20.5 +Country,Both.sexes,Male,Female +Afghanistan,4.5,2.7,6.2 +Albania,22.3,21.9,22.8 +Algeria,26.6,19.4,34 +Andorra,28,27.9,28.1 +Angola,6.8,3.5,10 +Antigua and Barbuda,19.1,11.7,26.3 +Argentina,28.5,27.4,29.6 +Armenia,20.9,17.2,24.5 +Australia,30.4,30.7,30.1 +Austria,21.9,23.4,20.6 +Azerbaijan,19.9,15.7,23.9 +Bahamas,32.1,24.8,39 +Bahrain,28.7,24.9,36.1 +Bangladesh,3.4,2.2,4.6 +Barbados,24.8,15.6,33.8 +Belarus,26.6,23.5,29.1 +Belgium,24.5,25.1,23.9 +Belize,22.4,15.4,29.4 +Benin,8.2,4.2,12.2 +Bhutan,5.8,4.5,7.4 +Bolivia (Plurinational State of),18.7,13.4,23.9 +Bosnia and Herzegovina,19.4,18.1,20.6 +Botswana,16.1,7,25.5 +Brazil,22.3,18.5,25.9 +Brunei Darussalam,14.7,13,16.4 +Bulgaria,27.4,27.5,27.4 +Burkina Faso,4.5,2.2,6.8 +Burundi,4.4,1.8,7 +Cabo Verde,10.6,6.3,14.9 +Cambodia,3.5,2.5,4.5 +Cameroon,9.5,5.2,13.9 +Canada,31.3,31.2,31.5 +Central African Republic,6.3,3.2,9.3 +Chad,4.8,2.6,7 +Chile,28.8,25.5,32.1 +China,6.6,6.2,7.1 +Colombia,22.1,17.3,26.7 +Comoros,6.9,3,10.8 +Congo,8.4,4.9,11.8 +Cook Islands,55.3,52,58.6 +Costa Rica,25.7,21,30.4 +Côte d'Ivoire,9,5.2,13.1 +Croatia,27.1,26,28.2 +Cuba,26.7,20.4,33 +Cyprus,22.6,22.4,22.8 +Czechia,28.5,28.5,28.6 +Democratic People's Republic of Korea,7.1,6.4,7.8 +Democratic Republic of the Congo,5.6,3.1,8 +Denmark,21.3,23.7,18.9 +Djibouti,12.2,7.9,16.5 +Dominica,28.2,20,36 +Dominican Republic,26.9,20.4,33.2 +Ecuador,19.3,14.4,24.1 +Egypt,31.1,22,40 +El Salvador,22.7,17.1,27.4 +Equatorial Guinea,7.4,3.6,11.4 +Eritrea,4.1,1.8,6.3 +Estonia,23.8,21.9,25.3 +Eswatini,13.5,4.4,22.2 +Ethiopia,3.6,1.6,5.6 +Fiji,30,24.9,35.3 +Finland,24.9,25.7,24.2 +France,23.2,23.5,23 +Gabon,13.4,8.6,18.2 +Gambia,8.7,4.8,12.4 +Georgia,23.3,20,26 +Germany,25.7,26.6,24.9 +Ghana,9.7,4.1,15 +Greece,27.4,26,28.7 +Grenada,20.2,12.6,27.6 +Guatemala,18.8,13.1,23.8 +Guinea,6.6,3.3,9.9 +Guinea-Bissau,8.2,4.5,11.8 +Guyana,19.2,12.2,26.1 +Haiti,20.5,16.4,24.3 +Honduras,19.4,14.1,24.5 +Hungary,28.6,29.9,27.5 +Iceland,23.1,25.3,20.9 +India,3.8,2.7,4.9 +Indonesia,6.9,4.9,9 +Iran (Islamic Republic of),25.5,19.1,31.8 +Iraq,27.4,21,33.8 +Ireland,26.9,26.5,27.3 +Israel,26.7,26.1,27.2 +Italy,22.9,22.5,23.3 +Jamaica,24.4,15,33.2 +Japan,4.4,4.6,4.1 +Jordan,33.4,26.6,40.4 +Kazakhstan,21.3,18.8,23.4 +Kenya,6,2.5,9.4 +Kiribati,45.6,41.2,50 +Kuwait,37,33,43.9 +Kyrgyzstan,15.4,13.1,17.5 +Lao People's Democratic Republic,4.5,3.2,5.7 +Latvia,25.7,22.9,28 +Lebanon,31.3,27.4,35.3 +Lesotho,13.5,3.7,22.8 +Liberia,8.6,4.9,12.3 +Libya,31.8,24.5,38.7 +Lithuania,28.4,25.3,30.9 +Luxembourg,24.2,26,22.4 +Madagascar,4.5,2.6,6.3 +Malawi,4.7,1.9,7.5 +Malaysia,15.3,12.9,17.6 +Maldives,7.9,5.4,10.3 +Mali,7.1,3.9,10.4 +Malta,31,30.9,31.2 +Marshall Islands,52.4,47.9,56.9 +Mauritania,11.3,6,16.6 +Mauritius,11.5,5.9,16.8 +Mexico,28.4,23.7,32.6 +Micronesia (Federated States of),41.6,36.1,47.3 +Monaco,NA,NA,NA +Mongolia,19.6,16.7,22.4 +Montenegro,24.9,24.5,25.2 +Morocco,25.6,19,31.9 +Mozambique,6,2.8,8.9 +Myanmar,5.7,4,7.3 +Namibia,15,6.5,22.7 +Nauru,60.7,58.5,63 +Nepal,3.8,2.5,4.8 +Netherlands,23.1,22.7,23.4 +New Zealand,32,31,32.9 +Nicaragua,21.8,16.5,26.8 +Niger,4.7,2.3,7.2 +Nigeria,7.8,4.1,11.5 +Niue,49.3,44.2,54.5 +Norway,25,25.1,24.8 +Oman,22.9,19.5,30.8 +Pakistan,7.8,5.5,10.1 +Palau,54.9,51.3,58.4 +Panama,22.5,17.6,27.5 +Papua New Guinea,19.4,15.2,23.7 +Paraguay,19,16.1,21.9 +Peru,19.1,14.7,23.5 +Philippines,6,5,7 +Poland,25.6,25.4,25.7 +Portugal,23.2,22.1,24.2 +Qatar,33.9,31.9,41.8 +Republic of Korea,4.9,4.6,5.3 +Republic of Moldova,20.1,16.9,23 +Romania,24.5,24.9,24.2 +Russian Federation,25.7,19.4,30.8 +Rwanda,4.8,1.6,7.7 +Saint Kitts and Nevis,23.1,15.4,30.5 +Saint Lucia,19.8,12,27.2 +Saint Vincent and the Grenadines,23.8,16.7,31 +Samoa,45.5,38.2,53.2 +San Marino,NA,NA,NA +Sao Tome and Principe,10.6,6.3,14.8 +Saudi Arabia,35,31,41.2 +Senegal,7.4,3.3,11 +Serbia,23.5,22.5,24.5 +Seychelles,14.6,8.1,21.4 +Sierra Leone,7.5,3.4,11.6 +Singapore,6.6,6.2,7 +Slovakia,22.4,22.5,22.3 +Slovenia,22.5,21.4,23.6 +Solomon Islands,20.5,16.3,24.7 +Somalia,6.9,3.4,10.3 +South Africa,27,14.5,38.5 +South Sudan,NA,NA,NA +Spain,27.1,27.1,27.2 +Sri Lanka,5.4,3,7.7 +Sudan,NA,NA,NA +Sudan (former),7.4,3.4,10.7 +Suriname,26.5,19,33.9 +Sweden,22.1,24.2,20 +Switzerland,21.2,23.7,18.8 +Syrian Arab Republic,25.8,19.3,32.4 +Tajikistan,12.6,10.4,14.6 +Thailand,10.8,7.5,13.8 +Republic of North Macedonia,23.9,23.8,23.9 +Timor-Leste,2.9,2.1,3.8 +Togo,7.1,3.4,10.7 +Tonga,45.9,39,52.6 +Trinidad and Tobago,19.7,11.4,27.7 +Tunisia,27.3,19.3,34.9 +Turkey,32.2,24.2,39.7 +Turkmenistan,17.5,15,19.9 +Tuvalu,51,46.4,55.6 +Uganda,4.1,1.5,6.8 +Ukraine,26.1,23.2,28.4 +United Arab Emirates,29.9,26.7,38.8 +United Kingdom of Great Britain and Northern Ireland,29.5,28.6,30.4 +United Republic of Tanzania,7.1,3.4,10.7 +United States of America,37.3,36.5,38.2 +Uruguay,28.9,25.3,32.1 +Uzbekistan,15.3,12.9,17.7 +Vanuatu,23.5,18.8,28.1 +Venezuela (Bolivarian Republic of),25.2,22.1,28.3 +Viet Nam,2.1,1.6,2.6 +Yemen,14.1,9.9,18.2 +Zambia,6.5,3,10 +Zimbabwe,12.3,3.7,20.5 diff --git a/templates/bmi_cal.html b/templates/bmi_cal.html index 070a4107..df47c773 100644 --- a/templates/bmi_cal.html +++ b/templates/bmi_cal.html @@ -62,6 +62,14 @@

BMI Calculator

You fall into the category of

+ +
+ + +
+ @@ -77,7 +85,36 @@

BMI Calculator

+ + {% endblock content %} From 0c038c3cc1806a33912bc15b9896ac13379172af Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Sat, 25 Nov 2023 13:12:00 -0500 Subject: [PATCH 5/5] show avg bmi by country and gender --- application.py | 39 +++++++++++++++++++++++++++++- templates/bmi_cal.html | 54 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/application.py b/application.py index c9269f9d..c61bda2b 100644 --- a/application.py +++ b/application.py @@ -8,7 +8,7 @@ # from apps import App from flask import json # from utilities import Utilities -from flask import render_template, session, url_for, flash, redirect, request, Flask +from flask import render_template, session, url_for, flash, redirect, request, Flask, jsonify from flask_mail import Mail from flask_pymongo import PyMongo from tabulate import tabulate @@ -972,6 +972,43 @@ def hrx(): return redirect(url_for('dashboard')) return render_template('hrx.html', title='HRX', form=form) +@app.route('/get_countries', methods=['GET']) +def get_countries(): + ''' + Populate countries in the bmi_cal.html dropdown from mongodb + ''' + countries = [country['country_name'] for country in mongo.db.obesity.find({}, {'country_name': 1, '_id': 0})] + return jsonify({'countries': countries}) + +@app.route('/get_average_bmi', methods=['GET']) +def get_average_bmi(): + ''' + Fetch the average bmi values from database + ''' + country = request.args.get('country') + gender = request.args.get('gender') + + bmi_data_for_country = list(mongo.db.obesity.find({'country_name': country})) + + # Get the keys for both sexes, male, and female + gender_keys = ['both_sexes', 'male', 'female'] + + # Dictionary to store average BMI values + average_bmi_data = {} + + # Calculate average BMI for both sexes + both_sexes_data = [entry[key] for entry in bmi_data_for_country for key in gender_keys if key in entry] + total_both_sexes = sum(both_sexes_data) + average_bmi_data['both_sexes'] = total_both_sexes / len(both_sexes_data) + + # Calculate average BMI for the selected gender + if gender in gender_keys: + selected_gender_data = [entry[gender] for entry in bmi_data_for_country if gender in entry] + total_selected_gender = sum(selected_gender_data) + average_bmi_data[gender] = total_selected_gender / len(selected_gender_data) + else: + return jsonify({'error': 'Invalid gender parameter'}), 400 + return jsonify(average_bmi_data) # @app.route("/ajaxdashboard", methods=['POST']) # def ajaxdashboard(): diff --git a/templates/bmi_cal.html b/templates/bmi_cal.html index df47c773..12f727bc 100644 --- a/templates/bmi_cal.html +++ b/templates/bmi_cal.html @@ -29,12 +29,12 @@

BMI Calculator

@@ -68,7 +68,14 @@

BMI Calculator

- + + + @@ -88,6 +95,42 @@

BMI Calculator