-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilize shared state in dashboard (#834)
* Use shared state for input parameters section * Only call state change when input is string Since the state change converts the input value from a string to a numeric, we do not want the input value to be read in numerous times. * Update docstring for custom text_field * include csr to shared state can't include others (distribution parameters/lattice config/space charge because either their states are nested by dictionary use or they use different validation errors. In the future, it would be good to have a single validation function than multiple separate ones. * move shared state logic to new shared.py * remove print statement * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b7a99e7
commit d8a963c
Showing
5 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from .. import setup_server | ||
from ..Input.inputParameters.inputMain import InputParameters | ||
from . import DashboardDefaults, generalFunctions | ||
|
||
server, state, ctrl = setup_server() | ||
|
||
|
||
input_parameters_defaults = list(DashboardDefaults.INPUT_PARAMETERS.keys()) | ||
space_charge_defaults = list(DashboardDefaults.CSR.keys()) | ||
INPUT_DEFAULTS = input_parameters_defaults + space_charge_defaults | ||
|
||
|
||
class SharedUtilities: | ||
@staticmethod | ||
@state.change(*INPUT_DEFAULTS) | ||
def on_input_state_change(**_): | ||
state_changes = state.modified_keys & set(INPUT_DEFAULTS) | ||
for state_name in state_changes: | ||
if type(state[state_name]) is str: | ||
value = getattr(state, state_name) | ||
desired_type = DashboardDefaults.TYPES.get(state_name, None) | ||
validation_name = f"{state_name}_error_message" | ||
conditions = DashboardDefaults.VALIDATION_CONDITION.get( | ||
state_name, None | ||
) | ||
|
||
validation_result = generalFunctions.validate_against( | ||
value, desired_type, conditions | ||
) | ||
setattr(state, validation_name, validation_result) | ||
generalFunctions.update_simulation_validation_status() | ||
|
||
if validation_result == []: | ||
converted_value = generalFunctions.convert_to_correct_type( | ||
value, desired_type | ||
) | ||
|
||
if getattr(state, state_name) != converted_value: | ||
setattr(state, state_name, converted_value) | ||
if state_name == "kin_energy_on_ui": | ||
InputParameters.on_kin_energy_unit_change() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters