-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
304 lines (266 loc) · 9.79 KB
/
main.py
File metadata and controls
304 lines (266 loc) · 9.79 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
from flask import Flask, render_template_string, redirect, url_for, flash, request
from flask_wtf import FlaskForm
from wtforms import StringField, FloatField, SubmitField
from wtforms.validators import DataRequired, NumberRange
import os
from babel.numbers import format_currency
app = Flask(__name__)
# Use environment variable for secret key
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'boobookitty')
class ComputeForm(FlaskForm):
customer_name = StringField('Customer Name', validators=[
DataRequired(message='Please enter a customer name')])
hourly_spend = FloatField(
'Hourly Spend on Eligible Compute (in $)',
validators=[NumberRange(
0, 10000, message='Please enter a number between 0 and 10000')]
)
three_year_flex = FloatField('3 Year FlexCUD Commitment ($/hr)',
validators=[
NumberRange(0, 10000,
message='Please enter a number between 0 and 10000')
])
one_year_flex = FloatField('1 Year FlexCUD Commitment ($/hr)', validators=[
NumberRange(0, 10000, message='Please enter a number between 0 and 10000')])
sud_percentage = FloatField(
'Percent of SUD (or ODVM) discount on OD Spend', validators=[NumberRange(0, 100, message='Please enter a number between 0 and 50')])
submit = SubmitField('Push it. Push it real good.')
@app.route('/', methods=['GET', 'POST'])
def index():
form = ComputeForm()
cost_3_year_flex = None
cost_1_year_flex = None
cost_on_demand = None
if form.validate_on_submit():
# Perform calculations based on form input
suds = form.sud_percentage.data/100
commitment_1_year_flex = form.one_year_flex.data
commitment_3_year_flex = form.three_year_flex.data
cost_1_year_flex = (commitment_1_year_flex * (1-.28))
cost_3_year_flex = (
(commitment_3_year_flex) * (1-.46)
)
cost_on_demand = (
(form.hourly_spend.data - form.three_year_flex.data -
form.one_year_flex.data) * (1-suds)
)
total_cost = cost_1_year_flex + cost_3_year_flex + cost_on_demand
overall_discount = (
(form.hourly_spend.data - total_cost)/form.hourly_spend.data)
discount = (form.hourly_spend.data - total_cost)/form.hourly_spend.data
avail_hourly_od = (form.hourly_spend.data -
form.three_year_flex.data - form.one_year_flex.data)
monthly_on_demand_cost = form.hourly_spend.data * 730
monthly_discount_cost = total_cost * 730
hourly_cost = form.hourly_spend.data
suds_discount = (avail_hourly_od * suds * -1)
final_hourly_od = avail_hourly_od + suds_discount
# Provide feedback to the user
flash(f"""
<div>
<table>
<thead>
<tr>
<th class="name" colspan="2" style="font-size: 2em; text-align: center">{form.customer_name.data}</th>
</tr>
</thead>
</div>
<tr>
<td class="label">Monthly On-Demand<br>Discount-Eligible Spend ($/mo)</td>
<td class="data">{format_currency(monthly_on_demand_cost,currency='USD')}
</td></tr>
<tr>
<td class="label">Hourly Spend ($/hr)</td>
<td class="data">{format_currency(hourly_cost,currency='USD')}</td>
</tr>
<tr>
<td class="header" colspan="2">Commitments</td>
</tr>
<tr>
<td class="label">3 Year FlexCUD Commitment ($/hr)</td>
<td class="data">{format_currency(commitment_3_year_flex, currency='USD')}</td>
</tr>
<tr>
<td class="label">1 Year FlexCUD Commitment ($/hr)</td>
<td class="data">{format_currency(commitment_1_year_flex,currency='USD')}
</td></tr>
<tr>
<td class="header" colspan="2">Discounted Costs</td>
</tr>
<tr>
<td class="label">1 Year FlexCUD Cost ($/hr)</td>
<td class="data">{format_currency(cost_1_year_flex,currency='USD')}</td>
</tr>
<tr>
<td class="label">3 Year FlexCUD Cost ($/hr)</td>
<td class="data">{format_currency(cost_3_year_flex,currency='USD')}</td>
</tr>
<tr>
<td class="header" colspan="2">On-Demand Discounting (SUDS, etc)</td>
</tr>
<tr>
<td class="label">Remaining ODVM Costs ($/hr)</td>
<td class="data">{format_currency(avail_hourly_od,currency='USD')}</td>
</tr>
<tr>
<td class="label">SUDs (or ODVM) Discount</td>
<td class="data">{format_currency(suds_discount,currency='USD')}</td>
</tr>
<tr>
<td class="label">Final On-Demand Hourly Cost ($/hr)</td>
<td class="data">{format_currency(final_hourly_od,currency='USD')}</td>
</tr>
<tr>
<td class="header" colspan="2">Math</td>
</tr>
<tr>
<td class="label">On-Demand Hourly Cost ($/hr)</td>
<td class="data">{format_currency(final_hourly_od,currency='USD')}</td>
</tr>
<tr>
<td class="label">+ 1 Yr FlexCUD Hourly Cost ($/hr)</td>
<td class="data">{format_currency(cost_1_year_flex,currency='USD')}</td>
</tr>
<tr>
<td class="label">+ 3 Yr FlexCUD Hourly Cost ($/hr)</td>
<td class="data">{format_currency(cost_3_year_flex,currency='USD')}</td>
</tr>
<tr>
<td class="label">= Total Hourly Cost ($/hr)</td>
<td class="data">{format_currency(total_cost,currency='USD')}</td>
<tr>
<td class="label">Total Monthly Cost ($/mo)</td>
<td class="data">{format_currency(total_cost*730,currency='USD')}</td></tr>
</tr></td>
<tr>
<td class="label">Discount (%)</td>
<td class="data" >{discount*100:.2f}%</td></tr>
</table>
""", "success")
return redirect(url_for('index'))
# Return the rendered form
return render_template_string(TEMPLATE_STRING, form=form, title="FlexCUD Calculator Extravaganza")
TEMPLATE_STRING = '''
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{title}}</title>
<style>
td {
padding: 10px;
font-size: 1.2em;
margin: 10px;
font-family: Arial, sans-serif;
}
td.label {
text-align: left;
}
td.data {
text-align: right;
}
td.header {
font-size: 1.5em;
font-weight: bold;
text-align: center;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 10;
padding: 10;
}
table {
width: 90%;
border-collapse: collapse;
}
table, th, td {
border: 3px solid black;
}
td.label {
padding: 8px;
text-align: center;
}
h1 {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}
form {
background-color: #fff;
font-size: 1.4em;
max-width: 500px;
margin: 40px auto;
padding: 15px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
p {
margin-bottom: 10px;
}
label {
display: ;
margin-bottom: 1px;
}
input[type="text"], input[type="number"] {
width: 90%;
padding: 15px;
border: 3px solid #119AFF;
border-radius: 25px;
;
}
input[type="submit"] {
background-color: #007BFF;
color: #fff;;
border: 5px solid #7BFF;
border-radius: 15px;
font-size: 1.3em;
width: 100%;
}
input[type="submit"]:hover {
background-color: #ADA;
-webkit-transition: background-color 0.4s ease-in-out;
}
ul {
max-width: 700px;
margin: 20px auto;
}
li {
background-color: #FA1; /* for the success category, adjust if needed */
margin-bottom: 10px;
padding: 10px;
border-radius: 4px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.error {
background-color: #FDD;
}
}
</style>
</head>
<body>
<h1>{{title}}</h1>
<form method="post">
{{ form.hidden_tag() }}
<p>{{ form.customer_name.label }}<br>{{ form.customer_name }}</p>
<p>{{ form.hourly_spend.label }}<br>{{ form.hourly_spend }}</p>
<p>{{ form.three_year_flex.label }}<br>{{ form.three_year_flex }}</p>
<p>{{ form.one_year_flex.label }}<br>{{ form.one_year_flex }}</p>
<p>{{ form.sud_percentage.label }}<br>{{ form.sud_percentage }}</p>
<p>{{ form.submit() }}</p>
</form>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul>
{% for category, message in messages %}
<li{% if category %} class="{{ category }}"{% endif %}>{{ message|safe }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</body>
</html>
'''
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))