diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc index 88ded3b..c544e39 100644 Binary files a/__pycache__/main.cpython-39.pyc and b/__pycache__/main.cpython-39.pyc differ diff --git a/__pycache__/plots.cpython-39.pyc b/__pycache__/plots.cpython-39.pyc index 5bc2636..3cec243 100644 Binary files a/__pycache__/plots.cpython-39.pyc and b/__pycache__/plots.cpython-39.pyc differ diff --git a/flaskapp.py b/flaskapp.py index 1f75b6e..89d481b 100644 --- a/flaskapp.py +++ b/flaskapp.py @@ -1,17 +1,16 @@ -import io from flask import Flask, render_template app = Flask("Project Numeri") -from plots import Cijferlijst -import base64 -cf = Cijferlijst() +#from plots import Cijferlijst + +#cf = Cijferlijst() import matplotlib.pyplot as plt from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure +from plots import plot @app.route('/') def index(): return render_template('index.html', title="joe", imgdata=None) - def RunWeb(): app.run(debug=True, port=5002) diff --git a/main.py b/main.py index d302f3f..2d7ae8d 100644 --- a/main.py +++ b/main.py @@ -1,40 +1,19 @@ # based on https://gist.github.com/rduplain/1641344 import random -import io - +from io import BytesIO +import base64 from flask import Flask, make_response, request from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure +import plots app = Flask(__name__) @app.route('/') -def root() : - return "
" +def plot_figure(): + return plots.plot() -@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] - - 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) diff --git a/plots.py b/plots.py index fe5ca09..75ef879 100644 --- a/plots.py +++ b/plots.py @@ -1,32 +1,56 @@ -import pandas as pd -import numpy as np -GRADE_LIST = "Cijfers-HerrewijnenJonathan.csv" +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 -class Cijferlijst: - def __init__(self, grade_list=GRADE_LIST): - self.grade_list = grade_list - self.ps = pd.read_csv(GRADE_LIST, skiprows=2, sep=';') +app = Flask(__name__) - ''' - Get all data from a subject and a (yearly) period: - GetSubjectByYear("godsdienst", "2010/2011") - ''' - def GetSubjectByYear(self, subject, year): - if(type(subject) == str and type(year) == str): - select_year = self.ps[self.ps['Schooljaar(Voortgangsdossier)'] == year] - select_subject = select_year[select_year["Vak(Voortgangsdossier)"] == subject] +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"" - #filter period and rapport - rapports = select_subject[select_subject['Cijfertype(Voortgangsdossier)'] != "Periodegemiddelde"] - return rapports[rapports ['Cijfertype(Voortgangsdossier)'] != "Rapportcijfer"] - else: - return False + +# import pandas as pd +# import numpy as np + +# GRADE_LIST = "Cijfers-HerrewijnenJonathan.csv" + +# class Cijferlijst: +# def __init__(self, grade_list=GRADE_LIST): +# self.grade_list = grade_list +# self.ps = pd.read_csv(GRADE_LIST, skiprows=2, sep=';') + +# ''' +# Get all data from a subject and a (yearly) period: +# GetSubjectByYear("godsdienst", "2010/2011") +# ''' +# def GetSubjectByYear(self, subject, year): +# if(type(subject) == str and type(year) == str): +# select_year = self.ps[self.ps['Schooljaar(Voortgangsdossier)'] == year] +# select_subject = select_year[select_year["Vak(Voortgangsdossier)"] == subject] + +# #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 iets(self): +# print(self.grade_list) - def CalculateMedian(self, subject, year): - # Calculates average for all scores without weight! - Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:] \ No newline at end of file +# def CalculateMedian(self, subject, year): +# # Calculates average for all scores without weight! +# Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:] \ No newline at end of file