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)

78
main.py
View File

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