Skip to content

Commit

Permalink
Unit Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GoingOffRoading committed Jul 24, 2024
1 parent f598fed commit e25f2ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
26 changes: 24 additions & 2 deletions Flask.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# app.py

from flask import Flask, render_template, request
import mysql.connector, subprocess, os
import mysql.connector, subprocess, os, math

app = Flask(__name__)

Expand Down Expand Up @@ -51,6 +51,10 @@ def get_data_from_db():

return result_1, result_2, result_3, result_4, table_data_1, table_data_2





# Route for the home page
@app.route('/', methods=['GET', 'POST'])
def index():
Expand All @@ -64,11 +68,29 @@ def index():
# Get data from the database
result_1, result_2, result_3, result_4, table_data_1, table_data_2 = get_data_from_db()

print('diagnostic1')
result_1 = round_size(result_1)
result_4 = round_size(result_4)

# Render the template with the retrieved data
return render_template(template_path, result_1=result_1, result_2=result_2, result_3=result_3, result_4=result_4,
table_data_1=table_data_1, table_data_2=table_data_2)



def round_size(kilobytes):
kilobytes = float(kilobytes)
if kilobytes < 1024:
return f"{kilobytes:.1f} KB"
elif kilobytes < 1024**2:
megabytes = kilobytes / 1024
return f"{math.ceil(megabytes * 10) / 10:.1f} MB"
elif kilobytes < 1024**3:
gigabytes = kilobytes / 1024**2
return f"{math.ceil(gigabytes * 10) / 10:.1f} GB"
else:
terabytes = kilobytes / 1024**3
return f"{math.ceil(terabytes * 10) / 10:.1f} TB"


if __name__ == '__main__':
app.run(debug=True)
3 changes: 1 addition & 2 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ FROM python:3.9-alpine
RUN apk update && \
apk add --no-cache \
build-base \
linux-headers \
supervisor && \
linux-headers && \
pip install --no-cache-dir celery flower requests Flask mysql-connector-python && \
apk upgrade

Expand Down
4 changes: 2 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ <h1>Boilest Stats</h1>
</form>

<div class="tile-container">
<div class="tile">{{ result_1 }} MB Saved</div>
<div class="tile">{{ result_1 }} Saved</div>
<div class="tile">{{ result_2 }} Files Processed</div>
<div class="tile">{{ result_3 }} Days Run</div>
<div class="tile">{{ result_4 }} MB saved per file</div>
<div class="tile">{{ result_4 }} saved per file</div>
</div>

<h2>Recent Performance</h2>
Expand Down

0 comments on commit e25f2ac

Please sign in to comment.