-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
121 lines (103 loc) · 3.91 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from flask import Flask, render_template, url_for, request, flash, Session
from datetime import datetime
import pandas as pd
import os
import algorithm as sch
from algorithm import Week, Day
UPLOADS = '/uploads'
ALLOWED_EXTENSIONS = set(['txt', 'csv'])
INCREMENTS = [
'09:00', '09:15', '09:30', '09:45',
'10:00', '10:15', '10:30', '10:45',
'11:00', '11:15', '11:30', '11:45',
'12:00', '12:15', '12:30', '12:45',
'13:00', '13:15', '13:30', '13:45',
'14:00', '14:15', '14:30', '14:45',
'15:00', '15:15', '15:30', '15:45',
'16:00', '16:15', '16:30', '16:45',
'17:00'
]
SCHEDULE = []
# FLASK APP
app = Flask(__name__)
app.config['SESSION_TYPE'] = 'memcached'
app.config['SECRET_KEY'] = 'super secret key'
sess = Session()
# BACKEND DATA
week = sch.Week()
patient_roster = pd.read_csv("data/patient_roster.csv")
patient_data = pd.read_csv("data/patient_data.csv")
# Construct an inflatable table from Week object
dayofweek_translate = {
"Monday":2,
"Tuesday":3,
"Wednesday":4,
"Thursday":5,
"Friday":6
}
def time_translate(military_time):
return int((military_time - 900) / 100)
def build_week(week):
SCHEDULE = []
for dayofweek, day in week.days.items():
for pat_time, pat_id in day.ppl.items():
SCHEDULE.append((pat_id, time_translate(pat_time), dayofweek_translate[dayofweek]))
return SCHEDULE
pat_cnt = 0
@app.route('/incoming', methods=['GET','POST'])
def incoming():
"""Handle scheduling for new user and re-render home page."""
if request.method == 'POST':
print('POST')
print(request.form)
if request.form['day'] == '':
print('empty field')
sch.schedule_appt(week, request.form['day'], pat_cnt, patient_roster)
pat_cnt += 1
return render_template('index.html', increments=INCREMENTS, time=SCHEDULE)
@app.route('/returning', methods=['GET','POST'])
def returning():
"""Handle scheduling for return user and re-render home page."""
if request.method == 'POST':
print('POST')
print(request.form)
if request.form['id'] == '' or request.form['day'] == '':
print('empty field')
return render_template('index.html', increments=INCREMENTS)
SCHEDULE.append((int(request.form['id']), len(SCHEDULE), dayofweek_translate[request.form['day']]))
return render_template('index.html', increments=INCREMENTS, time=SCHEDULE)
@app.route('/checkin', methods=['GET', 'POST'])
def checkin():
"""Handle checkout form submission and re-render home page."""
if request.method == 'POST':
username = request.form['username']
time = request.form['time'] if request.form['time'] != '' else datetime.now().strftime('%H:%M')
print(request.form)
return render_template('index.html', increments=INCREMENTS, time=SCHEDULE)
@app.route('/checkout', methods=['GET', 'POST'])
def checkout():
"""Handle checkout form submission and re-render home page."""
if request.method == 'POST':
username = request.form['username']
time = request.form['time'] if request.form['time'] != '' else datetime.now().strftime('%H:%M')
print(request.form)
return render_template('index.html', increments=INCREMENTS, time=SCHEDULE)
@app.route('/')
def index():
"""Render home page."""
# (day of week, start time, user id, probability))
return render_template('index.html', increments=INCREMENTS, time=SCHEDULE)
@app.context_processor
def override_url_for():
return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path,
endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)
if __name__ == '__main__':
pat_cnt = 0
app.run()