Changed the way flask is run

This commit is contained in:
Eljakim Herrewijnen 2022-09-18 15:11:54 +02:00
parent f55f925bdf
commit f8259a6bfd
8 changed files with 60 additions and 41 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,21 +1,17 @@
import io
from flask import Flask, render_template from flask import Flask, render_template
app = Flask("Project Numeri") app = Flask("Project Numeri")
from plots import Cijferlijst from plots import Cijferlijst
import base64 import base64
cf = Cijferlijst() cf = Cijferlijst()
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
@app.route('/') @app.route('/')
def index(): def index():
data = cf.GetSubjectByYear("godsdienst", "2010/2011")
x = data['Datum invoer(Voortgangsdossier)']
y = data['Cijfer(Voortgangsdossier)']
plt.plot(x,y)
return render_template('index.html', title="joe", imgdata=None) return render_template('index.html', title="joe", imgdata=None)
def RunWeb(): def RunWeb():
app.run(debug=True) app.run(debug=True, port=5002)

76
main.py
View File

@ -1,30 +1,58 @@
from flaskapp import * # based on https://gist.github.com/rduplain/1641344
from plots import Cijferlijst
import matplotlib.pyplot as plt import random
from datetime import datetime import io
import matplotlib.dates as mdates
if __name__ == "__main__": from flask import Flask, make_response, request
cf = Cijferlijst() from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
data = cf.GetSubjectByYear("godsdienst", "2010/2011") from matplotlib.figure import Figure
#Get dates and convert them to actual dates app = Flask(__name__)
x = data['Datum invoer(Voortgangsdossier)']
x = [datetime.strptime(date, "%d-%m-%Y") for date in x]
y = data['Cijfer(Voortgangsdossier)'] @app.route('/')
y = [float(line.replace(",", ".")) for line in y] def root() :
return "<form action='/plot.png' method='post'><input type='text' name='data'><input type='submit' value='submit'>"
# p = plt.scatter(x,y) @app.route('/plot.png', methods = ['GET', 'POST'])
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y')) def plot() :
# plt.gca().xaxis.set_major_locator(mdates.DayLocator()) fig = Figure()
plt.scatter(x,y) axis = fig.add_subplot(1, 1, 1)
plt.gcf().autofmt_xdate()
# plt.show()
# plt.plot(range(5))
# plt.xlim(0, 10) if request.method == 'GET' :
# plt.ylim(0, 10) xs = range(100)
# cf.CalculateMedian() ys = [random.randint(1, 50) for x in xs]
RunWeb()
if request.method == 'POST' :
ys = map( float, request.form['data'].strip().split(',') )
xs = range(len(ys))
axis.plot(xs, ys)
canvas = FigureCanvas(fig)
output = io.BytesIO()
canvas.print_png(output)
response = make_response(output.getvalue())
response.mimetype = 'image/png'
return response
if __name__ == '__main__':
app.run(debug=True, port=5002)
# from flaskapp import *
# from plots import Cijferlijst
# import matplotlib.pyplot as plt
# from datetime import datetime
# import matplotlib.dates as mdates
# if __name__ == "__main__":
# cf = Cijferlijst()
# data = cf.GetSubjectByYear("godsdienst", "2010/2011")
# #Get dates and convert them to actual dates
# x = data['Datum invoer(Voortgangsdossier)']
# x = [datetime.strptime(date, "%d-%m-%Y") for date in x]
# y = data['Cijfer(Voortgangsdossier)']
# y = [float(line.replace(",", ".")) for line in y]
# RunWeb()

View File

@ -20,17 +20,13 @@ class Cijferlijst:
#filter period and rapport #filter period and rapport
rapports = select_subject[select_subject['Cijfertype(Voortgangsdossier)'] != "Periodegemiddelde"] rapports = select_subject[select_subject['Cijfertype(Voortgangsdossier)'] != "Periodegemiddelde"]
return rapports[rapports ['Cijfertype(Voortgangsdossier)'] != "Rapportcijfer"] return rapports[rapports ['Cijfertype(Voortgangsdossier)'] != "Rapportcijfer"]
else: else:
return False return False
def iets(self): def iets(self):
print(self.grade_list) print(self.grade_list)
def CalculateMedian(self, subject, year): def CalculateMedian(self, subject, year):
# Calculates average for all scores without weight! # Calculates average for all scores without weight!
Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:] Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:]
print("blub")

View File

@ -7,7 +7,6 @@
</head> </head>
<body> <body>
<h1>{{title}}</h1> <h1>{{title}}</h1>
<img src="/" alt="img_data" id="imgplot"/>
<img src="data:image/png;base64,{house.image}" alt="img_data" id="imgslot"/>
</body> </body>
</html> </html>