11import ipywidgets as widgets # type: ignore
2- from IPython .display import display # type: ignore
2+ from IPython .display import display # type: ignore
33import json # type: ignore
4- import os # type: ignore
4+ import os # type: ignore
55from .axtract_report import EquationExtractionResponse
66from .models import VariableRequirement
77
8- def _find_symbol (name , variable_dict ):
98
10- matching_keys = [
11- key for key , value in variable_dict .items () if name in value ["name" ]
12- ]
9+ def _find_symbol (name , variable_dict ):
10+ matching_keys = [key for key , value in variable_dict .items () if name in value ["name" ]]
1311
1412 if not matching_keys :
1513 matching_keys .append ("unknown" )
1614
1715 return matching_keys [0 ]
1816
19- def _requirements_from_table (results , variable_dict ):
20-
2117
18+ def _requirements_from_table (results , variable_dict ):
2219 requirements = []
2320
2421 for key , value in results ["values" ].items ():
@@ -36,6 +33,7 @@ def _requirements_from_table(results, variable_dict):
3633
3734 return requirements
3835
36+
3937def interactive_table (loaded_equations , file_path = "./custom_presets.json" ):
4038 """
4139 Creates an interactive table for IMAGING_TELESCOPE,
@@ -60,7 +58,7 @@ def interactive_table(loaded_equations, file_path="./custom_presets.json"):
6058 # ---------------------------------------------------------------
6159 IMAGING_TELESCOPE_template = {
6260 "Resolution (panchromatic)" : 0 ,
63- "Ground sampling distance (panchromatic)" :0 ,
61+ "Ground sampling distance (panchromatic)" : 0 ,
6462 "Resolution (multispectral)" : 0 ,
6563 "Ground sampling distance (multispectral)" : 0 ,
6664 "Altitude" : 0 ,
@@ -228,16 +226,8 @@ def display_table(change):
228226 default_value = PAYLOAD_1 .get (row_name , 0.0 )
229227 default_unit = IMAGING_TELESCOPE_UNITS .get (row_name , "" )
230228 elif selected_option in custom_presets :
231- default_value = (
232- custom_presets [selected_option ]
233- .get (row_name , {})
234- .get ("Value" , 0.0 )
235- )
236- default_unit = (
237- custom_presets [selected_option ]
238- .get (row_name , {})
239- .get ("Units" , "" )
240- )
229+ default_value = custom_presets [selected_option ].get (row_name , {}).get ("Value" , 0.0 )
230+ default_unit = custom_presets [selected_option ].get (row_name , {}).get ("Units" , "" )
241231 else :
242232 default_value = 0.0
243233 default_unit = ""
@@ -271,7 +261,7 @@ def display_table(change):
271261 # ---------------------------------------------------------------
272262 # Store the requirements to return later
273263 requirements_result = [None ] # Using a list to store mutable reference
274-
264+
275265 def submit_values (_ ):
276266 updated_values = {}
277267 for k , widget in value_widgets .items ():
@@ -282,19 +272,19 @@ def submit_values(_):
282272
283273 result ["values" ] = updated_values
284274 requirements_result [0 ] = _requirements_from_table (result , variable_dict )
285-
275+
286276 # Display a confirmation message
287277 with message_output :
288278 message_output .clear_output ()
289279 print ("Requirements submitted successfully!" )
290-
280+
291281 return requirements_result [0 ]
292282
293283 # ---------------------------------------------------------------
294284 # 8) add_req(): Adds a new, blank row to the bottom
295285 # ---------------------------------------------------------------
296286 def add_req (_ ):
297- unique_key = ( f"req_{ len ([kk for kk in value_widgets if kk .startswith ('req_' )]) + 1 } " )
287+ unique_key = f"req_{ len ([kk for kk in value_widgets if kk .startswith ('req_' )]) + 1 } "
298288
299289 variable_dropdown = widgets .Dropdown (
300290 options = variable_names ,
@@ -341,9 +331,7 @@ def delete_req(_):
341331 # - Also updates custom_presets + JSON file,
342332 # - So it persists across restarts.
343333 # ---------------------------------------------------------------
344- custom_count = len (
345- [k for k in preset_options_dict if k .startswith ("Custom-" )]
346- )
334+ custom_count = len ([k for k in preset_options_dict if k .startswith ("Custom-" )])
347335
348336 def save_requirements (_ ):
349337 nonlocal custom_count
@@ -376,26 +364,19 @@ def save_requirements(_):
376364 # ---------------------------------------------------------------
377365 # 11) Create & display the buttons
378366 # ---------------------------------------------------------------
379- submit_button = widgets .Button (
380- description = "Submit" , button_style = "success" )
367+ submit_button = widgets .Button (description = "Submit" , button_style = "success" )
381368 submit_button .on_click (submit_values )
382369
383- add_req_button = widgets .Button (
384- description = "Add Requirement" , button_style = "primary"
385- )
370+ add_req_button = widgets .Button (description = "Add Requirement" , button_style = "primary" )
386371 add_req_button .on_click (add_req )
387372
388- del_req_button = widgets .Button (
389- description = "Delete Requirement" , button_style = "danger"
390- )
373+ del_req_button = widgets .Button (description = "Delete Requirement" , button_style = "danger" )
391374 del_req_button .on_click (delete_req )
392375
393376 save_req_button = widgets .Button (description = "Save" , button_style = "info" )
394377 save_req_button .on_click (save_requirements )
395378
396- buttons_box = widgets .HBox (
397- [submit_button , add_req_button , del_req_button , save_req_button ]
398- )
379+ buttons_box = widgets .HBox ([submit_button , add_req_button , del_req_button , save_req_button ])
399380 display (buttons_box )
400381
401382 # Return the requirements object directly - it will be updated when submit is clicked
@@ -423,16 +404,12 @@ def _create_variable_dict(equation_response: EquationExtractionResponse) -> dict
423404 }
424405 """
425406 variable_dict = {}
426-
407+
427408 # Iterate through all equations and their symbols
428409 for equation in equation_response .equations :
429410 for symbol in equation .latex_symbols :
430411 # Only add if not already present (avoid duplicates)
431412 if symbol .key not in variable_dict :
432413 variable_dict [symbol .key ] = {"name" : symbol .value }
433-
434- return variable_dict
435-
436-
437-
438414
415+ return variable_dict
0 commit comments