Skip to content

Commit 22add96

Browse files
committed
fix(loading): provide instant feedback and report loading time
1 parent 0d14c97 commit 22add96

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/e3sm_quickview/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import math
55
import os
6+
import time
67
from functools import partial
78
from pathlib import Path
89

@@ -450,10 +451,15 @@ def data_loading_hide(self):
450451
]
451452

452453
def data_load_variables(self):
454+
self.state.loading = True
453455
asynchronous.create_task(self._data_load_variables())
454456

455457
async def _data_load_variables(self):
456458
"""Called at 'Load Variables' button click"""
459+
t0 = time.perf_counter()
460+
# Give some room
461+
await asyncio.sleep(0.1)
462+
457463
vars_to_show = self.selected_variables
458464

459465
# Flatten the list of lists
@@ -477,17 +483,25 @@ async def _data_load_variables(self):
477483
# Trigger source update + compute avg
478484
with self.state:
479485
self.state.variables_loaded = True
486+
480487
await self.server.network_completion
481488

482489
# Update views in layout
483490
with self.state:
484491
self.view_manager.build_auto_layout(vars_to_show)
492+
485493
await self.server.network_completion
486494

487495
# Reset camera after yield
488496
await asyncio.sleep(0.1)
489497
self.view_manager.reset_camera()
490498

499+
# Done with the loading
500+
t1 = time.perf_counter()
501+
with self.state:
502+
self.state.loading = False
503+
self.state.loading_time = t1 - t0
504+
491505
@change("layout_grouped")
492506
def _on_layout_change(self, **_):
493507
vars_to_show = self.selected_variables

src/e3sm_quickview/components/drawers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def __init__(self, load_variables=None):
7474
style=(f"{js.is_active('select-fields')} ? 'transform: none;' : ''",),
7575
)
7676

77+
self.state.setdefault("loading_time", 0)
78+
7779
with self:
7880
with html.Div(
7981
style="position:fixed;top:0;width: 500px;height:100vh;",
@@ -85,12 +87,13 @@ def __init__(self, load_variables=None):
8587
color="primary",
8688
prepend_icon="mdi-database",
8789
text=(
88-
"`Load ${variables_selected.length} variable${variables_selected.length > 1 ? 's' :''}`",
90+
"`Load ${variables_selected.length} variable${variables_selected.length > 1 ? 's' :''} ${ loading_time ? ('(' + loading_time.toFixed(1) + ' s)') : ''}`",
8991
),
9092
variant="flat",
9193
disabled=(
92-
"variables_selected.length === 0 || variables_loaded",
94+
"variables_selected.length === 0 || variables_loaded || loading",
9395
),
96+
loading=("loading", False),
9497
click=load_variables,
9598
block=True,
9699
)

0 commit comments

Comments
 (0)