JMP 14中有幾個新功能,其中許多功能擴展或改進了JSL的可用性。在這篇博客中,我將僅介紹JSL和Scripting Index的一些新功能。
HTTP請求
您是否擁有支持REST API訪問數據的數據源?您想要與公共REST API服務(例如Twitter或Google API)進行交互嗎?現在,在JMP 14中,您可以使用New HTTP Request()函數本機訪問這些API。
以下是從腳本索引中獲取的一個小示例,它使用公共API服務來測試POST請求。
Names Default To Here( 1 );
request = New HTTP Request(
url( "http://httpbin.org/post" ),
Method( "POST" ),
JSON( "\[{"username":"bob","address":"12345"}]\" )
);
data = request << Send();
將數據變量中的字符串結果保存到JSON文件後,您可以在新的JSON語法中突出顯示腳本編輯器中的結果。一旦確定瞭如何處理此JSON響應,您還可以使用任意數量的JSON處理函數,例如Parse JSON,JSON to List或JSON to Data Table。
Python集成
您是否曾想從一個JMP應用程序中利用Python的強大功能?通過JMP 14的Python集成,它現在比以往更容易。
下面是一個示例,使用matplotlib Python包創建一個權重與高度的散點圖,按年齡著色。
NamesDefaultToHere( 1 );
// Establish connection to Python
PythonConnection = PythonConnect();
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Send the data table to Python as a dataframe
PythonConnection << Send( dt );
Close( dt, NoSave ); // close the JMP data table
// Submit python program that uses our data table (dataframe in python)
ml = PythonConnection << Submit(
"\[
import matplotlib.pyplot as plt
plt.scatter(dt.weight, dt.height, c=dt.age)
plt.ylabel('Height')
plt.xlabel('Weight')
plt.title('Weight vs. Height for Big Class')
plt.show(block=False)
]\"
);
// Get the graphics added by 'plt.show(...)'
plot = PythonConnection << Get Graphics( png );
// Show the graphic in a new window
pngJMP = NewWindow( "Plot", PictureBox( plot ) );
// close the plot
PythonConnection << Submit( "plt.close()" );
// disconnect from python
PythonConnection << Disconnect;

類
如果您是具有面向對象背景的JSL程序員,或者您想在高級應用程序中嘗試新事物,那麼您可能會對定義類的新功能感興趣。類與命名空間類似,但您可以擁有多個實例,稱為對象。這允許您創建多個實例,例如一組顯示框,每個顯示框都有自己的行為。
類中的這些行為是使用所謂的方法完成的。方法與當前稱為函數的方法非常相似,除了方法只能存在於類中。
這是一個簡單的計算器的例子,可以多次添加到窗口,而不會踩到彼此的腳趾。
// Define the class so we can create instances of it later
Define Class(
"Calculator",
// Define member variables
content = Empty();
num1_neb = Empty();
num2_neb = Empty();
operand_cmb = Empty();
calc_btn = Empty();
result_neb = Empty();
// _init_ is special method called when a new object is created
_init_ = Method( {},
content = H List Box(
num1_neb = Number Edit Box( 0 ),
operand_cmb = Combo Box( {"+", "- "} ),
num2_neb = Number Edit Box( 0 ),
calc_btn = Button Box( "=",
calc( operand_cmb << Get Selected(), num1_neb << Get(), num2_neb << Get() );
),
result_neb = Number Edit Box()
);
initializeValues();
);
// called from the _init_ method
initializeValues = Method( {},
num1_neb << Set( Random Integer( 10 ) );
num2_neb << Set( Random Integer( 10 ) );
);
// called when '=' button is clicked
calc = Method( {operand, n1, n2},
result = If( operand == "+",
addition( n1, n2 ),
subtraction( n1, n2 )
);
result_neb << set( result );
);
// methods called by calc
addition = Method( {n1, n2},
Return( n1 + n2 )
);
subtraction = Method( {n1, n2},
Return( n1 - n2 )
);
);
// Create multiple instances of the Calculator class
c1 = New Object( Calculator );
c2 = New Object( Calculator );
c3 = New Object( Calculator );
// Create a new window with the content of the three instances of Calculator
New Window( "Example", c1:content, c2:content, c3:content );

將JMP項目用作IDE
通過JMP 14項目,您可以輕鬆創建腳本的選項卡視圖,其中包含集成的日誌和書籤。這可以在一個地方為加載項或項目提供所有腳本的出色工作流管理。有關利用新JMP項目功能的更多示例,請查看博客與JMP 14保持聯繫 。

我希望您在JSL for JMP 14中享受所有這些新功能。有關JSL的更多改進,請查看“新功能”文檔的“腳本”部分,該部分可通過“幫助”>“新功能”獲得。