From 7daf6e8f50563c44fcdb958085e693a20d6743e3 Mon Sep 17 00:00:00 2001 From: Parthib Roy Date: Sat, 4 Jan 2025 17:13:05 -0800 Subject: [PATCH] rename lattice element default variables to snake case --- .../impactx/dashboard/Input/defaults.py | 4 +- .../dashboard/Input/generalFunctions.py | 6 +- .../Input/latticeConfiguration/latticeMain.py | 74 +++++++++---------- .../dashboard/Toolbar/exportTemplate.py | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/python/impactx/dashboard/Input/defaults.py b/src/python/impactx/dashboard/Input/defaults.py index b186e5106..0c8baa744 100644 --- a/src/python/impactx/dashboard/Input/defaults.py +++ b/src/python/impactx/dashboard/Input/defaults.py @@ -28,8 +28,8 @@ class DashboardDefaults: } LATTICE = { - "selectedLatticeList": [], - "selectedLattice": None, + "selected_lattice": None, + "selected_lattice_list": [], } SPACE_CHARGE = { diff --git a/src/python/impactx/dashboard/Input/generalFunctions.py b/src/python/impactx/dashboard/Input/generalFunctions.py index c9ab49137..bb48f79f3 100644 --- a/src/python/impactx/dashboard/Input/generalFunctions.py +++ b/src/python/impactx/dashboard/Input/generalFunctions.py @@ -146,7 +146,7 @@ def update_simulation_validation_status(): ) # Check for errors in lattice parameters - for lattice in state.selectedLatticeList: + for lattice in state.selected_lattice_list: for param in lattice["parameters"]: if param["parameter_error_message"]: error_details.append( @@ -165,7 +165,7 @@ def update_simulation_validation_status(): if state.mass_MeV_validation: error_details.append(f"Ref. Particle Mass: {state.mass_MeV}") - if state.selectedLatticeList == []: + if state.selected_lattice_list == []: error_details.append("LatticeListIsEmpty") # Check for errors in CSR parameters @@ -360,7 +360,7 @@ def reset_lattice_configuration_parameters(): Resets lattice inputs to defaults. """ state.update(DashboardDefaults.LATTICE) - state.selectedLatticeList = [] + state.selected_lattice_list = [] @staticmethod def reset_space_charge_parameters(): diff --git a/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py b/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py index 8bb3bc775..0ade7d21b 100644 --- a/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py +++ b/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py @@ -33,10 +33,10 @@ # Default # ----------------------------------------------------------------------------- -state.selectedLattice = generalFunctions.get_default( - "selectedLattice", "default_values" +state.selected_lattice = generalFunctions.get_default( + "selected_lattice", "default_values" ) -state.selectedLatticeList = [] +state.selected_lattice_list = [] state.nsliceDefaultValue = generalFunctions.get_default("n_slice", "default_values") # ----------------------------------------------------------------------------- @@ -51,13 +51,13 @@ def add_lattice_element(): :return: dictionary representing the added lattice element with its parameters. """ - selectedLattice = state.selectedLattice - selectedLatticeParameters = state.listOfLatticeElementParametersAndDefault.get( - selectedLattice, [] + selected_lattice = state.selected_lattice + selected_lattice_parameters = state.listOfLatticeElementParametersAndDefault.get( + selected_lattice, [] ) - selectedLatticeElement = { - "name": selectedLattice, + selected_lattice_element = { + "name": selected_lattice, "parameters": [ { "parameter_name": parameter[0], @@ -67,13 +67,13 @@ def add_lattice_element(): parameter[1], parameter[2] ), } - for parameter in selectedLatticeParameters + for parameter in selected_lattice_parameters ], } - state.selectedLatticeList.append(selectedLatticeElement) + state.selected_lattice_list.append(selected_lattice_element) generalFunctions.update_simulation_validation_status() - return selectedLatticeElement + return selected_lattice_element def update_latticeElement_parameters( @@ -83,13 +83,13 @@ def update_latticeElement_parameters( Updates parameter value and includes error message if user input is not valid """ - for param in state.selectedLatticeList[index]["parameters"]: + for param in state.selected_lattice_list[index]["parameters"]: if param["parameter_name"] == parameterName: param["parameter_default_value"] = parameterValue param["parameter_error_message"] = parameterErrorMessage generalFunctions.update_simulation_validation_status() - state.dirty("selectedLatticeList") + state.dirty("selected_lattice_list") # ----------------------------------------------------------------------------- @@ -127,7 +127,7 @@ def lattice_elements(): """ elements_list = [] - for latticeElement in state.selectedLatticeList: + for latticeElement in state.selected_lattice_list: latticeElement_name = latticeElement["name"] parameters = parameter_input_checker_for_lattice(latticeElement) @@ -142,31 +142,31 @@ def lattice_elements(): # ----------------------------------------------------------------------------- -@state.change("selectedLatticeList") -def on_selectedLatticeList_change(selectedLatticeList, **kwargs): - if selectedLatticeList == []: +@state.change("selected_lattice_list") +def on_selected_lattice_list_change(selected_lattice_list, **kwargs): + if selected_lattice_list == []: state.isSelectedLatticeListEmpty = "Please select a lattice element" generalFunctions.update_simulation_validation_status() else: state.isSelectedLatticeListEmpty = "" -@state.change("selectedLattice") -def on_lattice_element_name_change(selectedLattice, **kwargs): +@state.change("selected_lattice") +def on_lattice_element_name_change(selected_lattice, **kwargs): return @ctrl.add("add_latticeElement") def on_add_lattice_element_click(): - selectedLattice = state.selectedLattice + selected_lattice = state.selected_lattice - if selectedLattice not in state.listOfLatticeElements: + if selected_lattice not in state.listOfLatticeElements: state.isSelectedLatticeListEmpty = ( - f"Lattice element '{selectedLattice}' does not exist." + f"Lattice element '{selected_lattice}' does not exist." ) else: add_lattice_element() - state.dirty("selectedLatticeList") + state.dirty("selected_lattice_list") @ctrl.add("updateLatticeElementParameters") @@ -183,28 +183,28 @@ def on_lattice_element_parameter_change( @ctrl.add("deleteLatticeElement") def on_delete_LatticeElement_click(index): - state.selectedLatticeList.pop(index) - state.dirty("selectedLatticeList") + state.selected_lattice_list.pop(index) + state.dirty("selected_lattice_list") @ctrl.add("move_latticeElementIndex_up") def on_move_latticeElementIndex_up_click(index): if index > 0: - state.selectedLatticeList[index], state.selectedLatticeList[index - 1] = ( - state.selectedLatticeList[index - 1], - state.selectedLatticeList[index], + state.selected_lattice_list[index], state.selected_lattice_list[index - 1] = ( + state.selected_lattice_list[index - 1], + state.selected_lattice_list[index], ) - state.dirty("selectedLatticeList") + state.dirty("selected_lattice_list") @ctrl.add("move_latticeElementIndex_down") def on_move_latticeElementIndex_down_click(index): - if index < len(state.selectedLatticeList) - 1: - state.selectedLatticeList[index], state.selectedLatticeList[index + 1] = ( - state.selectedLatticeList[index + 1], - state.selectedLatticeList[index], + if index < len(state.selected_lattice_list) - 1: + state.selected_lattice_list[index], state.selected_lattice_list[index + 1] = ( + state.selected_lattice_list[index + 1], + state.selected_lattice_list[index], ) - state.dirty("selectedLatticeList") + state.dirty("selected_lattice_list") @ctrl.add("nsliceDefaultChange") @@ -259,7 +259,7 @@ def card(): with vuetify.VCol(cols=10): vuetify.VCombobox( label="Select Accelerator Lattice", - v_model=("selectedLattice", None), + v_model=("selected_lattice", None), items=("listOfLatticeElements",), error_messages=("isSelectedLatticeListEmpty",), dense=True, @@ -295,7 +295,7 @@ def card(): vuetify.VDivider() with vuetify.VContainer(fluid=True): with vuetify.VRow( - v_for="(latticeElement, index) in selectedLatticeList", + v_for="(latticeElement, index) in selected_lattice_list", align="center", no_gutters=True, style="min-width: 1500px;", @@ -362,7 +362,7 @@ def dialog_lattice_elementList(): vuetify.VDivider() with vuetify.VContainer(fluid=True): with vuetify.VRow( - v_for="(latticeElement, index) in selectedLatticeList", + v_for="(latticeElement, index) in selected_lattice_list", align="center", no_gutters=True, style="min-width: 1500px;", diff --git a/src/python/impactx/dashboard/Toolbar/exportTemplate.py b/src/python/impactx/dashboard/Toolbar/exportTemplate.py index 10cd187de..c01b53e82 100644 --- a/src/python/impactx/dashboard/Toolbar/exportTemplate.py +++ b/src/python/impactx/dashboard/Toolbar/exportTemplate.py @@ -51,7 +51,7 @@ def build_lattice_list(): for key, value in parameter_input_checker_for_lattice(element).items() ) + ")" - for element in state.selectedLatticeList + for element in state.selected_lattice_list ) return f"lattice_configuration = [\n {lattice_elements}\n]"