Dashboard: fix plots

This commit is contained in:
phil 2024-03-25 10:10:58 +05:30
parent 5434c7d6ef
commit c8ca68e1a4
3 changed files with 28 additions and 20 deletions

View file

@ -1,7 +1,5 @@
import logging
from pathlib import Path
from json import dumps
from typing import Annotated
from fastapi import Depends, APIRouter, HTTPException, status, responses
from sqlalchemy.orm import selectinload
@ -10,7 +8,7 @@ import pandas as pd
import geopandas as gpd
from gisaf.config import conf
from gisaf.utils import NumpyEncoder
from gisaf.utils import dict_array_to_list
from gisaf.database import fastapi_db_session as db_session
from gisaf.models.authentication import User
from gisaf.models.dashboard import (
@ -138,16 +136,8 @@ async def get_dashboard_page(group: str, name: str,
'see debug message')
logger.exception(err)
if page.plot:
try:
plot = page.get_plot()
plotData = {
'data': [d.to_plotly_json() for d in plot.data],
'layout': plot.layout.to_plotly_json(),
}
except Exception as err:
logger.warning(f'Dashboard: cannot add plot for page {page.name}, '
'see debug message')
logger.exception(err)
else:
dp.plotData = dumps(plotData, cls=NumpyEncoder)
plot = page.get_plot()
## Convert manually numpy arrays to lists
dp.plotData = [dict_array_to_list(d.to_plotly_json()) for d in plot.data]
dp.plotLayout = plot.layout.to_plotly_json()
return dp