Skip to content

Commit 47eae45

Browse files
committed
Add new route for updating batch time window and refactor data retrieval logic
1 parent 4f4254b commit 47eae45

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

dashboard/routes/search.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from monsterui.all import *
66

77
from dashboard.app import app, rt
8-
from .batch_view import ChartManager
8+
from .batch_view import ChartManager, get_batch_view, DEFAULT_LOAD_N_CHARTS
9+
from dashboard.data import get_data
910

1011

1112
@rt("/batch/{batch_name}/search")
@@ -79,3 +80,22 @@ def get(batch_name: str, start_index: int):
7980
hx_swap_oob="true",
8081
),
8182
]
83+
84+
@rt("/batch/{batch_name}/update-n")
85+
def post(batch_name: str, last_n: str = "30n", session=None):
86+
"""Update time window."""
87+
try:
88+
app.state.last_n[batch_name] = last_n
89+
app.state.clear_batch_cache(batch_name)
90+
app.state.df_cache[batch_name] = get_data(
91+
app.state.specs_enabled[batch_name],
92+
last_n=last_n,
93+
ensure_timestamp=True
94+
)
95+
app.state.calculate_metric_stats(batch_name)
96+
return get_batch_view(batch_name, initial_load=DEFAULT_LOAD_N_CHARTS)
97+
except ValueError as e:
98+
return Div(
99+
P(str(e), cls="text-red-500 p-4 text-center"),
100+
id="main-content",
101+
)

0 commit comments

Comments
 (0)