-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from DGrothe-PhD/dev
statistics calculation page using flask
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
Mathematics/Statistikberechnungen/static/styles/mainpage.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |