From 78759faf993c7b56e9377b2e3f95ef9957df8873 Mon Sep 17 00:00:00 2001 From: DGrothe-PhD Date: Wed, 15 May 2024 17:01:21 +0200 Subject: [PATCH 1/2] flask statistic calc (experimental) --- .../Statistikberechnungen/StatisticCalc.py | 71 +++++++++++++++++++ Mathematics/Statistikberechnungen/index.html | 33 +++++++++ 2 files changed, 104 insertions(+) create mode 100644 Mathematics/Statistikberechnungen/StatisticCalc.py create mode 100644 Mathematics/Statistikberechnungen/index.html diff --git a/Mathematics/Statistikberechnungen/StatisticCalc.py b/Mathematics/Statistikberechnungen/StatisticCalc.py new file mode 100644 index 0000000..6416524 --- /dev/null +++ b/Mathematics/Statistikberechnungen/StatisticCalc.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +from flask import Flask, render_template +from flask import request + +import ast +import statistics as stats +import numpy as np +from py_markdown_table.markdown_table import markdown_table + +# initialization + + +# 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) + + +if __name__ == '__main__': + app.run() + +# 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, + "Minimum" : sorted_data[0], + "Q1" : Q1, + "Median" : Median, + "Q3": Q3, + "Maximum" : sorted_data[-1], + "Average" : Avg + } + ] + + tableofresults = markdown_table(results).get_markdown() + return tableofresults + +# Example + +#EvaluateQuantiles(example_data, "Beispiel") \ No newline at end of file diff --git a/Mathematics/Statistikberechnungen/index.html b/Mathematics/Statistikberechnungen/index.html new file mode 100644 index 0000000..ee10a15 --- /dev/null +++ b/Mathematics/Statistikberechnungen/index.html @@ -0,0 +1,33 @@ + + + + Statistikberechnungen + + +

Median und Quartil

+

Aufgabe: Wir haben eine Zahlenreihe und sollen davon den Median und das erste und dritte Quartil berechnen.

+
+ + + + + + + +
{{tableofresults}}
+ +
+ + From a839fab289bfdc7600059122334a34cfbabcdaae Mon Sep 17 00:00:00 2001 From: DGrothe-PhD Date: Wed, 15 May 2024 19:33:18 +0200 Subject: [PATCH 2/2] finished layout --- .../Statistikberechnungen/StatisticCalc.py | 34 ++++++++++++------ .../static/styles/mainpage.css | 35 +++++++++++++++++++ .../{ => templates}/index.html | 14 ++------ 3 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 Mathematics/Statistikberechnungen/static/styles/mainpage.css rename Mathematics/Statistikberechnungen/{ => templates}/index.html (62%) diff --git a/Mathematics/Statistikberechnungen/StatisticCalc.py b/Mathematics/Statistikberechnungen/StatisticCalc.py index 6416524..db452ba 100644 --- a/Mathematics/Statistikberechnungen/StatisticCalc.py +++ b/Mathematics/Statistikberechnungen/StatisticCalc.py @@ -1,6 +1,7 @@ #!/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 @@ -8,7 +9,16 @@ 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__) @@ -22,17 +32,13 @@ def evalQuart(): result = '' if request.method == 'POST': raw_numbers = request.form['numbers'] - numbers = = list(ast.literal_eval(raw_numbers.strip("()[]{}"))) + numbers = list(ast.literal_eval(raw_numbers.strip("()[]{}"))) name = request.form['name'] result = EvaluateQuantiles(numbers, name) - elif request.method = 'GET': + elif request.method == 'GET': pass return render_template('index.html', tableofresults = result) - -if __name__ == '__main__': - app.run() - # Calculus #example_data = [43.07, 39.23, 44.76, 42.15, 39.98, 40.5, 46.08, 38.62] @@ -54,18 +60,24 @@ def EvaluateQuantiles(data_list, name = ""): results = [ { "Name": name, + "Average" : Avg, "Minimum" : sorted_data[0], - "Q1" : Q1, + "Quartile1" : Q1, "Median" : Median, - "Q3": Q3, + "Quartile3": Q3, "Maximum" : sorted_data[-1], - "Average" : Avg + } ] - tableofresults = markdown_table(results).get_markdown() + tableofresults = QuantileTable(results) + #tableofresults = markdown_table(results).get_markdown() return tableofresults # Example -#EvaluateQuantiles(example_data, "Beispiel") \ No newline at end of file +#EvaluateQuantiles(example_data, "Beispiel") + + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/Mathematics/Statistikberechnungen/static/styles/mainpage.css b/Mathematics/Statistikberechnungen/static/styles/mainpage.css new file mode 100644 index 0000000..4f97953 --- /dev/null +++ b/Mathematics/Statistikberechnungen/static/styles/mainpage.css @@ -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; +} \ No newline at end of file diff --git a/Mathematics/Statistikberechnungen/index.html b/Mathematics/Statistikberechnungen/templates/index.html similarity index 62% rename from Mathematics/Statistikberechnungen/index.html rename to Mathematics/Statistikberechnungen/templates/index.html index ee10a15..c1f129e 100644 --- a/Mathematics/Statistikberechnungen/index.html +++ b/Mathematics/Statistikberechnungen/templates/index.html @@ -2,6 +2,7 @@ Statistikberechnungen +

Median und Quartil

@@ -11,23 +12,12 @@

Median und Quartil

- - -
{{tableofresults}}
- +
{{tableofresults}}