Trying to revive Numeri
40
main.py
@ -1,28 +1,36 @@
|
||||
# based on https://gist.github.com/rduplain/1641344
|
||||
|
||||
import random
|
||||
from io import BytesIO
|
||||
import base64
|
||||
import os
|
||||
from flask import Flask, make_response, request, render_template
|
||||
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
||||
from matplotlib.figure import Figure
|
||||
import plots
|
||||
|
||||
config = {
|
||||
"DEBUG": True # run app in debug mode
|
||||
}
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def my_form():
|
||||
return render_template('index.html')
|
||||
def figure():
|
||||
plots.plot()
|
||||
|
||||
@app.route('/', methods=['POST'])
|
||||
def my_form_post():
|
||||
text = request.form['text']
|
||||
processed_text = text.upper()
|
||||
return processed_text
|
||||
@app.route('/', methods=["GET"])
|
||||
def root():
|
||||
title = "Project Numeri"
|
||||
figure()
|
||||
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__':
|
||||
app.run(debug=True, port=5002)
|
17
plots.py
@ -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.figure import Figure
|
||||
import base64
|
||||
import uuid
|
||||
|
||||
# app = Flask(__name__)
|
||||
GRADE_LIST = "Cijfers-HerrewijnenJonathan.csv"
|
||||
print(GRADE_LIST)
|
||||
|
||||
def plot():
|
||||
# Generate the figure **without using pyplot**.
|
||||
fig = Figure()
|
||||
ax = fig.subplots()
|
||||
ax.plot([1, 2])
|
||||
# Save it to a temporary buffer.
|
||||
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}'/>"
|
||||
fig.savefig(f'static/plots/{uuid.uuid4()}.png', format="png")
|
||||
|
||||
|
||||
# import pandas as pd
|
||||
|
BIN
static/plots/1a099ce5-1416-4c48-84b8-33470c4e923d.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/2927a53e-ae1f-41d8-915b-fac557637289.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/2b666d3c-41a9-4254-a0d7-f426b35a7e47.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/5ac5d6a2-1c2b-430e-9e73-393b584150e5.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/68330f3a-18f7-4335-a6a6-55df08910b6c.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/7810ed25-825b-4896-b34d-1c1e08523190.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/78d63720-9b69-45de-9017-fe8102b4170b.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/9cba9fdd-d0ae-4a75-8964-dfbad0d3f8e6.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/a6b7092f-3cd0-4636-b2d5-e60409b89074.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/be3fcb04-c835-48ef-949c-e2187ac21c1d.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/c9b40763-24f5-4839-a912-9c6dd64af257.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/cc5fcf0e-4b83-452f-93b5-c947ff313604.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/eb32f9ba-1974-449a-9cd8-da70e5a5d3c6.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/plots/plot.png
Normal file
After Width: | Height: | Size: 16 KiB |
@ -12,7 +12,13 @@
|
||||
|
||||
<body>
|
||||
<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>
|
||||
|
||||
</html>
|