Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics calculation page using flask #11

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Mathematics/Statistikberechnungen/StatisticCalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/python
from flask import Flask, render_template
from flask import request
from flask_table import Table, Col

import ast
import statistics as stats
import numpy as np
from py_markdown_table.markdown_table import markdown_table

# initialization
class QuantileTable(Table):
Name = Col('Name')
Average = Col('Mittelwert')
Minimum = Col('Min')
Quartile1 = Col('Q1')
Median = Col('Median')
Quartile3 = Col('Q3')
Maximum = Col('Max')



# Run app
app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/evalQuart', methods=['GET','POST'])
def evalQuart():
result = ''
if request.method == 'POST':
raw_numbers = request.form['numbers']
numbers = list(ast.literal_eval(raw_numbers.strip("()[]{}")))
name = request.form['name']
result = EvaluateQuantiles(numbers, name)
elif request.method == 'GET':
pass
return render_template('index.html', tableofresults = result)

# Calculus
#example_data = [43.07, 39.23, 44.76, 42.15, 39.98, 40.5, 46.08, 38.62]


def EvaluateQuantiles(data_list, name = ""):
# Sort first
original_data = data_list
data_list.sort()
sorted_data = data_list
print("sorted .... : ", sorted_data)
#
# Calculate quartiles
Q1 = np.percentile(original_data, 25)
Median = np.percentile(original_data, 50)
Q3 = np.percentile(original_data, 75)
Avg = stats.mean(original_data)
#
# Table
results = [
{
"Name": name,
"Average" : Avg,
"Minimum" : sorted_data[0],
"Quartile1" : Q1,
"Median" : Median,
"Quartile3": Q3,
"Maximum" : sorted_data[-1],

}
]

tableofresults = QuantileTable(results)
#tableofresults = markdown_table(results).get_markdown()
return tableofresults

# Example

#EvaluateQuantiles(example_data, "Beispiel")


if __name__ == '__main__':
app.run()
35 changes: 35 additions & 0 deletions Mathematics/Statistikberechnungen/static/styles/mainpage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
body{
font-family:Calibri;
font-size: 22px;
}
form, input, button{
font-size: 22px;
}
h1 { font-size: 52px; color: darkseagreen; }

th,td{
text-align:right;
padding:0.5em;
}

th:nth-child(4),td:nth-child(4){
text-align:left;
padding-right:3em;
}
div{
margin-top:12pt;
}
thead{
background-color: darkseagreen;
}

table, th, td{
border: 1px solid gray;
border-collapse: collapse;
}
tr:nth-child(even){
background-color: lavender;
}
td:hover{
background-color: #e7e7e7;
}
23 changes: 23 additions & 0 deletions Mathematics/Statistikberechnungen/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Statistikberechnungen</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/mainpage.css') }}">
</head>
<body>
<h1>Median und Quartil</h1>
<p>Aufgabe: Wir haben eine Zahlenreihe und sollen davon den Median und das erste und dritte Quartil berechnen.</p>
<form action='evalQuart' method='post'>
<label>Zahlenreihe eingeben (Dezimalpunkt, mit Komma getrennt)</label>
<input type='text' placeholder = 'Bezeichnung'
value='{{request.form.name}}'
name="name">
<input type='text' placeholder = 'Zahlenreihe'
value='{{request.form.numbers}}'
name="numbers">
<button type='submit'>Berechnen</button>

<div class="table">{{tableofresults}}</div>
</form>
</body>
</html>
Loading