Skip to content

Commit c2251a9

Browse files
committed
Rename alert_max_n to last_n and update related functions
Refactor dashboard components and functions to use a more generic "last_n" parameter instead of "alert_max_n". This includes updates to: - Components - Constants - Data retrieval functions - Routes - State management - SQL query template The changes provide a more flexible approach to filtering and displaying recent observations across the dashboard.
1 parent 27c821e commit c2251a9

File tree

6 files changed

+176
-132
lines changed

6 files changed

+176
-132
lines changed

dashboard/components.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _create_controls(batch_name):
128128
uk_tooltip="Refresh metrics data from source",
129129
),
130130
_create_search_form(batch_name),
131-
_create_alert_n_form(batch_name),
131+
_create_last_n_form(batch_name),
132132
style="display: flex; align-items: center; gap: 0.5rem;",
133133
),
134134
Div(
@@ -188,21 +188,22 @@ def _create_search_form(batch_name):
188188
)
189189

190190

191-
def _create_alert_n_form(batch_name):
191+
def _create_last_n_form(batch_name):
192192
"""
193-
Create the alert number form for the dashboard.
193+
Create the last n number form for the dashboard.
194194
"""
195195
state = get_state() # Get state instance first
196196
return Form(
197197
DivLAligned(
198198
Input(
199199
type="number",
200-
name="alert_max_n",
201-
value=state.alert_max_n.get(batch_name, DEFAULT_ALERT_MAX_N),
200+
name="last_n",
201+
value=state.last_n.get(batch_name, DEFAULT_LAST_N),
202202
min=1,
203203
max=1000,
204204
step=1,
205205
cls="uk-input uk-form-small uk-form-width-small",
206+
uk_tooltip="Filter for last N observations",
206207
),
207208
cls="space-x-2",
208209
),

dashboard/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"""
44

55
DEFAULT_LOAD_N_CHARTS = 10
6-
DEFAULT_ALERT_MAX_N = 30
6+
DEFAULT_LAST_N = 30

dashboard/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
from anomstack.sql.read import read_sql
88

99

10-
def get_data(spec: dict, max_n: int = 30, ensure_timestamp: bool = False) -> pd.DataFrame:
10+
def get_data(spec: dict, last_n: int = 30, ensure_timestamp: bool = False) -> pd.DataFrame:
1111
"""
12-
Get data from the database for a given spec and max_n.
12+
Get data from the database for a given spec and last_n.
1313
1414
Args:
1515
spec: The spec to get data for.
16-
max_n: The maximum number of alerts to return.
16+
last_n: The maximum number of observations to return.
1717
1818
Returns:
1919
A pandas DataFrame containing the data.
2020
"""
2121
sql = render(
2222
"dashboard_sql",
2323
spec,
24-
params={"alert_max_n": max_n},
24+
params={"last_n": last_n},
2525
)
2626
db = spec["db"]
2727
df = read_sql(sql, db=db)

dashboard/routes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def index(request: Request):
6666

6767
df = get_data(
6868
app.state.specs_enabled[batch_name],
69-
max_n=DEFAULT_ALERT_MAX_N,
69+
last_n=DEFAULT_LAST_N,
7070
ensure_timestamp=True
7171
)
7272

@@ -182,7 +182,7 @@ def get_batch_view(batch_name: str, session, initial_load: int = DEFAULT_LOAD_N_
182182
if batch_name not in app.state.df_cache:
183183
app.state.df_cache[batch_name] = get_data(
184184
app.state.specs_enabled[batch_name],
185-
max_n=DEFAULT_ALERT_MAX_N,
185+
last_n=DEFAULT_LAST_N,
186186
ensure_timestamp=True
187187
)
188188
app.state.calculate_metric_stats(batch_name)
@@ -395,16 +395,16 @@ def get(batch_name: str, search: str = ""):
395395

396396

397397
@rt("/batch/{batch_name}/update-n")
398-
def post(batch_name: str, alert_max_n: int = DEFAULT_ALERT_MAX_N, session=None):
398+
def post(batch_name: str, last_n: int = DEFAULT_LAST_N, session=None):
399399
"""
400-
Update the number of alerts for a given batch name.
400+
Update the number of observations for a given batch name.
401401
"""
402-
app.state.alert_max_n[batch_name] = alert_max_n
402+
app.state.last_n[batch_name] = last_n
403403
app.state.clear_batch_cache(batch_name)
404404

405405
app.state.df_cache[batch_name] = get_data(
406406
app.state.specs_enabled[batch_name],
407-
max_n=alert_max_n,
407+
last_n=last_n,
408408
ensure_timestamp=True
409409
)
410410
app.state.calculate_metric_stats(batch_name)

dashboard/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self):
3232
self.dark_mode = False
3333
self.two_columns = True
3434
self.show_markers = True
35-
self.alert_max_n = {}
35+
self.last_n = {}
3636
self.line_width = 2
3737
self.show_legend = False
3838
self.search_term = {}

0 commit comments

Comments
 (0)