Skip to content

Commit

Permalink
[Update]symptom checker functions
Browse files Browse the repository at this point in the history
Former-commit-id: df97bf08982f4f0bf26c78dea9b5f55932ccad9a
  • Loading branch information
krc authored and krc committed Nov 29, 2021
1 parent 30e2c4c commit 9b20344
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 55 deletions.
26 changes: 16 additions & 10 deletions app/ml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from catboost import CatBoostClassifier


def seed_everything(SEED=9):
random.seed(SEED)
os.environ['PYTHONHASHSEED'] = str(SEED)
Expand All @@ -14,23 +15,28 @@ def seed_everything(SEED=9):
seed_everything(SEED)

Age_dict = {
"Age_0-9":0,
"Age_10-19":1,
"Age_20-24":2,
"Age_25-59":3,
"Age_60+":4
# "Age_0-9":0,
# "Age_10-19":1,
# "Age_20-24":2,
# "Age_25-59":3,
# "Age_60+":4
"Age_60-":0,
"Age_60+":1
}

Gender_dict = {
"Gender_Female":0,
"Gender_Male":1,
"Gender_Transgender":2
# "Gender_Transgender":2
}

Contact_dict = {
"Contact_Dont-Know":0,
"Contact_No":1,
"Contact_Yes":2
# "Contact_Dont-Know":0,
# "Contact_No":1,
# "Contact_Yes":2
"Other":0,
"Abroad":1,
"Contact_with_confirmed":2
}

model_params = {
Expand All @@ -47,5 +53,5 @@ def seed_everything(SEED=9):
}

model = CatBoostClassifier(**model_params)
model_path = os.path.join(".", "app", "ml", "symptom_checker.cbm")
model_path = os.path.join(".", "app", "ml", "fold0.cbm")
model.load_model(model_path, format='cbm')
Binary file added app/ml/fold0.cbm
Binary file not shown.
48 changes: 27 additions & 21 deletions app/templates/checker.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ <h1>Inside Your Body 👀</h1>
<form method="post">
<div class="kit_personal_board">
<div class='symptom_1'>
<input type="checkbox" name="Fever" id="Fever" class="input_checker">
<label for="Fever" class="label_checker">고열</label>
<input type="checkbox" name="Tiredness" id="Tiredness" class="input_checker">
<label for="Tiredness" class="label_checker">피곤함</label>
<input type="checkbox" name="Dry_Cough" id="Dry_Cough" class="input_checker">
<label for="Dry_Cough" class="label_checker">마른 기침</label>
<input type="checkbox" name="fever" id="fever" class="input_checker">
<label for="fever" class="label_checker">고열</label>
<input type="checkbox" name="head_ache" id="head_ache" class="input_checker">
<label for="head_ache" class="label_checker">두통</label>
<input type="checkbox" name="cough" id="cough" class="input_checker">
<label for="cough" class="label_checker">마른 기침</label>
</div>
<div class='symptom_1'>
<input type="checkbox" name="Difficulty_in_Breathing" id="Difficulty_in_Breathing" class="input_checker">
<label for="Difficulty_in_Breathing" class="label_checker">호흡 곤란</label>
<input type="checkbox" name="Sore_Throat" id="Sore_Throat" class="input_checker">
<label for="Sore_Throat" class="label_checker">인후염</label>
<input type="checkbox" name="shortness_of_breath" id="shortness_of_breath" class="input_checker">
<label for="shortness_of_breath" class="label_checker">호흡 곤란</label>
<input type="checkbox" name="sore_throat" id="sore_throat" class="input_checker">
<label for="sore_throat" class="label_checker">인후염</label>
<input type="checkbox" name="None_Sympton" id="None_Sympton" class="input_checker">
<label for="None_Sympton" class="label_checker none_experience">증상 없음</label>
</div>
<div class='symptom_1'>
<!-- <div class='symptom_1'>
<input type="checkbox" name="Pains" id="Pains" class="input_checker">
<label for="Pains" class="label_checker">근육통</label>
<input type="checkbox" name="Nasal_Congestion" id="Nasal_Congestion" class="input_checker">
Expand All @@ -168,10 +168,10 @@ <h1>Inside Your Body 👀</h1>
<label for="Diarrhea" class="label_checker">설사</label>
<input type="checkbox" name="None_Experiencing" id="None_Experiencing" class="input_checker">
<label for="None_Experiencing" class="label_checker none_experience">경험 없음</label>
</div>
</div> -->
<div class='section'>

<table style='display:inline;'>국적
<!-- <table style='display:inline;'>국적
<tr>
<td>
<select name="Country">
Expand All @@ -188,16 +188,18 @@ <h1>Inside Your Body 👀</h1>
</select>
</td>
</tr>
</table>
</table> -->

<table style='display:inline;'>나이
<tr>
<td>
<select name="Age">
<option value="Age_0-9">9세 이하</option>
<select name="age_60_and_above">
<!-- <option value="Age_0-9">9세 이하</option>
<option value="Age_10-19">10-19세</option>
<option value="Age_20-24">20-24세</option>
<option value="Age_25-59">25-59세</option>
<option value="Age_60+">60세 이상</option> -->
<option value="Age_60-">60세 이하</option>
<option value="Age_60+">60세 이상</option>

</select>
Expand All @@ -208,10 +210,10 @@ <h1>Inside Your Body 👀</h1>
<table style='display:inline;'>성별
<tr>
<td>
<select name="Gender">
<select name="gender">
<option value="Gender_Female">Female</option>
<option value="Gender_Male">Male</option>
<option value="Gender_Transgender">Transgender</option>
<!-- <option value="Gender_Transgender">Transgender</option> -->
</select>
</td>
</tr>
Expand All @@ -220,14 +222,18 @@ <h1>Inside Your Body 👀</h1>
<table style='display:inline;'>확진자 접촉 여부
<tr>
<td>
<select name="Contact">
<option value="Contact_Dont-Know">알 수 없음</option>
<select name="test_indication">
<!-- <option value="Contact_Dont-Know">알 수 없음</option>
<option value="Contact_No">접촉 X</option>
<option value="Contact_Yes">접촉 O</option>
<option value="Contact_Yes">접촉 O</option> -->
<option value="Contact_with_confirmed">확진자 접촉</option>
<option value="Abroad">해외</option>
<option value="Other">기타</option>
</select>
</td>
</tr>
</table>

</div>
</div>
<div class="kit_two_button">
Expand Down
50 changes: 27 additions & 23 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import app, db
from .models import Food, User
import bcrypt
from datetime import datetime

global nutrients, result, food_lst, foods_nutrients
food_lst = None
Expand Down Expand Up @@ -125,43 +126,46 @@ def checker():
global nutrients, result, food_lst, foods_nutrients
if request.method == 'POST' and request.form.get('btn') == "diet_result" :
input_data = {
'Fever':0,
'Tiredness':0,
'Dry-Cough':0,
'Difficulty-in-Breathing':0,
'Sore-Throat':0,
'None_Sympton':0,
'Pains':0,
'Nasal-Congestion':0,
'Runny-Nose':0,
'Diarrhea':0,
'None_Experiencing':0,
'Country':0,
'Age':0,
'Gender':0,
'Contact':0
'test_date':int(datetime.today().month),
'cough':0,
'fever':0,
'sore_throat':0,
'shortness_of_breath':0,
'head_ache':0,
# 'Pains':0,
# 'Nasal-Congestion':0,
# 'Runny-Nose':0,
# 'Diarrhea':0,
# 'None_Experiencing':0,
# 'Country':0,
'age_60_and_above':0,
'gender':0,
'test_indication':0,
'sum_symptom':0
}

for i in request.form: # Fever
value = request.form.get(i)

if i not in ['Country', 'Age', 'Gender', 'Contact','button']:
if i not in ['test_indication','age_60_and_above', 'gender', 'button']:
input_data[i] = 1
input_data['sum_symptom'] += 1
elif i == 'None_Sympton':
for j in ['cough','fever','shortness_of_breath','head_ache']:
input_data[j] = 0
else:
if i == 'Country':
input_data[i] = value
elif i == 'Age':
if i == 'test_indication':
input_data[i] = Contact_dict[value]
elif i == 'age_60_and_above':
input_data[i] = Age_dict[value]
elif i == 'Gender':
elif i == 'gender':
input_data[i] = Gender_dict[value]
elif i == 'Contact':
input_data[i] = Contact_dict[value]
else:
continue

x = pd.DataFrame(input_data, index=[0])
pred = model.predict_proba(x)[:,1][0]
result = pred*0.3 + (1-pred)*0.7
result = pred*0.85 + (1-pred)*0.15

return redirect(url_for("loading"))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protobuf==3.19.1
pycparser==2.21
pylint==2.6.0
PyMySQL==1.0.2
pyparsing==3.0.5
pyparsing==2.2.1
python-dateutil==2.8.2
pytz==2021.3
pyzmq==19.0.2
Expand Down

0 comments on commit 9b20344

Please sign in to comment.