56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
|
|
import base64
|
||
|
|
|
||
|
|
from flask import Flask, request, render_template
|
||
|
|
|
||
|
|
from analyzer.parser import parse_csv
|
||
|
|
from analyzer.grouper import detect_groups
|
||
|
|
from analyzer.stats import compute_overall_stats, compute_group_stats
|
||
|
|
from analyzer.charts import render_group_charts, render_overview_chart
|
||
|
|
from analyzer.pdf_report import generate_pdf
|
||
|
|
|
||
|
|
app = Flask(__name__)
|
||
|
|
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
|
||
|
|
|
||
|
|
|
||
|
|
@app.route("/")
|
||
|
|
def index():
|
||
|
|
return render_template("upload.html")
|
||
|
|
|
||
|
|
|
||
|
|
@app.route("/analyze", methods=["POST"])
|
||
|
|
def analyze():
|
||
|
|
if "csv_file" not in request.files or request.files["csv_file"].filename == "":
|
||
|
|
return render_template("upload.html", error="No file selected.")
|
||
|
|
|
||
|
|
file = request.files["csv_file"]
|
||
|
|
|
||
|
|
try:
|
||
|
|
df = parse_csv(file.stream)
|
||
|
|
groups = detect_groups(df)
|
||
|
|
overall = compute_overall_stats(df)
|
||
|
|
group_stats = compute_group_stats(groups)
|
||
|
|
charts = render_group_charts(
|
||
|
|
groups,
|
||
|
|
y_min=overall["min_speed"],
|
||
|
|
y_max=overall["max_speed"],
|
||
|
|
)
|
||
|
|
overview_chart = render_overview_chart(group_stats)
|
||
|
|
except ValueError as e:
|
||
|
|
return render_template("upload.html", error=str(e))
|
||
|
|
|
||
|
|
pdf_bytes = generate_pdf(overall, group_stats, charts, overview_chart)
|
||
|
|
pdf_b64 = base64.b64encode(pdf_bytes).decode("utf-8")
|
||
|
|
|
||
|
|
groups_display = list(zip(group_stats, charts))
|
||
|
|
return render_template(
|
||
|
|
"results.html",
|
||
|
|
overall=overall,
|
||
|
|
groups_display=groups_display,
|
||
|
|
overview_chart=overview_chart,
|
||
|
|
pdf_b64=pdf_b64,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
app.run(debug=True)
|