def hello(): """The flask web app first runs the temperature and CO2 plot generators for specified parameters, generates an image, and then embeds that image the web page by using html.""" plot_temperature('February', 1820, 2000, -10, 10) plot_CO2(1820, 2000, 3, 10000) plot_CO2_by_country(1.5, 3.0, 1960) return render_template('assign6.html', var=random.random())
def render_page(options): plot_temperature(options) temperature_url = save_plot_and_return_url() plot_CO2(options) co2_url = save_plot_and_return_url() return render_template('index.html', temperature_url=temperature_url, co2_url=co2_url, options=options)
def root(): temp_file = BytesIO() co2_file = BytesIO() plot_temperature(fig_file=temp_file) plot_CO2(fig_file=co2_file) temp_file.seek(0) co2_file.seek(0) temp_figdata_png = base64.b64encode(temp_file.getvalue()).decode() co2_figdata_png = base64.b64encode(co2_file.getvalue()).decode() return render_template('plots.html', co2_plot=co2_figdata_png, temp_plot=temp_figdata_png)
def temperature_plot(): months = request.args.getlist("month") if len(months) == 0: months = "January" tmin = request.args.get("tmin") tmax = request.args.get("tmax") t_b = (int(tmin), int(tmax)) if tmin != "" and tmax != "" else None ymin = request.args.get("ymin") ymax = request.args.get("ymax") y_b = (float(ymin), float(ymax)) if ymin != "" and ymax != "" else None plotter.plot_temperature(months, time_bounds=t_b, y_bounds=y_b) plt.savefig("static/plot_img.png") return render_template("show_plot.html")
def temp_plot(): ymin = request.form["ymin"] ymax = request.form["ymax"] start_year = int(request.form["starty"]) end_year = int(request.form["endy"]) month = int(request.form["month"]) temp_data = np.genfromtxt("temperature.csv", delimiter=',', dtype="str") plot_temperature(temp_data, month, ymin, ymax, start_year, end_year) return render_template('plot_temp.html', start_year=start_year, end_year=end_year, ymin=ymin, ymax=ymax, month=month)
def temperature(): """ Takes the given aguments from the user and creates pyplot with plot_temperature and returns it to temperature_page.html """ if request.method == "GET": return render_template("temperature_page.html", yearMin=tempYearMin, yearMax=tempYearMax) month = request.form["month"] start = request.form["start"] end = request.form["end"] minY = request.form["minY"] maxY = request.form["maxY"] args = [_str(month), _int(start), _int(end), _float(minY), _float(maxY)] plots = [ base64.b64encode(plot.getvalue()).decode("ascii") for plot in plot_temperature(*args) ] return render_template("temperature_page.html", plots=plots, yearMin=tempYearMin, yearMax=tempYearMax, m=month, start=start, end=end, minY=minY, maxY=maxY)
def handle_changes(): '''This function incorporates the users requested changes into the plots, generates updated plots and then updates the web page.''' assert request.method == 'POST' # Check that we are really in a POST request # Acces the form data: m = str(request.form["month"]) ts = int(request.form["t_starting_year"]) te = int(request.form["t_ending_year"]) tys = float(request.form["t_y_min"]) tye = float(request.form["t_y_max"]) cs = int(request.form["c_starting_year"]) ce = int(request.form["c_ending_year"]) cys = float(request.form["c_y_min"]) cye = float(request.form["c_y_max"]) plot_temperature(m, ts, te, tys, tye) plot_CO2(cs, ce, cys, cye) return render_template('assign6.html', var=random.random())
def temperature(): start_year = int(request.form['selectStartYear']) end_year = int(request.form['selectEndYear']) ymin = float(request.form['ymin']) ymax = float(request.form['ymax']) month = request.form['selectMonth'] plot_temperature((start_year, end_year), ymin, ymax, month) file = '{}_plot.png'.format(month) return render_template('result_template.html', start_year=start_year, end_year=end_year, ymin=ymin, ymax=ymax, month=month, file=file)
def temperature(): #convert parameters to ints arguments = {k: int(v) for k, v in request.form.items() if v} #get months month = arguments.get("month", 1) #remove month if in arguments to avoid duplicate arguments if "month" in arguments: del(arguments["month"]) b = plot_temperature(month, "svg", **arguments) svg = b[b.index(b"<svg "):].decode() arguments["month"] = month return render_template("temperature.html",month_list=month_list[1:], svg=svg, **arguments)
def temp_plot(): start_yearTemp = int(request.form["startyearTemp"]) end_yearTemp = int(request.form["endyearTemp"]) ymin = request.form["yminTemp"] ymax = request.form["ymaxTemp"] y_axis = [ymin, ymax] if ("Default" in y_axis) or ("" in y_axis): y_axis = None else: y_axis = [float(ymin), float(ymax)] month = request.form["month"] temp = plot_temperature(month, start_yearTemp, end_yearTemp, y_axis) return render_template("temp_plot.html", temp=temp)