Skip to content

Commit

Permalink
t_scoreok
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsds committed Nov 5, 2023
1 parent 82ec176 commit 51aba43
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 56 deletions.
Binary file modified app1/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/views.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion app1/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Meta:
class PersonalInfoForm(forms.ModelForm):
class Meta:
model = PersonalInfo
fields = ['height', 'weight', 'weight_lost']
fields = ['weight', 'height','weight_lost']


class SuperuserCreationForm(UserCreationForm):
Expand Down
2 changes: 1 addition & 1 deletion app1/templates/app1/create_superuser.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>Sign Up</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Create Superuser</button>
<button type="submit">Sign Up</button>
</form>

<p>Already have an account? <a href="{% url 'app1:login' %}">Log in</a></p>
Expand Down
2 changes: 1 addition & 1 deletion app1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
urlpatterns = [
path('', views.index, name='index'), # Example URL pattern
path('about/', views.about, name='about'),
path('illness-form/', views.illness_form, name='illness_form'),
path('illness-form/<int:user_age>/<int:user_height>/<int:user_weight>/<int:user_lost>/', views.illness_form, name='illness_form'),
path('login/', views.login_view, name='login'),
path('create-superuser/', views.create_superuser, name='create_superuser'),
path('home/', views.homepage, name='home'),
Expand Down
112 changes: 60 additions & 52 deletions app1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,13 @@
from django.shortcuts import render, redirect
from .forms import UserInfoForm, PersonalInfoForm,SuperuserCreationForm

# def add_user_info(request):
# user_age = None
# if request.method == 'POST':
# user_info_form = UserInfoForm(request.POST)
# personal_info_form = PersonalInfoForm(request.POST)

# if user_info_form.is_valid() and personal_info_form.is_valid():
# user_info = user_info_form.save()
# personal_info = personal_info_form.save()
# user_age = user_info_form.cleaned_data['age']


# # You can associate the two models if needed
# user_info.personal_info = personal_info
# user_info.save()

# # Redirect to a success page
# return redirect('app1:illness_form')
# else:
# user_info_form = UserInfoForm()
# personal_info_form = PersonalInfoForm()

# return render(request, 'app1/user_info_form.html', {
# 'user_info_form': user_info_form,
# 'personal_info_form': personal_info_form,
# 'user_age': user_age,
# })
from django.shortcuts import render, redirect

def add_user_info(request):
user_age = None
user_weight = None
user_height = None
user_lost = None
if request.method == 'POST':
user_info_form = UserInfoForm(request.POST)
personal_info_form = PersonalInfoForm(request.POST)
Expand All @@ -54,13 +30,16 @@ def add_user_info(request):
user_info = user_info_form.save()
personal_info = personal_info_form.save()
user_age = user_info_form.cleaned_data['age']

user_weight = personal_info_form.cleaned_data['weight']

user_height = personal_info_form.cleaned_data['height']
user_lost = personal_info_form.cleaned_data['weight_lost']

# You can associate the two models if needed
user_info.personal_info = personal_info
user_info.save()

# Redirect to the illness form page
return redirect('app1:illness_form')

return redirect(reverse('app1:illness_form', kwargs={'user_age': user_age, 'user_height': user_height, 'user_weight': user_weight, 'user_lost': user_lost}))

else:
user_info_form = UserInfoForm()
Expand All @@ -70,6 +49,9 @@ def add_user_info(request):
'user_info_form': user_info_form,
'personal_info_form': personal_info_form,
'user_age': user_age,
'user_weight':user_weight,
'user_height':user_height,
'user_lost':user_lost,
})


Expand All @@ -83,7 +65,7 @@ def about(request):
# Example: return a simple text response
return HttpResponse("This is the about page of app1.")

def calculate_total_score(user_age,selected_illnesses, selected_diet_changes, selected_gastr_symptoms, selected_physical): # Define a dictionary to map illness names to their scores
def calculate_total_score( user_age,user_weight,user_height,user_lost,selected_illnesses, selected_diet_changes, selected_gastr_symptoms, selected_physical): # Define a dictionary to map illness names to their scores

illness_scores = {
"Mental illness": 0,
Expand Down Expand Up @@ -128,15 +110,7 @@ def calculate_total_score(user_age,selected_illnesses, selected_diet_changes, se
"Major burns":2,
"Severe burns":3,
"Head injury/ Multiple Trauma":3,}
# Calculate the total score for selected illnesses

# Define dictionaries for scores of selected items (e.g., illness, diet changes, symptoms, and physical)
# Replace these dictionaries with your actual data

# total_diet_change_score = sum(diet_change_scores.get(diet_changes, 0) for diet_changes in selected_diet_changes if selected_diet_changes is not None)
# total_gastr_symptoms_score = sum(gastr_symptoms_scores.get(symptoms, 0) for symptoms in selected_gastr_symptoms if selected_gastr_symptoms is not None)
# total_illness_score = sum(illness_scores.get(illness, 0) for illness in selected_illnesses if selected_illnesses is not None)
# total_physical_score = sum(physical_scores.get(phy_illness, 0) for phy_illness in selected_physical if selected_physical is not None)

if selected_diet_changes is not None:
total_diet_change_score = sum(diet_change_scores.get(diet_changes, 0) for diet_changes in selected_diet_changes)
Expand All @@ -158,25 +132,50 @@ def calculate_total_score(user_age,selected_illnesses, selected_diet_changes, se
else:
total_illness_score=0

# Calculate the final total score
total_score = (
total_illness_score +
total_diet_change_score +
total_gastr_symptoms_score +
total_physical_score
)

# if user_age >= 70:
# total_score += 1
# return total_score
if isinstance(user_age, int):
# user_age is an integer
print("user_age is an integer")
print(f'user_age: {user_age}')
print(f'user_weight: {user_weight}')
print(f'user_height: {user_height}')
print(f'user_lost: {user_lost}')

if user_age >= 70:
print("total score should be increased by 1")
total_score += 1


percentage_lost = (user_lost / user_weight) * 100
if 5 <= percentage_lost <= 10:

total_score += 1
elif percentage_lost > 10:
total_score += 2
print("total score should be increased by 2")


bmi = (user_weight * 10000) / (user_height ** 2)
print(f"BMI: {bmi}") # Add this line for debugging

if 16.5 <= bmi <= 18.5:
total_score += 1
elif bmi < 16.5:
total_score += 2
print(f"Total Score after BMI: {total_score}") # Add this line for debugging

if user_age is not None and isinstance(user_age, int):
if user_age >= 70:
total_score += 1

return total_score




def get_nutritional_message(total_score):
if total_score < 3:
return "Well Nourished: No nutritional intervention required and only balanced intake of food items should be ensured."
Expand All @@ -185,10 +184,15 @@ def get_nutritional_message(total_score):
else:
return "Moderate to Severely Malnourished: Nutritional intervention required and regular monitoring is required."

def illness_form(request):
def illness_form(request, user_age,user_height,user_weight,user_lost):
if isinstance(user_age, int):
# user_age is an integer
print("user_age is an integer")
print(f'user_age: {user_age}')


user_age = None
user_info_form = UserInfoForm() # Define the form here
user_info_form = UserInfoForm()
personal_info_form = PersonalInfoForm() # Define the form here

diet_change_form = DietChangeForm()
illness_form = IllnessForm()
Expand All @@ -202,7 +206,7 @@ def illness_form(request):
if user_info_form.is_valid() and personal_info_form.is_valid():
user_info = user_info_form.save()
personal_info = personal_info_form.save()
user_age = user_info_form.cleaned_data['age']


# You can associate the two models if needed
user_info.personal_info = personal_info
Expand All @@ -226,6 +230,9 @@ def illness_form(request):

total_score = calculate_total_score(
user_age,
user_weight,
user_height,
user_lost,
selected_illnesses,
selected_diet_changes,
selected_gastr_symptoms,
Expand All @@ -246,7 +253,8 @@ def illness_form(request):
'illness_form': illness_form,
'gastr_symptoms_form': gastr_symptoms_form,
'physical_form': physical_form,
'user_info_form': user_info_form, # Pass the form to the template
'user_info_form': user_info_form,
'personal_info_form':personal_info_form, # Pass the form to the template
})


Expand Down
Binary file modified project1/__pycache__/settings.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion project1/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'wellness',
'NAME': 'healthX',
'USER': 'root',
'PASSWORD': 'password',
'HOST':'localhost',
Expand Down

0 comments on commit 51aba43

Please sign in to comment.