sda.dashboard.script_generator#
Python Script Generator.
Generates equivalent Python scripts that reproduce the current dashboard state, including data loading, filtering, and plotting operations.
This enables users to download Python code that recreates their analysis outside of the dashboard environment.
DEVELOPER TIP:#
The script generator should be minimal and only show what the pipeline decided. - Only generate filtering code when filters are actually needed - Move if/else logic to code generation time, not in the generated code - Don’t duplicate pipeline logic - just show the results - The generated script should be clean and readable - NO CONDITIONAL LOGIC in the generated script - all decisions happen at code generation time - At script generation time, you have all information to generate the right code conditionally
Attributes#
Classes#
Generates Python scripts that reproduce dashboard operations. |
Functions#
Get the plot format from user configuration. |
Module Contents#
- sda.dashboard.script_generator.BASE_SCRIPT_TEMPLATE = Multiline-String#
Show Value
""" """ SDA Dashboard - Generated Python Script Timestamp: {timestamp} Test(s): {test_name} Plot Format: {script_plot_format} This script reproduces the current dashboard analysis state following the 4-step pipeline: 1. Data Load (Test Selection) - Load raw test data 2. Column Filtering (Test Selection) - Select specific columns 3. Row Filtering (Filter Side pane) - Apply filters 4. Plot (Scatter/Line) - Create visualizations Usage: 1. Ensure you have the required packages installed 2. Run this script in your Python environment 3. The script will load data and create plots Requirements: - sda library (for data loading) - pandas (for data manipulation) - {script_plot_format_lower} (for plotting) """ # %% Imports # ----------------------------------------- {imports} # %% Step 1: Data Load (Test Selection) # ----------------------------------------- {data_loading} # %% Step 2: Column filtering (Test Selection) # ----------------------------------------- {column_selection} # %% Step 3: Row filtering (Filter Side pane) # ----------------------------------------- {filtering} # %% Step 4: Plot (Scatter/Line) # ----------------------------------------- {plotting} # %% Additional Analysis # ----------------------------------------- # Additional analysis can be added here # For example: # - Statistical analysis: df.describe() # - Export data: df.to_csv('exported_data.csv') # - Custom plots: create your own visualizations print("\nScript execution completed!") print(f"Final dataset shape: {{df.shape}}") """
- class sda.dashboard.script_generator.PythonScriptGenerator(script_plot_format='plotly')#
Generates Python scripts that reproduce dashboard operations.
This class maintains the current state of the dashboard and generates equivalent Python code for data loading, filtering, and plotting.
- script_plot_format = ''#
- reset_state()#
Reset the generator state to initial values.
- update_test(test_name)#
Update the current test selection.
- update_columns(columns)#
Update the selected columns.
- update_filters(filters)#
Update the active filters.
- update_filter_options(filter_options)#
Update the available filter options for each column.
- update_plot_config(plot_type, config)#
Update the plot configuration.
- generate_from_pipeline_state(pipeline_state, filter_options=None)#
Generate script from a pipeline state object.
- Parameters:
pipeline_state (
PipelineState) – Pipeline state containing all necessary informationfilter_options (
Dict[str,List[Any]], optional) – Available filter options for each column
- generate_script()#
Generate a complete Python script that reproduces the current state.
- Returns:
Complete Python script as a string
- Return type:
- get_state_summary()#
Get a summary of the current generator state.
- Returns:
Dictionary containing the current state
- Return type:
Dict[str,Any]
- sda.dashboard.script_generator.get_script_plot_format_from_config()#
Get the plot format from user configuration.
- Returns:
Plot format to use (“plotly” or “matplotlib”)
- Return type:
Notes
Reads from ~/sda.json under the DASHBOARD.script_plot_format key. Falls back to “plotly” if configuration is missing or invalid.
- sda.dashboard.script_generator.script_generator#