Add processing module
This commit is contained in:
parent
ffe9009d1b
commit
7011a8f405
|
@ -0,0 +1,49 @@
|
|||
from base64 import b64encode
|
||||
from io import BytesIO
|
||||
|
||||
from folium import Map
|
||||
|
||||
from app.preprocessing import create_dataframe
|
||||
from constants import COORDINATES
|
||||
|
||||
|
||||
def get_figure(plot):
|
||||
plot_figure = plot.get_figure()
|
||||
figure = BytesIO()
|
||||
plot_figure.savefig(figure)
|
||||
figure.seek(0)
|
||||
return figure
|
||||
|
||||
|
||||
def render_plot(df):
|
||||
df.fillna(value=0, inplace=True)
|
||||
plot = df.plot("year", ["surface", "length", "elevation"], kind="bar")
|
||||
figure = get_figure(plot)
|
||||
return figure
|
||||
|
||||
|
||||
def encode_plot(figure):
|
||||
plot = b64encode(figure.getvalue().decode())
|
||||
return plot
|
||||
|
||||
|
||||
def create_plot(df):
|
||||
figure = render_plot(df)
|
||||
plot = encode_plot(figure)
|
||||
return plot
|
||||
|
||||
|
||||
def create_map(df):
|
||||
map = Map(location=COORDINATES)
|
||||
for row in df.iterrows():
|
||||
map.simple_marker(
|
||||
location=[row["fields.geo_shape.coordinates"]], clustered_marker=True
|
||||
)
|
||||
return map
|
||||
|
||||
|
||||
def process_data(dataset):
|
||||
df = create_dataframe(dataset)
|
||||
plot = create_plot(df)
|
||||
map = create_map(df)
|
||||
return plot, map
|
|
@ -2,6 +2,7 @@ from flask import render_template
|
|||
|
||||
from app import app
|
||||
from app.forms import DatasetForm
|
||||
from app.processing import process_data
|
||||
|
||||
|
||||
@app.route("/")
|
||||
|
@ -19,5 +20,8 @@ def data():
|
|||
|
||||
|
||||
@app.route("/visualization")
|
||||
def visualization():
|
||||
return render_template("visualization.html", title="Visualization", form=form)
|
||||
def visualization(form):
|
||||
plot, map = process_data(form.dataset)
|
||||
return render_template(
|
||||
"visualization.html", title="Visualization", plot=plot, map=map
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% block app_content %}
|
||||
<h1>Dataset visualization</h1>
|
||||
<img src="data:image/png;base64,{{ plot }}" alt="Image Placeholder">
|
||||
<img src="data:image/png;base64,{{ map }}" alt="Image Placeholder">
|
||||
<img src="data:image/png;base64,{{ plot }}" alt="Plot Placeholder">
|
||||
<img src="data:image/png;base64,{{ map }}" alt="Map Placeholder">
|
||||
<p><a href="{{ url_for('data') }}">Back</a></p>
|
||||
{% endblock %}
|
||||
|
|
|
@ -48,3 +48,4 @@ COLUMNS = {
|
|||
],
|
||||
}
|
||||
SECRET_KEY = "trolaso"
|
||||
COORDINATES = [48.864716, 2.349014]
|
||||
|
|
Loading…
Reference in New Issue