Fakultas Ilmu Komputer UI

Commit 5f47a017 authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo Committed by Muzaki Azami
Browse files

Pbi 2 dietela quiz items

parent 0d0dd730
class DietProfileChoices:
CHOICES_GENDER = (
(1, 'Laki-laki'),
(2, 'Perempuan'),
)
CHOICES_SPECIAL_CONDITION = (
(1, "Tidak ada"),
(2, "Hamil Trimester 1"),
(3, "Hamil Trimester 2"),
(4, "Hamil Trimester 3"),
(5, "Menyusui Bayi 0-6 Bulan"),
(6, "Menyusui Bayi 7-12 Bulan"),
)
CHOICES_BODY_ACTIVITY = (
(1, "Lebih banyak duduk dan tidak rutin olahraga"),
(2, "Banyak jalan, banyak bergerak, tetapi tidak rutin olahraga"),
(3, "Olahraga rutin 30-45 menit per hari"),
(4, "Olahraga rutin 45-60 menit per hari"),
(5, "Olahraga rutin lebih dari 60 menit per hari"),
)
CHOICES_VEGETABLES_IN_ONE_DAY = (
(1, "0 porsi"),
(2, "1 porsi"),
(3, "2 porsi"),
(4, "3 porsi"),
(5, "Lebih dari 3 porsi"),
)
CHOICES_FRUITS_IN_ONE_DAY = (
(1, "0 porsi"),
(2, "1 porsi"),
(3, "2 porsi"),
(4, "3 porsi"),
(5, "Lebih dari 3 porsi"),
)
CHOICES_FRIED_FOOD_IN_ONE_DAY = (
(1, "0 potong"),
(2, "1 potong"),
(3, "2 potong"),
(4, "3 potong"),
(5, "Lebih dari 3 potong"),
)
CHOICES_SWEET_SNACKS_IN_ONE_DAY = (
(1, "0 potong"),
(2, "1 potong"),
(3, "2 potong"),
(4, "3 potong"),
(5, "Lebih dari 3 potong"),
)
CHOICES_SWEET_DRINKS_IN_ONE_DAY = (
(1, "0 gelas"),
(2, "1 gelas"),
(3, "2 gelas"),
(4, "3 gelas"),
(5, "Lebih dari 3 gelas"),
)
CHOICES_PACKAGED_FOOD_IN_ONE_DAY = (
(1, "0 porsi"),
(2, "1 porsi"),
(3, "2 porsi"),
(4, "3 porsi"),
(5, "Lebih dari 3 porsi"),
)
CHOICES_LARGE_MEAL_IN_ONE_DAY = (
(1, "1 kali"),
(2, "2 kali"),
(3, "3 kali"),
(4, "Lebih dari 3 kali"),
)
CHOICES_SNACKS_IN_ONE_DAY = (
(1, "Tidak pernah"),
(2, "1 kali "),
(3, "2 kali"),
(4, "3 kali"),
(5, "Lebih dari 3 kali"),
)
CHOICES_BREAKFAST_TYPE = (
(1, "Tidak pernah makan pagi"),
(2, "Makanan yang ringan saja"),
(3, "Makanan yang sampai mengenyangkan perut"),
)
CHOICES_CURRENT_CONDITION = (
(1, "Saya belum tertarik melakukan diet dan gaya hidup sehat dan tidak tahu kondisi gizi serta kesehatan saya"),
(2, "Saya belum tertarik melakukan diet dan gaya hidup sehat meskipun saya tahu kondisi gizi dan kesehatan saya"),
(3, "Saya mulai tertarik melakukan diet dan gaya hidup sehat meskipun saya tidak tahu kondisi gizi dan kesehatan saya"),
(4, "Saya mulai tertarik melakukan diet dan gaya hidup sehat dan tahu kondisi gizi dan kesehatan saya"),
(5, "Saya sudah tahu manfaat diet dan gaya hidup sehat namun belum tahu harus mulai menerapkannya dari mana"),
(6, "Saya sudah pernah merubah diet dan gaya hidup menjadi lebih sehat tetapi tidak bertahan lama (dilakukan kurang dari 6 bulan)"),
(7, "Saya sudah pernah berhasil menjalani diet dan gaya hidup sehat selama lebih dari 6 bulan dan ingin melakukannya lagi"),
)
CHOICES_PROBLEM_TO_SOLVE = (
(1, "Turun berat badan dengan target yang realistis"),
(2, "Naik berat badan dengan target yang realistis"),
(3, "Berat badan yang bertahan permanen, menjaga agar berat badan tidak naik, anti yo-yo diet"),
(4, "Butuh pengaturan gizi Ibu Hamil"),
(5, "Butuh pengaturan gizi Ibu Menyusui"),
(6, "Menyiapkan tubuh untuk mencapai kesuburan dan persiapan kehamilan"),
(7, "Mengatur gula darah tinggi (Pre-diabetes), hiperlipidemia (kolesterol), hipertensi (tekanan darah tinggi)"),
(8, "Capai pola makan sehat dan tetap enjoy menikmati makanan yang disukai"),
(9, "Transisi vegan"),
(10, " Butuh pengaturan gizi pada anak-anak atau remaja"),
)
CHOICES_HEALTH_PROBLEM = (
(1, "Tidak ada yang perlu dikhawatirkan"),
(2, "Diabetes Tipe 2"),
(3, "Diabetes Tipe 1"),
(4, "PCOS (Polycystic Ovary Syndrome)"),
(5, "Kolesterol tinggi"),
(6, "Asam urat tinggi"),
(7, "Tekanan darah tinggi"),
(8, "Gula darah tinggi"),
(9, "Kanker"),
(10, "HIV/AIDS"),
(11, "Maag/GERD/Dispepsia/Gangguan lambung"),
(12, "Penyintas Kanker"),
(13, "Penyakit Kronis Lainnya"),
)
from django.db import models
# Choices 17-20 is for items 16-22, choice 8 is also needed
class Gender(models.IntegerChoices):
MALE = 1, 'Laki-laki'
FEMALE = 2, 'Perempuan'
# Input 17
CHOICES_BREAKFAST = (
(1, "Tidak pernah makan pagi"),
(2, "Makanan yang ringan saja"),
(3, "Makanan yang sampai mengenyangkan perut"),
)
class SpecialCondition(models.IntegerChoices):
NONE = 1, 'Tidak ada'
PREGNANT_1 = 2, 'Hamil Trimester 1'
PREGNANT_2 = 3, 'Hamil Trimester 2'
PREGNANT_3 = 4, 'Hamil Trimester 3'
MILK_1 = 5, 'Menyusui Bayi 0-6 Bulan'
MILK_2 = 6, 'Menyusui Bayi 7-12 Bulan'
# Input 18
CHOICES_YOUR_CONDITION = (
(1, "Saya belum tertarik melakukan diet dan gaya hidup sehat dan tidak tahu kondisi gizi serta kesehatan saya"),
(2, "Saya belum tertarik melakukan diet dan gaya hidup sehat meskipun saya tahu kondisi gizi dan kesehatan saya"),
(3, "Saya mulai tertarik melakukan diet dan gaya hidup sehat meskipun saya tidak tahu kondisi gizi dan kesehatan saya"),
(4, "Saya mulai tertarik melakukan diet dan gaya hidup sehat dan tahu kondisi gizi dan kesehatan saya"),
(5, "Saya sudah tahu manfaat diet dan gaya hidup sehat namun belum tahu harus mulai menerapkannya dari mana"),
(6, "Saya sudah pernah merubah diet dan gaya hidup menjadi lebih sehat tetapi tidak bertahan lama (dilakukan kurang dari 6 bulan)"),
(7, "Saya sudah pernah berhasil menjalani diet dan gaya hidup sehat selama lebih dari 6 bulan dan ingin melakukannya lagi")
)
class BodyActivity(models.IntegerChoices):
NO_SPORT = 1, 'Lebih banyak duduk dan tidak rutin olahraga'
WALK = 2, 'Banyak jalan, banyak bergerak, tetapi tidak rutin olahraga'
ROUTINE_1 = 3, 'Olahraga rutin 30-45 menit per hari'
ROUTINE_2 = 4, 'Olahraga rutin 45-60 menit per hari'
ROUTINE_3 = 5, 'Olahraga rutin lebih dari 60 menit per hari'
# Input 19
CHOICES_YOUR_PROBLEM = (
(1, "Turun berat badan dengan target yang realistis"),
(2, "Naik berat badan dengan target yang realistis"),
(3, "Berat badan yang bertahan permanen, menjaga agar berat badan tidak naik, anti yo-yo diet"),
(4, "Butuh pengaturan gizi Ibu Hamil"),
(5, "Butuh pengaturan gizi Ibu Menyusui"),
(6, "Menyiapkan tubuh untuk mencapai kesuburan dan persiapan kehamilan"),
(7, "Mengatur gula darah tinggi (Pre-diabetes), hiperlipidemia (kolesterol), hipertensi (tekanan darah tinggi)"),
(8, "Capai pola makan sehat dan tetap enjoy menikmati makanan yang disukai"),
(9, "Transisi vegan"),
(10, "Butuh pengaturan gizi pada anak-anak atau remaja"),
)
class PiecesInOneDay(models.IntegerChoices):
NO_PIECE = 1, '0 potong'
ONE_PIECE = 2, '1 potong'
TWO_PIECES = 3, '2 potong'
THREE_PIECES = 4, '3 potong'
MORE_PIECES = 5, 'Lebih dari 3 potong'
# Input 20
CHOICES_HEALTH_PROBLEM = (
(1, "Tidak ada yang perlu dikhawatirkan"),
(2, "Diabetes Tipe 2"),
(3, "Diabetes Tipe 1"),
(4, "PCOS (Polycystic Ovary Syndrome)"),
(5, "Kolesterol tinggi"),
(6, "Asam urat tinggi"),
(7, "Tekanan darah tinggi"),
(8, "Gula darah tinggi"),
(9, "Kanker"),
(10, "HIV/AIDS"),
(11, "Maag/GERD/Dispepsia/Gangguan lambung"),
(12, "Penyintas Kanker"),
(13, "Penyakit Kronis Lainnya"),
)
class DrinksInOneDay(models.IntegerChoices):
NO_GLASS = 1, '0 gelas'
ONE_GLASS = 2, '1 gelas'
TWO_GLASSES = 3, '2 gelas'
THREE_GLASSES = 4, '3 gelas'
MORE_GLASSES = 5, 'Lebih dari 3 gelas'
class PortionInOneDay(models.IntegerChoices):
NO_PORTION = 1, '0 porsi'
ONE_PORTION = 2, '1 porsi'
TWO_PORTIONS = 3, '2 porsi'
THREE_PORTIONS = 4, '3 porsi'
MORE_PORTIONS = 5, 'Lebih dari 3 porsi'
class LargeMealInOneDay(models.IntegerChoices):
ONE_TIME = 1, '1 kali'
TWO_TIMES = 2, '2 kali'
THREE_TIMES = 3, '3 kali'
MORE_TIMES = 4, 'Lebih dari 3 kali'
class SnacksInOneDay(models.IntegerChoices):
NONE = 1, 'Tidak pernah'
ONE_TIME = 2, '1 kali'
TWO_TIMES = 3, '2 kali'
THREE_TIMES = 4, '3 kali'
MORE_TIMES = 5, 'Lebih dari 3 kali'
class Breakfast(models.IntegerChoices):
NONE = 1, 'Tidak pernah makan pagi'
LIGHT = 2, 'Makanan yang ringan saja'
HEAVY = 3, 'Makanan yang sampai mengenyangkan perut'
class CurrentCondition(models.IntegerChoices):
CONDITION_1 = 1, 'Saya belum tertarik melakukan diet dan gaya hidup sehat dan tidak tahu kondisi gizi serta kesehatan saya'
CONDITION_2 = 2, 'Saya belum tertarik melakukan diet dan gaya hidup sehat meskipun saya tahu kondisi gizi dan kesehatan saya'
CONDITION_3 = 3, 'Saya mulai tertarik melakukan diet dan gaya hidup sehat meskipun saya tidak tahu kondisi gizi dan kesehatan saya'
CONDITION_4 = 4, 'Saya mulai tertarik melakukan diet dan gaya hidup sehat dan tahu kondisi gizi dan kesehatan saya'
CONDITION_5 = 5, 'Saya sudah tahu manfaat diet dan gaya hidup sehat namun belum tahu harus mulai menerapkannya dari mana'
CONDITION_6 = 6, 'Saya sudah pernah merubah diet dan gaya hidup menjadi lebih sehat tetapi tidak bertahan lama (dilakukan kurang dari 6 bulan)'
CONDITION_7 = 7, 'Saya sudah pernah berhasil menjalani diet dan gaya hidup sehat selama lebih dari 6 bulan dan ingin melakukannya lagi'
class ProblemToSolve(models.IntegerChoices):
PROBLEM_1 = 1, 'Turun berat badan dengan target yang realistis'
PROBLEM_2 = 2, 'Naik berat badan dengan target yang realistis'
PROBLEM_3 = 3, 'Berat badan yang bertahan permanen, menjaga agar berat badan tidak naik, anti yo-yo diet'
PROBLEM_4 = 4, 'Butuh pengaturan gizi Ibu Hamil'
PROBLEM_5 = 5, 'Butuh pengaturan gizi Ibu Menyusui'
PROBLEM_6 = 6, 'Menyiapkan tubuh untuk mencapai kesuburan dan persiapan kehamilan'
PROBLEM_7 = 7, 'Mengatur gula darah tinggi (Pre-diabetes), hiperlipidemia (kolesterol), hipertensi (tekanan darah tinggi)'
PROBLEM_8 = 8, 'Capai pola makan sehat dan tetap enjoy menikmati makanan yang disukai'
PROBLEM_9 = 9, 'Transisi vegan'
PROBLEM_10 = 10, ' Butuh pengaturan gizi pada anak-anak atau remaja'
class HealthProblem(models.IntegerChoices):
PROBLEM_1 = 1, 'Tidak ada yang perlu dikhawatirkan'
PROBLEM_2 = 2, 'Diabetes Tipe 2'
PROBLEM_3 = 3, 'Diabetes Tipe 1'
PROBLEM_4 = 4, 'PCOS (Polycystic Ovary Syndrome)'
PROBLEM_5 = 5, 'Kolesterol tinggi'
PROBLEM_6 = 6, 'Asam urat tinggi'
PROBLEM_7 = 7, 'Tekanan darah tinggi'
PROBLEM_8 = 8, 'Gula darah tinggi'
PROBLEM_9 = 9, 'Kanker'
PROBLEM_10 = 10, 'HIV/AIDS'
PROBLEM_11 = 11, 'Maag/GERD/Dispepsia/Gangguan lambung'
PROBLEM_12 = 12, 'Penyintas Kanker'
PROBLEM_13 = 13, 'Penyakit Kronis Lainnya'
......@@ -33,3 +33,12 @@ class BodyMassConstants:
OBESITY1 = "Obesitas 1"
OBESITY2 = "Obesitas 2"
class VegetableAndFruitSufficiencyResponse:
STILL_NOT_ENOUGH = "Kurang makan sayur dan buah"
ENOUGH = "Asupan sayur dan buah sudah cukup"
class VegetableAndFruitDietRecommendation:
STILL_NOT_ENOUGH = "Yah.. asupan buah & sayur kamu masih kurang nih. Yuk, cari solusi agar kamu bisa konsumsi setidaknya 2 porsi sayur & 3 porsi buah atau sebaliknya per hari. Pokoknya kalau di total kamu perlu 5 porsi buah & sayur per hari."
ENOUGH = "Selamat! Kamu sudah memenuhi salah satu langkah menuju hidup sehat. Pertahankan untuk konsumsi setidaknya 2 porsi sayur & 3 porsi buah atau sebaliknya per hari ya. Pokoknya kalau di total kamu perlu 5 porsi buah dan sayur per sehari."
from constants.quiz_constants import *
from constants.model_choices import *
def body_mass_index(weight, height):
if (weight < 0) or (height < 0):
raise ValueError("Invalid input!")
return weight / ((height / 100)**2)
......@@ -18,10 +21,15 @@ def nutrition_status(body_mass_index):
def ideal_weight_range(height):
if (height < 0):
raise ValueError("Invalid input!")
return {'min': 19 * ((height / 100)**2), 'max': 23 * ((height / 100)**2)}
def basic_energy_needs(gender, weight, height, age):
if (gender > 2) or (gender < 1) or (
weight < 0) or (height < 0) or (age < 0):
raise ValueError("Invalid input!")
if (gender == 1):
return (10 * weight) + (6.25 * height - 5 * age) + 5
else:
......@@ -29,6 +37,8 @@ def basic_energy_needs(gender, weight, height, age):
def physical_activity_percentage(body_activity):
if (body_activity > 5) or (body_activity < 1):
raise ValueError("Invalid choice number!")
physical_activity_percentage_switch = {
1: 0.20,
2: 0.20,
......@@ -139,3 +149,85 @@ def program_recommendation(condition, target, disease):
programs_dictionary['priority_1'] = ProgramRecommendationResponse.TRIAL
programs_dictionary['priority_2'] = None
return programs_dictionary
def calculate_specific_nutrition_needs(
percentage, daily_energy_needs, denominator):
return ((percentage / 100) * daily_energy_needs) / denominator
def protein_needs(
special_condition_choice,
body_mass_index,
daily_energy_needs):
client_nutrition_status = nutrition_status(body_mass_index)
if (
special_condition_choice != 1) or (
client_nutrition_status == BodyMassConstants.UNDERWEIGHT) or (
client_nutrition_status == BodyMassConstants.NORMAL) or (
client_nutrition_status == BodyMassConstants.PREOBESITY):
return calculate_specific_nutrition_needs(13, daily_energy_needs, 4)
return calculate_specific_nutrition_needs(18, daily_energy_needs, 4)
def fat_needs(special_condition_choice, body_mass_index, daily_energy_needs):
client_nutrition_status = nutrition_status(body_mass_index)
if (
special_condition_choice != 1) or (
client_nutrition_status == BodyMassConstants.UNDERWEIGHT) or (
client_nutrition_status == BodyMassConstants.NORMAL) or (
client_nutrition_status == BodyMassConstants.PREOBESITY):
return calculate_specific_nutrition_needs(30, daily_energy_needs, 9)
return calculate_specific_nutrition_needs(27, daily_energy_needs, 9)
def carbohydrate_needs(
special_condition_choice,
body_mass_index,
daily_energy_needs):
client_nutrition_status = nutrition_status(body_mass_index)
if (
special_condition_choice != 1) or (
client_nutrition_status == BodyMassConstants.UNDERWEIGHT) or (
client_nutrition_status == BodyMassConstants.NORMAL) or (
client_nutrition_status == BodyMassConstants.PREOBESITY):
return calculate_specific_nutrition_needs(57, daily_energy_needs, 4)
return calculate_specific_nutrition_needs(55, daily_energy_needs, 4)
def fiber_needs(body_mass_index):
return 25
def get_food_consumed_score(choice):
return choice - 1
def get_total_vegetable_and_fruit_score(vegetable_choice, fruit_choice):
if (vegetable_choice < 1) or (vegetable_choice > 5) or (
fruit_choice < 1) or (fruit_choice > 5):
raise ValueError("Invalid choice number!")
vegetable_score = get_food_consumed_score(vegetable_choice)
fruit_score = get_food_consumed_score(fruit_choice)
return vegetable_score + fruit_score
def get_vegetable_and_fruit_sufficiency_response(
total_vegetable_and_fruit_score):
if (total_vegetable_and_fruit_score < 0) or (
total_vegetable_and_fruit_score > 8):
raise ValueError("Invalid total score!")
if (0 <= total_vegetable_and_fruit_score <= 4):
return VegetableAndFruitSufficiencyResponse.STILL_NOT_ENOUGH
return VegetableAndFruitSufficiencyResponse.ENOUGH
def get_vegetable_and_fruit_diet_recommendation(
vegetable_and_fruit_suffiency_response):
if (vegetable_and_fruit_suffiency_response ==
VegetableAndFruitSufficiencyResponse.STILL_NOT_ENOUGH):
return VegetableAndFruitDietRecommendation.STILL_NOT_ENOUGH
return VegetableAndFruitDietRecommendation.ENOUGH
# Generated by Django 3.1 on 2021-03-23 14:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dietela_quiz', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='dietprofile',
name='snacks_in_one_day',
field=models.IntegerField(choices=[(1, 'Tidak pernah'), (2, '1 kali'), (3, '2 kali'), (4, '3 kali'), (5, 'Lebih dari 3 kali')]),
),
]
from django.db import models
from constants.model_choices import DietProfileChoices
from constants.model_choices import (
Gender,
SpecialCondition,
BodyActivity,
PiecesInOneDay,
DrinksInOneDay,
PortionInOneDay,
LargeMealInOneDay,
SnacksInOneDay,
Breakfast,
CurrentCondition,
ProblemToSolve,
HealthProblem
)
from multiselectfield import MultiSelectField
......@@ -9,32 +22,32 @@ class DietProfile(models.Model):
age = models.PositiveIntegerField()
weight = models.PositiveIntegerField()
height = models.PositiveIntegerField()
gender = models.IntegerField(choices=DietProfileChoices.CHOICES_GENDER)
gender = models.IntegerField(choices=Gender.choices)
special_condition = models.IntegerField(
choices=DietProfileChoices.CHOICES_SPECIAL_CONDITION)
choices=SpecialCondition.choices)
body_activity = models.IntegerField(
choices=DietProfileChoices.CHOICES_BODY_ACTIVITY)
choices=BodyActivity.choices)
vegetables_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_VEGETABLES_IN_ONE_DAY)
choices=PortionInOneDay.choices)
fruits_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_FRUITS_IN_ONE_DAY)
choices=PortionInOneDay.choices)
fried_food_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_FRIED_FOOD_IN_ONE_DAY)
choices=PiecesInOneDay.choices)
sweet_snacks_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_SWEET_SNACKS_IN_ONE_DAY)
choices=PiecesInOneDay.choices)
sweet_drinks_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_SWEET_DRINKS_IN_ONE_DAY)
choices=DrinksInOneDay.choices)
packaged_food_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_PACKAGED_FOOD_IN_ONE_DAY)
choices=PortionInOneDay.choices)
large_meal_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_LARGE_MEAL_IN_ONE_DAY)
choices=LargeMealInOneDay.choices)
snacks_in_one_day = models.IntegerField(
choices=DietProfileChoices.CHOICES_SNACKS_IN_ONE_DAY)
choices=SnacksInOneDay.choices)
breakfast_type = models.IntegerField(
choices=DietProfileChoices.CHOICES_BREAKFAST_TYPE)
choices=Breakfast.choices)
current_condition = models.IntegerField(
choices=DietProfileChoices.CHOICES_CURRENT_CONDITION)
choices=CurrentCondition.choices)
problem_to_solve = models.IntegerField(
choices=DietProfileChoices.CHOICES_PROBLEM_TO_SOLVE)
choices=ProblemToSolve.choices)
health_problem = MultiSelectField(
choices=DietProfileChoices.CHOICES_HEALTH_PROBLEM)
choices=HealthProblem.choices)
from rest_framework import fields, serializers
from constants.model_choices import DietProfileChoices
from constants.model_choices import HealthProblem
from .models import DietProfile
class DietProfileSerializer(serializers.ModelSerializer):
health_problem = fields.MultipleChoiceField(
choices=DietProfileChoices.CHOICES_HEALTH_PROBLEM)
choices=HealthProblem.choices)
class Meta:
model = DietProfile
......
import json
import unittest
from rest_framework.test import APITestCase
from rest_framework import status
from .models import DietProfile
from django.test import TestCase
from constants.quiz_constants import *
from constants.model_choices import DietProfileChoices
from .formulas import (
body_mass_index,
nutrition_status,
......@@ -15,7 +15,16 @@ from .formulas import (
recommendation_breakfast,
energy_needed_per_dine,
physical_activity_recommendation,
program_recommendation
program_recommendation,
calculate_specific_nutrition_needs,
protein_needs,
fat_needs,
carbohydrate_needs,
fiber_needs,
get_food_consumed_score,
get_total_vegetable_and_fruit_score,
get_vegetable_and_fruit_sufficiency_response,
get_vegetable_and_fruit_diet_recommendation,
)
......@@ -111,6 +120,16 @@ class FormulaTest(TestCase):
self.assertEqual(body_mass_index(weight, height),
weight / ((height / 100)**2))
def test_invalid_input_body_mass_index(self):
weight_1 = -1
height_1 = 172
weight_2 = 61
height_2 = -1
with self.assertRaises(ValueError):
body_mass_index(weight_1, height_1)
with self.assertRaises(ValueError):
body_mass_index(weight_2, height_2)
def test_nutrition_status(self):
self.assertEqual(nutrition_status(18), BodyMassConstants.UNDERWEIGHT)
self.assertEqual(nutrition_status(20.62), BodyMassConstants.NORMAL)
......@@ -124,6 +143,11 @@ class FormulaTest(TestCase):
{'min': 19 * ((height / 100)**2),
'max': 23 * ((height / 100)**2)})
def test_invalid_input_ideal_weight_range(self):
with self.assertRaises(ValueError):
height = -1
ideal_weight_range(height)
def test_basic_energy_needs(self):
gender_male = 1
gender_female = 2
......@@ -138,6 +162,17 @@ class FormulaTest(TestCase):
age),
(10 * weight) + (6.25 * height - 5 * age) - 161)
def test_invalid_input_basic_energy_needs(self):
gender_male = 0
gender_female = 3
weight = -1
height = -1
age = -1
with self.assertRaises(ValueError):
basic_energy_needs(gender_male, weight, height, age)
with self.assertRaises(ValueError):
basic_energy_needs(gender_female, weight, height, age)
def test_physical_activity_percentage(self):
self.assertEqual(physical_activity_percentage(1), 0.20)
self.assertEqual(physical_activity_percentage(2), 0.20)
......@@ -145,6 +180,12 @@ class FormulaTest(TestCase):
self.assertEqual(physical_activity_percentage(4), 0.35)
self.assertEqual(physical_activity_percentage(5), 0.40)
def test_invalid_input_physical_activity_percentage(self):
with self.assertRaises(ValueError):
physical_activity_percentage(0)
with self.assertRaises(ValueError):
physical_activity_percentage(6)
def test_daily_energy_needs(self):
basic_energy_needs = 100
physical_activity_percentage = 0.2
......@@ -424,3 +465,168 @@ class FormulaTest(TestCase):
client_type_9.get('priority_1'),
ProgramRecommendationResponse.TRIAL)
self.assertEqual(client_type_9.get('priority_2'), None)
def test_calculate_specific_nutrition_needs(self):
percentage = 50
daily_energy_needs = 500
denominator = 10
self.assertEqual(
calculate_specific_nutrition_needs(
percentage,
daily_energy_needs,
denominator),
25)
def test_protein_needs_condition_1(self):
special_condition_choice = 3
body_mass_index = 20
daily_energy_needs = 500
self.assertEquals(
protein_needs(