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)
|
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(
|
@api_bp.output(
|
||||||
FileSchema(type="string", format="binary"), content_type="image/png", example=""
|
FileSchema(type="string", format="binary"), content_type="image/png", example=""
|
||||||
)
|
)
|
||||||
def get_dataset_hist(name: str):
|
def get_dataset_hist(name: str, column: str):
|
||||||
data = service.get_hist(name)
|
data = service.get_hist(name, column)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
return send_file(
|
return send_file(data, download_name=f"{name}.hist.png", mimetype="image/png")
|
||||||
data,
|
|
||||||
download_name=f"{name}.hist.png",
|
|
||||||
mimetype="image/png",
|
|
||||||
as_attachment=True,
|
|
||||||
conditional=True,
|
|
||||||
)
|
|
||||||
|
@ -49,12 +49,10 @@ class Service:
|
|||||||
items = sorted(dataset[column].astype(str).unique())
|
items = sorted(dataset[column].astype(str).unique())
|
||||||
return {"datatype": datatype, "items": items}
|
return {"datatype": datatype, "items": items}
|
||||||
|
|
||||||
def get_hist(self, filename) -> BinaryIO:
|
def get_hist(self, filename, column) -> BinaryIO:
|
||||||
dataset = self.__get_dataset(filename)
|
dataset = self.__get_dataset(filename)
|
||||||
data = dataset[["Pclass", "Survived", "Age"]].copy()
|
|
||||||
data.dropna(subset=["Age"], inplace=True)
|
|
||||||
bytes = io.BytesIO()
|
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:
|
if plot is None:
|
||||||
raise Exception("Can't create hist plot")
|
raise Exception("Can't create hist plot")
|
||||||
plot.savefig(bytes, dpi=300, format="png")
|
plot.savefig(bytes, dpi=300, format="png")
|
||||||
|
Loading…
Reference in New Issue
Block a user