-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
111 lines (95 loc) · 4.22 KB
/
app.py
File metadata and controls
111 lines (95 loc) · 4.22 KB
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
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
values = {
"stitch_gauge": "",
"row_gauge": "",
"neck_circumference": "",
"yoke_depth": "",
"arm_circumference": "",
"chest_circumference": "",
"desired_ease": "",
"desired_body_length": "",
"wrist_circumference": "",
"desired_arm_length": "",
"schematic_d": "",
}
errors = []
results = None
if request.method == "POST":
stage = request.form.get("stage", "initial")
values = {
key: request.form.get(key, "").strip()
for key in values
}
try:
stitch_gauge = float(values["stitch_gauge"])
row_gauge = float(values["row_gauge"])
neck_circumference = float(values["neck_circumference"])
yoke_depth = float(values["yoke_depth"])
arm_circumference = float(values["arm_circumference"])
chest_circumference = float(values["chest_circumference"])
desired_ease = float(values["desired_ease"])
wrist_circumference = float(values["wrist_circumference"])
numeric_inputs = {
"Stitch gauge": stitch_gauge,
"Row gauge": row_gauge,
"Neck circumference": neck_circumference,
"Yoke depth": yoke_depth,
"Arm circumference": arm_circumference,
"Chest circumference": chest_circumference,
"Desired ease": desired_ease,
"Final sleeve circumference at wrist": wrist_circumference,
}
desired_arm_length = None
desired_body_length = None
schematic_d = None
if stage == "schematic":
desired_arm_length = float(values["desired_arm_length"])
desired_body_length = float(values["desired_body_length"])
schematic_d = float(values["schematic_d"])
numeric_inputs["B: Desired arm length"] = desired_arm_length
numeric_inputs["C: Desired body length"] = desired_body_length
numeric_inputs["D: Arm circumference plus ease"] = schematic_d
for label, value in numeric_inputs.items():
if value <= 0:
errors.append(f"{label} must be greater than 0.")
if not errors:
stitches_per_inch = stitch_gauge / 4
rows_per_inch = row_gauge / 4
chest_with_ease = chest_circumference + desired_ease
arm_with_ease = arm_circumference + desired_ease
chest_total_stitches = chest_with_ease * stitches_per_inch
armhole_stitches = arm_with_ease * stitches_per_inch
neck_circumference = neck_circumference * stitches_per_inch
yoke_depth = yoke_depth * rows_per_inch
increases = (chest_total_stitches - neck_circumference) / 4
every = yoke_depth / increases if increases != 0 else 0
results = {
"stitches_per_inch": stitches_per_inch,
"rows_per_inch": rows_per_inch,
"chest_total_stitches": chest_total_stitches,
"armhole_stitches": armhole_stitches,
"neck_circumference": neck_circumference,
"yoke_depth": yoke_depth,
"label_a": chest_with_ease,
"label_c": desired_body_length,
"label_e": float(values["yoke_depth"]),
"wrist_circumference": wrist_circumference,
"show_schematic_prompt": stage == "initial",
"label_b": desired_arm_length,
"label_d": schematic_d if schematic_d is not None else arm_with_ease,
"increases": increases,
"every": every,
}
except ValueError:
errors.append("Please enter valid numeric values for all fields.")
return render_template(
"index.html",
values=values,
errors=errors,
results=results,
)
if __name__ == "__main__":
app.run(debug=True)