-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeedTrig.py
94 lines (79 loc) · 3.13 KB
/
SpeedTrig.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
from flask import Flask, request, render_template, send_file
from io import BytesIO
import TrigGen
from datetime import datetime
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
return render_template('index.html')
@app.route('/generated-quiz', methods=['GET', 'POST'])
def generated():
### Title is a string used to create worksheet title text.
if "title" in request.form:
title = request.form["title"]
else:
title = "Speed Trig Quiz"
print(title)
### norm is a Boolean for whether the Normal Trig Functions option was selected.
# True if selected
# False if not selected
norm = "norm" in request.form
print(norm)
### reci is a Boolean for whether the Reciprocal Trig Functions option was selected.
# True if selected
# False if not selected
reci = "reci" in request.form
print(reci)
### invnorm is a Boolean for whether the Inverse Normal Trig Functions option was selected.
# True if selected
# False if not selected
invnorm = "invnorm" in request.form
print(invnorm)
### invreci is a Boolean for whether the Inverse Reciprocal Trig Functions option was selected.
# True if selected
# False if not selected
invreci = "invreci" in request.form
print(invreci)
### inc is a Boolean for whether the user wants values above 2π or below 0.
# True if selected
# False if not selected
if "inc" in request.form:
inc = True if request.form["inc"] == "yes" else False
else:
inc = False
print(inc)
timesNewRoman = "timesnewroman" in request.form
### override is a Boolean for whether the user wants exact number or percent chance.
# True if % chance
# False if exact number wanted
if "override" in request.form:
override = True if request.form["override"] == "yes" else False
else:
override = False
print(override)
if "num" in request.form and "chance" in request.form:
num = int(request.form["chance"]) if override else int(request.form["num"])
elif "num" in request.form:
num = int(request.form["num"])
override = False
elif "chance" in request.form:
num = int(request.form["chance"])
override = True
else:
num = 0
print(num)
dl = "dl" in request.form
if app.config['TESTING']:
quiz = TrigGen.test_tex([norm, reci, invnorm, invreci], inc, num, timesNewRoman, override)
if quiz == ('', 204):
return ('', 204)
return send_file(BytesIO(quiz), as_attachment=dl, mimetype="text/x-tex",
download_name="Speed Trig Quiz"+datetime.now().strftime(" %Y-%m-%d at %H.%M.%S.pdf"))
quiz = TrigGen.create_tex(title, [norm, reci, invnorm, invreci], inc, num, timesNewRoman, override)
if quiz == ('', 204):
return ('', 204)
return send_file(BytesIO(bytes(quiz)),
mimetype="application/pdf", as_attachment=dl,
download_name="Speed Trig Quiz"+datetime.now().strftime(" %Y-%m-%d at %H.%M.%S.pdf"))
if __name__ == '__main__':
app.run(host='0.0.0.0', threaded=True, debug=True)