diff --git a/__pycache__/flaskapp.cpython-38.pyc b/__pycache__/flaskapp.cpython-38.pyc new file mode 100644 index 0000000..af8f8e4 Binary files /dev/null and b/__pycache__/flaskapp.cpython-38.pyc differ diff --git a/__pycache__/flaskapp.cpython-39.pyc b/__pycache__/flaskapp.cpython-39.pyc new file mode 100644 index 0000000..af9ad2a Binary files /dev/null and b/__pycache__/flaskapp.cpython-39.pyc differ diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000..88ded3b Binary files /dev/null and b/__pycache__/main.cpython-39.pyc differ diff --git a/__pycache__/plots.cpython-39.pyc b/__pycache__/plots.cpython-39.pyc new file mode 100644 index 0000000..5bc2636 Binary files /dev/null and b/__pycache__/plots.cpython-39.pyc differ diff --git a/flaskapp.py b/flaskapp.py index 3116568..1f75b6e 100644 --- a/flaskapp.py +++ b/flaskapp.py @@ -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) diff --git a/main.py b/main.py index 4c94fb3..d302f3f 100644 --- a/main.py +++ b/main.py @@ -1,30 +1,58 @@ -from flaskapp import * -from plots import Cijferlijst +# based on https://gist.github.com/rduplain/1641344 + +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 -from datetime import datetime -import matplotlib.dates as mdates +@app.route('/') +def root() : + return "
" -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] +@app.route('/plot.png', methods = ['GET', 'POST']) +def plot() : + fig = Figure() + axis = fig.add_subplot(1, 1, 1) + + if request.method == 'GET' : + xs = range(100) + ys = [random.randint(1, 50) for x in xs] - y = data['Cijfer(Voortgangsdossier)'] - y = [float(line.replace(",", ".")) for line in y] + if request.method == 'POST' : + ys = map( float, request.form['data'].strip().split(',') ) + xs = range(len(ys)) - # 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)) + 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 - # plt.xlim(0, 10) - # plt.ylim(0, 10) - # cf.CalculateMedian() - RunWeb() \ No newline at end of file + +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() \ No newline at end of file diff --git a/plots.py b/plots.py index 0264c7e..fe5ca09 100644 --- a/plots.py +++ b/plots.py @@ -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") - + Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:] \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index cadb24c..989b5f4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,7 +7,6 @@

{{title}}

- - img_data + img_data \ No newline at end of file