# based on https://gist.github.com/rduplain/1641344 import os from flask import Flask, make_response, request, render_template from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas import plots import pandas as pd config = { "DEBUG": True # run app in debug mode } app = Flask(__name__) params = [] def grade_files(): grade_files = {} for file in os.listdir('./'): if file.endswith(".csv"): grade_files[file] = {} grade_file = pd.read_csv(file, skiprows=2, sep=';') for i in grade_file: grade_files[file][i] = 'checked' break # Could add exam fle at some point here as well return grade_files def figure(): plots.plot() def value_to_list(given_list, old_value, new_value): given_list = list(map(lambda x: x[1].replace(old_value, new_value), [j for j in given_list])) return given_list def initialize(): title = "Project Numeri" plots = os.listdir(os.path.join(app.static_folder, "plots")) return title, plots, grade_files() # Renders template. All below is constantly executed by Flask @app.route('/', methods=['GET', 'POST']) def root(): title, plots, grade_files = params if request.method == 'POST': form = request.form for filename in grade_files: grade_files_unchecked = grade_files[filename].keys() - form.keys() for column_name in grade_files_unchecked: grade_files[filename][column_name] = "unchecked" return render_template('index.html', title=title, plots=plots, grade_files=grade_files) if __name__ == '__main__': params = initialize() app.run(debug=True, port=5003)