Salut,
Vous trouverez ci-joint du matériel que j'ai utilisé pour montrer comment chatGPT peut être utilisé pour créer du code JSL. Il y a 3 fichiers avec toutes les informations qu'il contient. Je l'inclus également dans cet article sous forme de boîtes de script. Certains peuvent le trouver utile.
La conclusion pour moi est que
- il fait déjà un travail assez décent dans la structure du code et pour des fonctionnalités simples
- il ne connaît pas les détails du codage JSL, comme le commutateur de colonnes, car il essaie de créer une fonction propre qui ne fonctionne pas
- il fait des erreurs surprenantes comme Numeric() au lieu de Num() dans le premier exemple
- Il y a probablement trop peu de code JSL pour en apprendre suffisamment, mais cela pourrait changer à l'avenir
(je ne savais pas si cela devait être mis à la bibliothèque car ce n'est pas vraiment une démo mais plutôt amusant)
Premier exemple :
/* 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();
Deuxième exemple :
/* 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();
Troisième exemple :
/* 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();