Skip to content

Commit ac0a51c

Browse files
committed
Refactor table schema methods in multiple UI managers to standardize column definitions and filters
1 parent 499c0c8 commit ac0a51c

4 files changed

Lines changed: 76 additions & 85 deletions

File tree

schismviz/out2dui.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,25 @@ def get_data_for_time_range(self, r, time_range) -> tuple[pd.DataFrame, str, str
292292
# DataUIManager required overrides — table / map configuration
293293
# ------------------------------------------------------------------
294294

295-
def get_table_column_width_map(self) -> dict:
295+
def get_table_schema(self, df=None):
296+
if df is None:
297+
df = self.get_data_catalog()
296298
return {
297-
"node_id": "10%",
298-
"node_name": "15%",
299-
"variable": "20%",
300-
"unit": "10%",
301-
"x": "15%",
302-
"y": "15%",
303-
}
304-
305-
def get_table_filters(self) -> dict:
306-
return {
307-
"node_name": {
308-
"type": "input",
309-
"func": "like",
310-
"placeholder": "Enter match",
299+
"required_columns": ["node_id", "node_name", "variable", "unit", "x", "y"],
300+
"optional_columns": [],
301+
"hidden_by_default": [],
302+
"drop_if_all_null": False,
303+
"column_widths": {
304+
"node_id": "10%",
305+
"node_name": "15%",
306+
"variable": "20%",
307+
"unit": "10%",
308+
"x": "15%",
309+
"y": "15%",
311310
},
312-
"variable": {
313-
"type": "input",
314-
"func": "like",
315-
"placeholder": "Enter match",
311+
"filters": {
312+
"node_name": {"type": "input", "func": "like", "placeholder": "Enter match"},
313+
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
316314
},
317315
}
318316

schismviz/readers.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -477,35 +477,26 @@ def _make_plot_action(self) -> SchismRegistryPlotAction:
477477
# Table / map configuration
478478
# ------------------------------------------------------------------
479479

480-
def _get_table_column_width_map(self) -> dict:
480+
def get_table_schema(self, df=None):
481+
if df is None:
482+
df = self.get_data_catalog()
483+
optional = [c for c in ["source_num"] if c in (df.columns if hasattr(df, "columns") else [])]
481484
return {
482-
"station": "10%",
483-
"station_name": "15%",
484-
"variable": "12%",
485-
"unit": "10%",
486-
}
487-
488-
def get_table_filters(self) -> dict:
489-
return {
490-
"station": {
491-
"type": "input",
492-
"func": "like",
493-
"placeholder": "Enter match",
494-
},
495-
"station_name": {
496-
"type": "input",
497-
"func": "like",
498-
"placeholder": "Enter match",
499-
},
500-
"variable": {
501-
"type": "input",
502-
"func": "like",
503-
"placeholder": "Enter match",
485+
"required_columns": ["station", "station_name", "variable", "unit"],
486+
"optional_columns": optional,
487+
"hidden_by_default": [],
488+
"drop_if_all_null": True,
489+
"column_widths": {
490+
"station": "10%",
491+
"station_name": "15%",
492+
"variable": "12%",
493+
"unit": "10%",
504494
},
505-
"unit": {
506-
"type": "input",
507-
"func": "like",
508-
"placeholder": "Enter match",
495+
"filters": {
496+
"station": {"type": "input", "func": "like", "placeholder": "Enter match"},
497+
"station_name": {"type": "input", "func": "like", "placeholder": "Enter match"},
498+
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
499+
"unit": {"type": "input", "func": "like", "placeholder": "Enter match"},
509500
},
510501
}
511502

schismviz/schismcalibplotui.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,27 @@ def _build_dvue_catalog(self) -> DataCatalog:
304304
pass # duplicate id+variable; skip
305305
return catalog
306306

307-
def get_table_column_width_map(self):
308-
"""only columns to be displayed in the table should be included in the map"""
309-
column_width_map = {
310-
"id": "10%",
311-
"name": "65%",
312-
"variable": "15%",
313-
"unit": "10%",
314-
}
315-
return column_width_map
316-
317-
def get_table_filters(self):
318-
table_filters = {
319-
"id": {"type": "input", "func": "like", "placeholder": "Enter match"},
320-
"name": {"type": "input", "func": "like", "placeholder": "Enter match"},
321-
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
322-
"unit": {
323-
"type": "input",
324-
"func": "like",
325-
"placeholder": "Enter match",
307+
def get_table_schema(self, df=None):
308+
if df is None:
309+
df = self.get_data_catalog()
310+
return {
311+
"required_columns": ["id", "name", "variable", "unit"],
312+
"optional_columns": [],
313+
"hidden_by_default": [],
314+
"drop_if_all_null": False,
315+
"column_widths": {
316+
"id": "10%",
317+
"name": "65%",
318+
"variable": "15%",
319+
"unit": "10%",
320+
},
321+
"filters": {
322+
"id": {"type": "input", "func": "like", "placeholder": "Enter match"},
323+
"name": {"type": "input", "func": "like", "placeholder": "Enter match"},
324+
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
325+
"unit": {"type": "input", "func": "like", "placeholder": "Enter match"},
326326
},
327327
}
328-
return table_filters
329328

330329
def get_datastore_param_name(self, variable):
331330
return VAR_to_PARAM[variable]

schismviz/schismui.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,29 @@ def build_station_name(self, r):
282282
return f"{name}"
283283
return f'{r["source"]}:{name}'
284284

285-
def get_table_column_width_map(self):
286-
"""only columns to be displayed in the table should be included in the map"""
287-
column_width_map = {
288-
"id": "10%",
289-
"station_name": "15%",
290-
"variable": "15%",
291-
"unit": "15%",
292-
"source": "10%",
285+
def get_table_schema(self, df=None):
286+
if df is None:
287+
df = self.get_data_catalog()
288+
return {
289+
"required_columns": ["id", "station_name", "variable", "unit", "source"],
290+
"optional_columns": [],
291+
"hidden_by_default": [],
292+
"drop_if_all_null": False,
293+
"column_widths": {
294+
"id": "10%",
295+
"station_name": "15%",
296+
"variable": "15%",
297+
"unit": "15%",
298+
"source": "10%",
299+
},
300+
"filters": {
301+
"id": {"type": "input", "func": "like", "placeholder": "Enter match"},
302+
"station_name": {"type": "input", "func": "like", "placeholder": "Enter match"},
303+
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
304+
"unit": {"type": "input", "func": "like", "placeholder": "Enter match"},
305+
"source": {"type": "input", "func": "like", "placeholder": "Enter match"},
306+
},
293307
}
294-
return column_width_map
295-
296-
def get_table_filters(self):
297-
table_filters = {
298-
"id": {"type": "input", "func": "like", "placeholder": "Enter match"},
299-
"station_name": {"type": "input", "func": "like", "placeholder": "Enter match"},
300-
"variable": {"type": "input", "func": "like", "placeholder": "Enter match"},
301-
"unit": {"type": "input", "func": "like", "placeholder": "Enter match"},
302-
"source": {"type": "input", "func": "like", "placeholder": "Enter match"},
303-
}
304-
return table_filters
305308

306309
def is_irregular(self, r):
307310
return False

0 commit comments

Comments
 (0)