Make draw hist method more universal
This commit is contained in:
parent
1702c19883
commit
f552afef2a
@ -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/<string:name>")
|
||||
@api_bp.get("/dataset/draw/hist/<string:name>/<string:column>")
|
||||
@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")
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user