Browse Source

add web ui

master
kenzie tandun 4 years ago
parent
commit
3e5b395e95
5 changed files with 152 additions and 15 deletions
  1. 13
    15
      health_calc.py
  2. 10
    0
      requirements.txt
  3. 55
    0
      templates/form.html
  4. 38
    0
      templates/submit.html
  5. 36
    0
      web.py

health-calc.py → health_calc.py View File

@@ -33,9 +33,10 @@ def head_age(gender, age):
def is_head_normal(gender, age, head):
h = head_age(gender, age)
if float(head) < h[0] and float(head) > h[1]:
print('Ukuran kepala\t: Normal')
ans = 'Normal'
else:
print('Ukuran kepala\t: Tidak normal')
ans = 'Tidak normal'
return ans

def weight_age(band, gender, age):
if gender == 'boys':
@@ -142,16 +143,17 @@ def weight_age(band, gender, age):
def is_weight_normal(gender, age, weight):
# kelebihan
if weight > weight_age(2, gender, age):
print('BB per U\t: Gizi Berlebih')
ans = 'Gizi Berlebih'
# buruk
elif weight < weight_age(-3, gender, age):
print('BB per U\t: Gizi Buruk')
ans = 'Gizi Buruk'
# kurang
elif weight < weight_age(-2, gender, age):
print('BB per U\t: Gizi Kurang')
ans = 'Gizi Kurang'
# normal
else:
print('BB per U\t: Gizi Normal')
ans = 'Gizi Normal'
return ans

def height_age(band, gender, age):
if gender == 'boys':
@@ -253,13 +255,14 @@ def height_age(band, gender, age):

def is_height_normal(gender, age, height):
if height < height_age(-3, gender, age):
print('TB per U\t: Sangat pendek')
ans = 'Sangat pendek'
elif height < height_age(-2, gender, age):
print('TB per U\t: Pendek')
ans = 'Pendek'
elif height > height_age(2, gender, age):
print('TB per U\t: Tinggi')
ans = 'Tinggi'
else:
print('TB per U\t: Normal')
ans = 'Normal'
return ans

# def is_weight_length_normal(gender, length, height):

@@ -290,10 +293,5 @@ if __name__ == '__main__':
print('head circumference can\'t be less than 0')
weight = int(input("head circumference? (in cm) "))

print()
is_head_normal(gender, age, head_c)
is_weight_normal(gender, age, weight)
is_height_normal(gender, age, height)
print()
print('''Ada bug? Laporkan ke Kenzie!
mailto://nudnateiznek@gmail.com''')

+ 10
- 0
requirements.txt View File

@@ -0,0 +1,10 @@
appdirs==1.4.3
click==6.7
Flask==0.12.1
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
packaging==16.8
pyparsing==2.2.0
six==1.10.0
Werkzeug==0.12.1

+ 55
- 0
templates/form.html View File

@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<title>baby health calc</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1>HCal</h1>
<p>by kenzie tandun</p>
</div>
<div class="container text-center">
<form method="post" action="{{ url_for('submit') }}">
<div class="form-group">
<label for="gender">Gender: </label>
<input type="radio" name="gender" value="male" checked/> Male
<input type="radio" name="gender" value="female"/> Female
</div>

<div class="form-group">
<p><label for="weight">Weight in kg: </label></p>
<input required pattern="[0-9]*" type="number" name="weight" placeholder="e.g. 20"/>
</div>

<div class="form-group">
<p><label for="height">Height in cm: </label></p>
<input required pattern="[0-9]*" type="number" name="height" placeholder="e.g. 100"/>

</div>
<div class="form-group">
<p><label for="hc">Head Circumference in cm: </label></p>
<input required pattern="[0-9]*" type="number" name="hc" placeholder="e.g. 30"/>

</div>
<div class="form-group">
<p><label for="age">Age in months: </label></p>
<input required type="number" name="age" min="0" max="60" step="1"/>
</div>
<button type="submit" class="btn btn-default" formaction="/submit">Submit!</button>
</form>
</div>

<br>
<br>

<div class="text-center">
<p>Ada bug? Laporkan ke nudnateiznek@gmail.com</p>
</div>
</body>
</html>

+ 38
- 0
templates/submit.html View File

@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<title>Submit</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.result {
color: purple;
}
</style>
</head>
<body>
<div class="jumbotron text-center">
<h1>HCal</h1>
<p>by kenzie tandun</p>
</div>
<div class="text-center">
<h4> Berat Badan per Umur </h4>
<div class="result">
<h1><p> {{weight}} </p></h1>
</div>
<br>
<h4> Tinggi Badan per Umur </h4>
<div class="result">
<h1><p> {{height}} </p></h1>
</div>
<br>
<h4> Ukuran Kepala </h4>
<div class="result">
<h1><p> {{hc}} </p></h1>
</div>
</div>
</body>
</html>

+ 36
- 0
web.py View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3

from flask import Flask, render_template, request, url_for
import health_calc as hcal

app = Flask(__name__)

@app.route('/')
def form():
return render_template('form.html')

@app.route('/submit', methods=['POST'])
def submit():
gender = request.form['gender']
if gender == "male":
gender = 'boys'
else:
gender = 'girls'
weight = int(request.form['weight'])
height = int(request.form['height'])
hc = int(request.form['hc'])
age = int(request.form['age'])
w_normal = hcal.is_weight_normal(gender, age, weight)
h_normal = hcal.is_height_normal(gender, age, height)
head_normal = hcal.is_head_normal(gender, age, hc)
return render_template('submit.html',
weight = w_normal,
height = h_normal,
hc = head_normal,
)

if __name__ == "__main__":
app.run(
host='0.0.0.0',
port=8080
)

Loading…
Cancel
Save