Cleaning up code
This commit is contained in:
parent
f8259a6bfd
commit
3f0c355578
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
31
main.py
31
main.py
@ -1,39 +1,18 @@
|
||||
# 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 "<form action='/plot.png' method='post'><input type='text' name='data'><input type='submit' value='submit'>"
|
||||
|
||||
@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
|
||||
|
||||
def plot_figure():
|
||||
return plots.plot()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5002)
|
||||
|
76
plots.py
76
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]
|
||||
|
||||
#filter period and rapport
|
||||
rapports = select_subject[select_subject['Cijfertype(Voortgangsdossier)'] != "Periodegemiddelde"]
|
||||
return rapports[rapports ['Cijfertype(Voortgangsdossier)'] != "Rapportcijfer"]
|
||||
else:
|
||||
return False
|
||||
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"<img src='data:image/png;base64,{data}'/>"
|
||||
|
||||
|
||||
def iets(self):
|
||||
print(self.grade_list)
|
||||
# import pandas as pd
|
||||
# import numpy as np
|
||||
|
||||
def CalculateMedian(self, subject, year):
|
||||
# Calculates average for all scores without weight!
|
||||
Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:]
|
||||
# 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 CalculateMedian(self, subject, year):
|
||||
# # Calculates average for all scores without weight!
|
||||
# Grades = self.ps['Cijfer(Voortgangsdossier)'].loc[:]
|
Loading…
Reference in New Issue
Block a user