|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from fastapi import FastAPI, Request |
|
|
from pydantic import BaseModel |
|
|
from autoviz import AutoViz_Class |
|
|
import os |
|
|
import pandas as pd |
|
|
import uuid |
|
|
from fastapi import APIRouter |
|
|
|
|
|
Autoviz_router = APIRouter(prefix="/autoviz", tags=["autoviz"]) |
|
|
|
|
|
|
|
|
class AutoVizParams(BaseModel): |
|
|
filename: str |
|
|
sep: str = "," |
|
|
depVar: str = "" |
|
|
header: int = 0 |
|
|
verbose: int = 2 |
|
|
lowess: bool = False |
|
|
chart_format: str = "html" |
|
|
max_rows_analyzed: int = 150000 |
|
|
max_cols_analyzed: int = 30 |
|
|
|
|
|
def run_autoviz( |
|
|
filename, |
|
|
sep=",", |
|
|
depVar="", |
|
|
dfte=None, |
|
|
header=0, |
|
|
verbose=2, |
|
|
lowess=False, |
|
|
chart_format="html", |
|
|
max_rows_analyzed=150000, |
|
|
max_cols_analyzed=30, |
|
|
save_plot_dir=None |
|
|
): |
|
|
vis_in = str(uuid.uuid4()) |
|
|
save_plot_dir = f"./{chart_format}_{vis_in}" |
|
|
os.makedirs(save_plot_dir, exist_ok=True) |
|
|
df = pd.read_csv(filename) |
|
|
AV = AutoViz_Class() |
|
|
dft = AV.AutoViz( |
|
|
filename, |
|
|
sep=sep, |
|
|
depVar=depVar, |
|
|
dfte=dfte, |
|
|
header=header, |
|
|
verbose=verbose, |
|
|
lowess=lowess, |
|
|
chart_format=chart_format, |
|
|
max_rows_analyzed=max_rows_analyzed, |
|
|
max_cols_analyzed=max_cols_analyzed, |
|
|
save_plot_dir=save_plot_dir |
|
|
) |
|
|
return {"message": "AutoViz run complete", "plots_dir": save_plot_dir} |
|
|
|
|
|
@Autoviz_router.post("/run_autoviz") |
|
|
async def autoviz_api(params: AutoVizParams): |
|
|
result = run_autoviz( |
|
|
filename=params.filename, |
|
|
sep=params.sep, |
|
|
depVar=params.depVar, |
|
|
dfte=None, |
|
|
header=params.header, |
|
|
verbose=params.verbose, |
|
|
lowess=params.lowess, |
|
|
chart_format=params.chart_format, |
|
|
max_rows_analyzed=params.max_rows_analyzed, |
|
|
max_cols_analyzed=params.max_cols_analyzed, |
|
|
save_plot_dir=None |
|
|
) |
|
|
return result |