diff --git a/backend/api.py b/backend/api.py index 9c5ed0a..2f6d2be 100644 --- a/backend/api.py +++ b/backend/api.py @@ -47,17 +47,11 @@ def get_column_info(name: str, column: str): return service.get_column_info(name, column) -@api_bp.get("/dataset/draw/hist/") +@api_bp.get("/dataset/draw/hist//") @api_bp.output( FileSchema(type="string", format="binary"), content_type="image/png", example="" ) -def get_dataset_hist(name: str): - data = service.get_hist(name) +def get_dataset_hist(name: str, column: str): + data = service.get_hist(name, column) data.seek(0) - return send_file( - data, - download_name=f"{name}.hist.png", - mimetype="image/png", - as_attachment=True, - conditional=True, - ) + return send_file(data, download_name=f"{name}.hist.png", mimetype="image/png") diff --git a/backend/service.py b/backend/service.py index 0b4fde9..c4a3935 100644 --- a/backend/service.py +++ b/backend/service.py @@ -49,12 +49,10 @@ class Service: items = sorted(dataset[column].astype(str).unique()) return {"datatype": datatype, "items": items} - def get_hist(self, filename) -> BinaryIO: + def get_hist(self, filename, column) -> BinaryIO: dataset = self.__get_dataset(filename) - data = dataset[["Pclass", "Survived", "Age"]].copy() - data.dropna(subset=["Age"], inplace=True) bytes = io.BytesIO() - plot: Figure | None = data.plot.hist(column=["Age"], bins=80).get_figure() + plot: Figure | None = dataset.plot.hist(column=[column], bins=80).get_figure() if plot is None: raise Exception("Can't create hist plot") plot.savefig(bytes, dpi=300, format="png")