3
3
from __future__ import annotations
4
4
5
5
from importlib import import_module
6
- from pathlib import Path
7
6
import warnings
8
7
9
8
from dash import Dash , Input , Output , callback
10
9
from dash .dash_table import DataTable
11
10
from dash .dcc import Store , Tab , Tabs
12
- from dash .html import H1 , Div
11
+ from dash .html import H1 , H3 , Div
12
+ from yaml import safe_load
13
13
14
- from ml_peg import app
15
14
from ml_peg .analysis .utils .utils import calc_ranks , calc_scores , get_table_style
15
+ from ml_peg .app import APP_ROOT
16
16
from ml_peg .app .utils .build_components import build_weight_components
17
17
18
18
@@ -35,14 +35,14 @@ def get_all_tests(
35
35
# Find Python files e.g. app_OC157.py in mlip_tesing.app module.
36
36
# We will get the category from the parent's parent directory
37
37
# E.g. ml_peg/app/surfaces/OC157/app_OC157.py -> surfaces
38
- tests = Path ( app . __file__ ). parent .glob (f"{ category } /*/app*.py" )
38
+ tests = APP_ROOT .glob (f"{ category } /*/app*.py" )
39
39
layouts = {}
40
40
tables = {}
41
41
42
42
# Build all layouts, and register all callbacks to main app.
43
43
for test in tests :
44
44
try :
45
- # Import tab application layout/callbacks
45
+ # Import test layout/callbacks
46
46
test_name = test .parent .name
47
47
category_name = test .parent .parent .name
48
48
test_module = import_module (
@@ -64,7 +64,7 @@ def get_all_tests(
64
64
)
65
65
continue
66
66
67
- # Register tab callbacks
67
+ # Register test callbacks
68
68
try :
69
69
test_app .register_callbacks ()
70
70
except FileNotFoundError as err :
@@ -94,19 +94,29 @@ def build_category(
94
94
95
95
Returns
96
96
-------
97
- ...
98
- .. .
97
+ tuple[dict[str, list[Div]], dict[str, DataTable]]
98
+ Dictionary of category layouts, and dictionary of category summary tables .
99
99
"""
100
100
# Take all tables in category, build new table, and set layout
101
101
category_layouts = {}
102
102
category_tables = {}
103
103
104
104
for category in all_layouts :
105
+ # Get category name and description
106
+ try :
107
+ with open (APP_ROOT / category / f"{ category } .yml" ) as file :
108
+ category_info = safe_load (file )
109
+ category_title = category_info .get ("title" , category )
110
+ category_descrip = category_info .get ("description" , "" )
111
+ except FileNotFoundError :
112
+ category_title = category
113
+ category_descrip = ""
114
+
105
115
# Build summary table
106
116
summary_table = build_summary_table (
107
117
all_tables [category ], table_id = f"{ category } -summary-table"
108
118
)
109
- category_tables [category ] = summary_table
119
+ category_tables [category_title ] = summary_table
110
120
111
121
# Build weight components for summary table
112
122
weight_components = build_weight_components (
@@ -117,9 +127,10 @@ def build_category(
117
127
)
118
128
119
129
# Build full layout with summary table, weight controls, and test layouts
120
- category_layouts [category ] = Div (
130
+ category_layouts [category_title ] = Div (
121
131
[
122
- H1 (category ),
132
+ H1 (category_title ),
133
+ H3 (category_descrip ),
123
134
summary_table ,
124
135
weight_components ,
125
136
Div ([all_layouts [category ][test ] for test in all_layouts [category ]]),
0 commit comments