save csv + paper dims

Co-authored-by: Alex <AlexanderMcDowell@users.noreply.github.com>
master
michael 2022-11-04 18:42:22 -07:00
parent fa1e988344
commit 76e178176d
4 changed files with 61 additions and 6 deletions

View File

@ -1,11 +1,11 @@
from flask import Flask, render_template, request from flask import Flask, render_template, request, send_file
import numpy as np import numpy as np
from ratio_pyrometry import ratio_pyrometry_pipeline from ratio_pyrometry import ratio_pyrometry_pipeline
from size_projection import get_projected_area from size_projection import get_projected_area
import base64 import base64
import cv2 as cv import cv2 as cv
import plotly.figure_factory as ff import plotly.figure_factory as ff
from scipy import stats import pandas as pd
app = Flask( app = Flask(
__name__, __name__,
@ -58,12 +58,28 @@ def ratio_pyro():
) )
freq_plot = fig.to_html() freq_plot = fig.to_html()
# create csv-formatted stuff
# currently only supports 1 firebrand (grabs first object in plot).
plot_data=fig.to_dict()
x_data = plot_data["data"][0]["x"]
y_data = plot_data["data"][0]["y"]
tdata = [["Temperature", "Frequency"]]
for i in range(len(x_data)):
r = []
r.append(x_data[i])
r.append(y_data[i])
tdata.append(r)
csvstr = pd.DataFrame(tdata).to_csv(index=False, header=False)
return render_template( return render_template(
'pyrometry-results.html', 'pyrometry-results.html',
img_orig_b64=img_orig_b64, img_orig_b64=img_orig_b64,
img_res_b64=img_res_b64, img_res_b64=img_res_b64,
legend=key, legend=key,
freq_plot=freq_plot freq_plot=freq_plot,
csv_data=csvstr
) )
@ -81,6 +97,8 @@ def projected_area_results():
f_bytes, f_bytes,
int(request.form['area_threshold']), int(request.form['area_threshold']),
int(request.form['min_display_threshold']), int(request.form['min_display_threshold']),
float(request.form['paper_width']),
float(request.form['paper_width'])
) )
return render_template( return render_template(
@ -88,3 +106,7 @@ def projected_area_results():
img_b64=img, img_b64=img,
dtable=dtable dtable=dtable
) )
# @app.route("/download_pyrometry_temps")
# def download_pyrometry_temps():
# return send_file()

View File

@ -9,9 +9,9 @@ import matplotlib.pyplot as plt
from skimage import measure, morphology, color, segmentation from skimage import measure, morphology, color, segmentation
import io import io
def get_projected_area(image, area_threshold, display_threshold): def get_projected_area(image, area_threshold, display_threshold, paper_width, paper_height):
total_px = image.size total_px = image.size
total_mm = 60322.46 total_mm = paper_width * paper_height * 25.4
output = [] output = []
original = cv.imdecode(image, cv.IMREAD_UNCHANGED) original = cv.imdecode(image, cv.IMREAD_UNCHANGED)

View File

@ -1,3 +1,21 @@
function saveCsv(csvString) { function saveCsv(csvStr) {
// string rep
// var csvStr = "";
// for (let r = 0; r < csvData.length; r++) {
// let row = csvData[r]
// for (let c = 0; c < row.length; c++) {
// let item = row[c]
// csvStr += item;
// if (c < row.length - 1)
// csvStr += ",";
// }
// if (r < csvStr.length - 1)
// csvStr += "\r\n";
// }
// define data blob
var data = new Blob([csvStr]);
// create & click temp link
window.open(URL.createObjectURL(data));
} }

View File

@ -1,6 +1,12 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block head %}
<script src="/s/js/csv_download.js"></script>
{% endblock %}
{% block content %} {% block content %}
<div style="display:flex; flex-direction: column;">
<table class="img-table"> <table class="img-table">
<tr> <tr>
<th class="img-table-heading">Input Image</th> <th class="img-table-heading">Input Image</th>
@ -33,8 +39,17 @@
</td> </td>
</tr> </tr>
</table> </table>
<br>
{# Temperature Frequency Plot #} {# Temperature Frequency Plot #}
<div style="display: flex; flex-direction: row; align-items: center;">
<strong>Temperature Distribution</strong> <strong>Temperature Distribution</strong>
<button
style="width: 10rem; height: 2rem; margin-left: 1rem;"
download="temperature-data.csv" type="text/csv" onclick="saveCsv(`{{csv_data}}`)">Download Data as CSV</button>
</div>
{{ freq_plot | safe }} {{ freq_plot | safe }}
</div>
{% endblock %} {% endblock %}