Trying to revive Numeri

This commit is contained in:
Jonathan Herrewijnen 2022-10-28 22:16:19 +02:00
parent 21faffb150
commit 440a73f828
20 changed files with 35 additions and 34 deletions

Binary file not shown.

Binary file not shown.

42
main.py
View File

@ -1,28 +1,36 @@
# based on https://gist.github.com/rduplain/1641344 # based on https://gist.github.com/rduplain/1641344
import os
import random
from io import BytesIO
import base64
from flask import Flask, make_response, request, render_template from flask import Flask, make_response, request, render_template
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import plots import plots
config = {
"DEBUG": True # run app in debug mode
}
app = Flask(__name__) app = Flask(__name__)
@app.route('/') def figure():
def my_form(): plots.plot()
return render_template('index.html')
@app.route('/', methods=['POST']) @app.route('/', methods=["GET"])
def my_form_post(): def root():
text = request.form['text'] title = "Project Numeri"
processed_text = text.upper() figure()
return processed_text plots = os.listdir(os.path.join(app.static_folder, "plots"))
return render_template('index.html', title=title, plots=plots)
# @app.route('/', methods=['POST'])
# def my_form_post():
# text = request.form['text']
# processed_text = text.upper()
# return processed_text
# def grades():
# grades_list = pd.read_csv("*.csv")
# print(grades_list)
# @app.route('/')
# def plot_figure():
# return plots.plot()
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, port=5002) app.run(debug=True, port=5002)

BIN
plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,27 +1,14 @@
from io import BytesIO
from flask import Flask, render_template
# app = Flask("Project Numeri")
from flask import Flask, make_response, request
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure from matplotlib.figure import Figure
import base64 import uuid
# app = Flask(__name__)
GRADE_LIST = "Cijfers-HerrewijnenJonathan.csv" GRADE_LIST = "Cijfers-HerrewijnenJonathan.csv"
print(GRADE_LIST)
def plot(): def plot():
# Generate the figure **without using pyplot**.
fig = Figure() fig = Figure()
ax = fig.subplots() ax = fig.subplots()
ax.plot([1, 2]) ax.plot([1, 2])
# Save it to a temporary buffer. fig.savefig(f'static/plots/{uuid.uuid4()}.png', format="png")
buf = BytesIO()
fig.savefig(buf, format="png")
# Embed the result in the html output.
data = base64.b64encode(buf.getbuffer()).decode("ascii")
return f"<img src='data:image/png;base64,{data}'/>"
# import pandas as pd # import pandas as pd

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
static/plots/plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -11,8 +11,14 @@
</form> </form>
<body> <body>
<h1>{{title}}</h1> <h1>{{ title }}</h1>
<img src="/" alt="img_data" id="imgplot" /> <section class="row">
{% for image in plots %}
<section class="col-md-4 col-sm-6" style="background-color: green;">
<a href="{{ url_for('static', filename='plots/' + image) }}">{{ image }}</a>
</section>
{% endfor %}
</section>
</body> </body>
</html> </html>