Hallo,
Im Anhang finden Sie einige Materialien, die ich verwendet habe, um zu zeigen, wie chatGPT zum Erstellen von JSL-Code verwendet werden kann. Es gibt 3 Dateien mit allen Informationen darin. Ich füge es auch als Skriptboxen in diesen Beitrag ein. Manche mögen es nützlich finden.
Fazit für mich ist das
- Es leistet hinsichtlich der Struktur des Codes und der einfachen Funktionalität bereits recht gute Arbeit
- Es kennt keine Details der JSL-Codierung, wie z. B. den Spaltenumschalter, da es versucht, eine eigene Funktion dafür zu erstellen, die nicht funktioniert
- es macht einige überraschende Fehler wie Numeric() statt Num() im ersten Beispiel
- Wahrscheinlich gibt es zu wenig JSL-Code, um genug zu lernen, aber das könnte sich in Zukunft ändern
(Ich war mir nicht sicher, ob dies in die Bibliothek gestellt werden sollte, da es nicht wirklich eine Demo ist, sondern eher Spaß macht)
Erstes Beispiel:
/* https://chat.openai.com/
https://chat.openai.com/share/8b5143ad-1221-4a65-8459-4006cec6ff13
Question asked:
---------------
Write me a JMP Scripting Language (JSL) program with a graphical user interface including a button to import "big class.jmp" sample data, a button with a function where the input will be multiplied by 3 and the result displayed in a text box in the gui.
Answer got:
-----------
Certainly! Here's an example of a JSL program with a graphical user interface (GUI) that includes a button to import "big class.jmp" sample data and another button that multiplies the input by 3 and displays the result in a text box:
This script defines a main function Main_GUI() that creates the graphical user interface. It includes a button labeled "Import Data" that, when clicked, imports the "big class.jmp" sample data. There is also an input box where you can enter a value, and a button labeled "Multiply by 3" that, when clicked, multiplies the input value by 3. The result is then displayed in a text box below the input box.
Note: Make sure to have the "big class.jmp" sample data file available in the $SAMPLE_DATA directory for the data import to work properly.
*/
// Define the main function to create the GUI
Main_GUI = Function({},
// Create the main window
main_window = New Window("JSL GUI Example",
H List Box(
// Create a button to import data
Button Box("Import Data", import_data),
// Create an input box and a button to calculate the result
H List Box(
Text Box("Enter a value: "),
input_box = Text Edit Box(""),
Button Box("Multiply by 3", multiply_by_3)
),
// Create a text box to display the result
result_box = Text Box("result")
)
);
// Function to handle importing data
import_data = Function({},
// Import the "big class.jmp" sample data
dt = Open("$SAMPLE_DATA/Big Class.jmp");
);
// Function to handle multiplying by 3
multiply_by_3 = Function({},
// Get the input value
input_value = input_box << Get Text;
// Check if the input value is a valid number
// Start wrong code
If(Numeric(input_value),
// Corrected:
//If(Num(input_value),
// Multiply the input by 3
result = Parse(input_value) * 3;
// Display the result in the result box
result_box << Set Text(Char(result));
);
);
// Show the main window
main_window << Show;
);
// Call the main function to start the GUI
Main_GUI();
Zweites Beispiel:
/* https://chat.openai.com/
https://chat.openai.com/share/8b5143ad-1221-4a65-8459-4006cec6ff13
Question asked:
---------------
Write me a JMP Scripting Language (JSL) program with a graphical user interface including a button to import "big class.jmp" sample data, a button with a function where I can select a numeric column, calculate the mean of that column grouped by the column "sex". The result should be displayed in the "graph builder" platform as a bar chart with the result value on Y axis and column "sex "on X axis
Answer got:
-----------
Certainly! Here's an example of a JSL program with a graphical user interface (GUI) that includes a button to import "big class.jmp" sample data. It also includes a button that allows you to select a numeric column, calculates the mean of that column grouped by the "sex" column, and displays the result in the "Graph Builder" platform as a bar chart:
This script defines a main function Main_GUI() that creates the graphical user interface. It includes a button labeled "Import Data" that, when clicked, imports the "big class.jmp" sample data. There is also a button labeled "Calculate Mean" that, when clicked, allows you to select a numeric column from the imported data table. It then calculates the mean of that column grouped by the "sex" column.
The result is displayed in the "Graph Builder" platform as a bar chart, where the mean values are shown on the Y-axis and the "sex" column is displayed on the X-axis.
Note: Make sure to have the "big class.jmp" sample data file available in the $SAMPLE_DATA directory for the data import to work properly.
*/
// Define the main function to create the GUI
Main_GUI = Function({},
// Create the main window
main_window = New Window("JSL GUI Example",
H List Box(
// Create a button to import data
Button Box("Import Data", import_data),
// Create a button to calculate the mean
Button Box("Calculate Mean", calculate_mean)
)
);
// Function to handle importing data
import_data = Function({},
// Import the "big class.jmp" sample data
dt = Open("$SAMPLE_DATA/Big Class.jmp");
);
// Function to handle calculating the mean and displaying the bar chart
calculate_mean = Function({},
// Check if the data table is available
//*********************
// Start Wrong Code:
// /*
If(NItems(dt) > 0,
// */
//*********************
//*********************
// Correction:
// If(!is empty(dt),
//*********************
//*********************
// Start Wrong Code:
// /*
// Select the numeric column
column = Column(dt << Get Column Name Dialog("Select a numeric column"));
// */
//*********************
//*********************
// Possible Correction:
/*
column = dt << Get Column Names(Continuous);
*/
// but then there still more issues with the following
// scripts to be adjusted, better another try with Chat GPT!
//*********************
// Check if a column was selected
If(column != "",
// Calculate the mean grouped by the "sex" column
summary_table = dt << Summary(
Group By(:sex),
Mean(column)
);
// Create the graph builder platform and display the bar chart
gb = dt << Graph Builder(
Variables(X(:sex), Y(:Mean)),
Elements(
Bar(X, Y, Legend(2))
)
);
)
)
);
// Show the main window
main_window << Show;
);
// Call the main function to start the GUI
Main_GUI();
Drittes Beispiel:
/* https://chat.openai.com/
https://chat.openai.com/share/8b5143ad-1221-4a65-8459-4006cec6ff13
Question asked:
---------------
Write me a JMP Scripting Language (JSL) program with a graphical user interface including a button to import "big class.jmp" sample data,
a button with a function where I get the column names of all numeric columns, open "graph builder" platform, Put the column "sex" on the x axis, and the first numeric column on the y axis,
change to a bar chart and set "median" as statistics. Use the Graph Builder option "Column Switcher" to switch the first numeric column with all other numeric columns.
Answer got:
-----------
This updated script adds the "Column Switcher" option to the GUI. It allows you to switch between the first numeric column and all other numeric columns. The program still includes a button to import the "big class.jmp" sample data and another button to display a bar chart with the median values. The X-axis represents the "sex" column, and the Y-axis initially uses the first numeric column. The "Column Switcher" event handler updates the Y column in the Graph Builder platform when a new column is selected, ensuring that the bar chart reflects the chosen numeric column.
Note: Make sure to have the "big class.jmp" sample data file available in the $SAMPLE_DATA directory for the data import to work properly.
*/
// Define the main function to create the GUI
Main_GUI = Function({},
// Create the main window
main_window = New Window("JSL GUI Example",
H List Box(
// Create a button to import data
Button Box("Import Data", import_data),
// Create a button to display the bar chart
Button Box("Display Bar Chart", display_bar_chart),
/* // Create a column switcher to switch the Y column
y_column_switcher = Column Switcher(
<< Get Column List(Dialog Numeric),
<< Set Selected(1)
)*/
)
);
/* // Declare global variables
global dt;
global gb;
*/
// Function to handle importing data
import_data = Function({},
// Import the "big class.jmp" sample data
dt = Open("$SAMPLE_DATA/Big Class.jmp");
);
// Function to get the column names of numeric columns
get_numeric_column_names = Function({},
// Get the column names of numeric columns
numeric_columns = dt << Get Column Names(Numeric, "String");
Return(numeric_columns);
);
// Function to display the bar chart
display_bar_chart = Function({},
// Check if the data table is available
//*********************
// Start Wrong Code:
// /*
If(NItems(dt) > 0,
// */
//*********************
//*********************
// Correction:
// If(!is empty(dt),
//*********************
// Get the column names of numeric columns
numeric_columns = get_numeric_column_names();
// Check if there are numeric columns available
If(NItems(numeric_columns) > 0,
//*********************
// Start Wrong Code:
// /*
// Open the Graph Builder platform
gb = dt << Graph Builder(
Show Control Panel(false),
Variables(
X(:sex),
Y(Column(dt, numeric_columns[1]))
),
Elements(
Bar( X, Y, Legend(2), Summary Statistic("Median") )
)
);
// Set the column switcher's column list
y_column_switcher << Set Column List(numeric_columns);
// Event handler for the Y column switcher
y_column_switcher << On Column Switch(
Function({},
// Get the selected column name
selected_column = y_column_switcher << Get Selected;
// Update the Y column in the Graph Builder platform
gb << Variables(Y(Column(dt, selected_column)));
// Update the chart type to bar chart with median values
gb << Update Types(
Bar( X, Y, Legend(2), Summary Statistic("Median") )
);
)
);
// */
//*********************
//*********************
// Correction:
/*
// Open the Graph Builder platform
gb = dt << Graph Builder(
Show Control Panel(false),
Variables(
X(:sex),
Y(Column(dt, numeric_columns[1]))
),
Elements(
Bar( X, Y, Legend(2), Summary Statistic("Median") )
),
Column Switcher( numeric_columns[1], {:age, :height, :weight} )
)
*/
//*********************
)
)
);
// Show the main window
main_window << Show;
);
// Call the main function to start the GUI
Main_GUI();