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
app = Flask("Project Numeri")
from plots import Cijferlijst
import base64
cf = Cijferlijst()
import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
@app.route('/')
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)
def RunWeb():
app.run(debug=True)
app.run(debug=True, port=5002)

76
main.py
View File

@ -1,30 +1,58 @@
from flaskapp import *
from plots import Cijferlijst
# based on https://gist.github.com/rduplain/1641344
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.dates as mdates
import random
import io
if __name__ == "__main__":
cf = Cijferlijst()
data = cf.GetSubjectByYear("godsdienst", "2010/2011")
from flask import Flask, make_response, request
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
#Get dates and convert them to actual dates
x = data['Datum invoer(Voortgangsdossier)']
x = [datetime.strptime(date, "%d-%m-%Y") for date in x]
app = Flask(__name__)
y = data['Cijfer(Voortgangsdossier)']
y = [float(line.replace(",", ".")) for line in y]
@app.route('/')
def root() :
return "<form action='/plot.png' method='post'><input type='text' name='data'><input type='submit' value='submit'>"
# p = plt.scatter(x,y)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))
# plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.scatter(x,y)
plt.gcf().autofmt_xdate()
# plt.show()
# plt.plot(range(5))
@app.route('/plot.png', methods = ['GET', 'POST'])
def plot() :
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
# plt.xlim(0, 10)
# plt.ylim(0, 10)
# cf.CalculateMedian()
RunWeb()
if request.method == 'GET' :
xs = range(100)
ys = [random.randint(1, 50) for x in xs]
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
rapports = select_subject[select_subject['Cijfertype(Voortgangsdossier)'] != "Periodegemiddelde"]
return rapports[rapports ['Cijfertype(Voortgangsdossier)'] != "Rapportcijfer"]
else:
return False
def iets(self):
print(self.grade_list)
def CalculateMedian(self, subject, year):
# Calculates average for all scores without weight!
Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:]
print("blub")

View File

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