Skip to content

Commit 46a328d

Browse files
committed
Merge branch 'jafranc/feat/trame-HPC-launcher' of https://github.com/GEOS-DEV/geosPythonPackages into jafranc/feat/trame-HPC-launcher
2 parents 4535890 + 3c26199 commit 46a328d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from enum import Enum, auto, unique
2+
3+
from trame_client.widgets.html import H3, Div
4+
from trame_server import Server
5+
from trame_vuetify.widgets.vuetify3 import VCard
6+
7+
@unique
8+
class SimulationStatus(Enum):
9+
SCHEDULED = auto()
10+
RUNNING = auto()
11+
COMPLETING = auto()
12+
COPY_BACK = auto()
13+
DONE = auto()
14+
NOT_RUN = auto()
15+
UNKNOWN = auto()
16+
17+
18+
class SimulationStatusView:
19+
"""
20+
Simple component containing simulation status in a VCard with some coloring depending on the status.
21+
"""
22+
23+
def __init__(self, server: Server):
24+
def state_name(state_str):
25+
return f"{type(self).__name__}_{state_str}_{id(self)}"
26+
27+
self._text_state = state_name("text")
28+
self._date_state = state_name("date")
29+
self._time_state = state_name("time")
30+
self._color_state = state_name("color")
31+
self._state = server.state
32+
33+
for s in [self._text_state, self._date_state, self._time_state, self._color_state]:
34+
self._state.client_only(s)
35+
36+
with VCard(
37+
classes="p-8",
38+
style=(f"`border: 4px solid ${{{self._color_state}}}; width: 300px; margin:auto; padding: 4px;`",),
39+
) as self.ui:
40+
H3(f"{{{{{self._text_state}}}}}", style="text-align:center;")
41+
Div(f"{{{{{self._date_state}}}}} {{{{{self._time_state}}}}}", style="text-align:center;")
42+
43+
self.set_status(SimulationStatus.NOT_RUN)
44+
self.set_time_stamp("")
45+
46+
def set_status(self, status: SimulationStatus):
47+
self._state[self._text_state] = status.name
48+
self._state[self._color_state] = self.status_color(status)
49+
self._state.flush()
50+
51+
def set_time_stamp(self, time_stamp: str):
52+
date, time = self.split_time_stamp(time_stamp)
53+
self._state[self._time_state] = time
54+
self._state[self._date_state] = date
55+
self._state.flush()
56+
57+
@staticmethod
58+
def split_time_stamp(time_stamp: str) -> tuple[str, str]:
59+
default_time_stamp = "", ""
60+
if not time_stamp:
61+
return default_time_stamp
62+
63+
time_stamp = time_stamp.split("_")
64+
if len(time_stamp) < 2:
65+
return default_time_stamp
66+
67+
return time_stamp[0].replace("-", "/"), time_stamp[1].split(".")[0].replace("-", ":")
68+
69+
@staticmethod
70+
def status_color(status: SimulationStatus) -> str:
71+
return {
72+
SimulationStatus.DONE: "#4CAF50",
73+
SimulationStatus.RUNNING: "#3F51B5",
74+
SimulationStatus.SCHEDULED: "#FFC107",
75+
SimulationStatus.COMPLETING: "#C5E1A5",
76+
SimulationStatus.COPY_BACK: "#C5E1A5",
77+
SimulationStatus.UNKNOWN: "#E53935",
78+
}.get(status, "#607D8B")

0 commit comments

Comments
 (0)