Skip to content

Commit

Permalink
Merge pull request #10 from utsavll0/vighnesh_second_branch
Browse files Browse the repository at this point in the history
added static graph and made changes to the UI
  • Loading branch information
ojas1901 authored Oct 13, 2023
2 parents 3bf8f4f + 38ce06c commit a5fdb0e
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 5 deletions.
41 changes: 39 additions & 2 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from flask_mail import Mail
from flask_pymongo import PyMongo
from tabulate import tabulate
from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm
from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm,WorkoutForm

app = Flask(__name__)
app.secret_key = 'secret'
Expand Down Expand Up @@ -155,7 +155,30 @@ def calories():
return redirect(url_for('home'))
return render_template('calories.html', form=form, time=now)

@app.route("/workout", methods=['GET', 'POST'])
def workout():
now = datetime.now()
now = now.strftime('%Y-%m-%d')
get_session = session.get('email')

if get_session is not None:
form = WorkoutForm()
if form.validate_on_submit():
if request.method == 'POST':
email = session.get('email')
burn = request.form.get('burnout')


mongo.db.calories.insert_one({'date': now, 'email': email, 'calories': -int(burn)})

flash(f'Successfully updated the data', 'success')
return redirect(url_for('workout'))
else:
return redirect(url_for('home'))
return render_template('workout.html', form=form, time=now)


# print(intake)
@app.route("/user_profile", methods=['GET', 'POST'])
def user_profile():
"""
Expand Down Expand Up @@ -208,7 +231,21 @@ def history():
email = get_session = session.get('email')
if get_session is not None:
form = HistoryForm()
return render_template('history.html', form=form)

data=[
("01-01-2020",100),
("02-01-2020",101),
("03-01-2020",102)
]

# labels=[row[0] for row in data]
# values=[row[1] for row in data]
labels=[]
values=[]
for row in data:
labels.append(row[0])
values.append(row[1])
return render_template('history.html', form=form,labels=labels,values=values)


@app.route("/ajaxhistory", methods=['POST'])
Expand Down
20 changes: 20 additions & 0 deletions forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ class LoginForm(FlaskForm):
remember = BooleanField('Remember Me')
submit = SubmitField('Login')

class WorkoutForm(FlaskForm):
app = App()
mongo = app.mongo

# cursor = mongo.db.food.find()
# get_docs = []
# for record in cursor:
# get_docs.append(record)

# result = []
# temp = ""
# for i in get_docs:
# temp = i['food'] + ' (' + i['calories'] + ')'
# result.append((temp, temp))

# food = SelectField(
# 'Select Food', choices=result)

burnout = StringField('Burn Out', validators=[DataRequired()])
submit = SubmitField('Save')

class CalorieForm(FlaskForm):
app = App()
Expand Down
3 changes: 2 additions & 1 deletion templates/calories.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block content %}
<div class="content-section">
<form method="POST" onSubmit="storeCalories()" name='calorieform'>
<form method="POST" name='calorieform'>
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Today's Calories</legend>
Expand All @@ -10,6 +10,7 @@
<p class="form-control form-control-lg" name='time'>{{ time }}</p>
</div>
<div class="form-group">

{{ form.food.label(class="form-control-label") }}
{{ form.food(class="form-control form-control-lg") }}
</div>
Expand Down
38 changes: 38 additions & 0 deletions templates/history.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends "layout.html" %}
{% block content %}

<script src="https://cdn.jsdelivr.net/npm/chart.js">

</script>
<div class="content-section">
<form method="POST" onSubmit="event.preventDefault(); return history(event)" name='historyForm'>
{{ form.hidden_tag() }}
Expand All @@ -26,5 +30,39 @@ <h5 class="card-header">History</h5>
<p class="border-bottom mb-4 h6" id="burnout_legend"></p>
<p class="card-text" id="burnout"></p> <br>
</div>


<div>

<canvas id="myChart" width="400" height="400"></canvas>
</div>



<script>
var ctx=document.getElementById('myChart').getContext('2d');
var chart=new Chart(ctx, {
type:"bar",
data:{
labels:{{ labels | safe}},
datasets:[
{
label:"data points",
data:{{values | safe}},
fill:false,
borderColor:"rgb(75,192,192)",
lineTension:0.1
}
]
},
options:{
responsive:false
}
})
</script>

</div>



{% endblock content %}
5 changes: 3 additions & 2 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
{% else %}
<div class="navbar-nav mr-4">
<a class="nav-item nav-link" href="{{ url_for('calories') }}">Enter Calories</a>
<a class="nav-item nav-link" href="{{ url_for('history') }}">History</a>
<a class="nav-item nav-link" href="/history">Your plan</a>
<a class="nav-item nav-link" href="/workout">Burnout</a>
<a class="nav-item nav-link" href="{{url_for('friends')}}">Friends</a>
<a class="nav-item nav-link btn btn-link" href="{{ url_for('user_profile') }}">Profile</button>
</div>
Expand Down Expand Up @@ -90,7 +91,7 @@ <h5 class="text-white mb-3">Quick links</h5>
<div class="col-lg-6 col-md-6">
<ul class="list-unstyled text-muted">
<li><a class="nav-item nav-link" href="{{ url_for('calories') }}">Enter Calories</a></li>
<li><a class="nav-item nav-link" href="{{ url_for('history') }}">History</a></li>
<li><a class="nav-item nav-link" href="/history">Your plan</a></li>
<li><a class="nav-item nav-link" href="{{url_for('friends')}}">Friends</a></li>
<li><a class="nav-item nav-link" href="{{ url_for('user_profile') }}">Profile</a></li>
</ul>
Expand Down
23 changes: 23 additions & 0 deletions templates/workout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "layout.html" %}
{% block content %}
<div class="content-section">
<form method="POST" onSubmit="storeCalories()" name='workoutform'>
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Today's Burnout</legend>
<div class="form-group">
<label class="form-control-label">Date</label>
<p class="form-control form-control-lg" name='time'>{{ time }}</p>
</div>

<div class="form-group">
{{ form.burnout.label(class="form-control-label") }}
{{ form.burnout(class="form-control form-control-lg") }}
</div>
</fieldset>
<div class="form-group">
{{ form.submit(class="btn btn-outline-info") }}
</div>
</form>
</div>
{% endblock content %}

0 comments on commit a5fdb0e

Please sign in to comment.