Petits ajustements (cache => utils, noms de variables)
This commit is contained in:
+1
-1
@@ -7,8 +7,8 @@ from dash import Dash, Input, Output, State, dcc, html, page_container, page_reg
|
||||
from dotenv import load_dotenv
|
||||
from flask import Response
|
||||
|
||||
from src.cache import cache
|
||||
from src.utils import DEVELOPMENT
|
||||
from utils.cache import cache
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from dash import (
|
||||
register_page,
|
||||
)
|
||||
|
||||
from src.cache import cache
|
||||
from src.db import query_marches, schema
|
||||
from src.figures import (
|
||||
DataTable,
|
||||
@@ -40,6 +39,7 @@ from src.utils.data import (
|
||||
from src.utils.frontend import get_enum_values_as_dict
|
||||
from src.utils.seo import META_CONTENT
|
||||
from src.utils.table import COLUMNS, get_default_hidden_columns, prepare_table_data
|
||||
from utils.cache import cache
|
||||
|
||||
NAME = "Observatoire"
|
||||
|
||||
@@ -658,9 +658,11 @@ def _normalize_filter_params(filter_params: dict) -> tuple:
|
||||
|
||||
|
||||
@cache.memoize()
|
||||
def _compute_dashboard_children(cache_key: tuple):
|
||||
def _compute_dashboard_children(filter_params_normalized: tuple):
|
||||
logger.debug("Cache miss — computing dashboard")
|
||||
filter_params = {k: (list(v) if isinstance(v, tuple) else v) for k, v in cache_key}
|
||||
filter_params = {
|
||||
k: (list(v) if isinstance(v, tuple) else v) for k, v in filter_params_normalized
|
||||
}
|
||||
|
||||
lff: pl.LazyFrame = query_marches().lazy()
|
||||
lff = prepare_dashboard_data(lff=lff, **filter_params)
|
||||
@@ -772,8 +774,8 @@ def update_dashboard_cards(*filter_values):
|
||||
):
|
||||
filter_params[input_id] = value
|
||||
|
||||
cache_key = _normalize_filter_params(filter_params)
|
||||
children = _compute_dashboard_children(cache_key)
|
||||
filter_params_normalized = _normalize_filter_params(filter_params)
|
||||
children = _compute_dashboard_children(filter_params_normalized)
|
||||
|
||||
return dbc.Row(children=children), filter_params
|
||||
|
||||
|
||||
+3
-3
@@ -5,12 +5,12 @@ import polars as pl
|
||||
from dash import no_update
|
||||
from polars import selectors as cs
|
||||
|
||||
from src.cache import cache
|
||||
from src.db import query_marches, schema
|
||||
from src.utils import logger
|
||||
from src.utils.data import DATA_SCHEMA
|
||||
from src.utils.frontend import get_button_properties
|
||||
from src.utils.tracking import track_search
|
||||
from utils.cache import cache
|
||||
|
||||
|
||||
def split_filter_part(filter_part):
|
||||
@@ -150,7 +150,7 @@ def dates_to_strings(lff: pl.LazyFrame, column: str) -> pl.LazyFrame:
|
||||
def normalize_sort_by(sort_by) -> tuple:
|
||||
if not sort_by:
|
||||
return ()
|
||||
return tuple((entry["column_id"], entry["direction"]) for entry in sort_by)
|
||||
return tuple(sorted((entry["column_id"], entry["direction"]) for entry in sort_by))
|
||||
|
||||
|
||||
def format_number(number) -> str:
|
||||
@@ -167,7 +167,7 @@ def unformat_montant(number: str) -> float:
|
||||
|
||||
|
||||
def format_values(dff: pl.DataFrame) -> pl.DataFrame:
|
||||
def format_montant(expr, scale=None):
|
||||
def format_montant(expr):
|
||||
# https://stackoverflow.com/a/78636786
|
||||
expr = expr.cast(pl.String)
|
||||
expr = expr.str.splitn(".", 2)
|
||||
|
||||
Reference in New Issue
Block a user