更新 JMP 數據表<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />我有一個 Excel 表格,每周用來更新 JMP 數據表 2-3 次。但是,檢索 Excel 文件後,當我使用 Tables 平台執行更新時,源腳本會發生更改。源腳本更改為表更新平台中完成的步驟。為什麼會發生這種情況?我是不是少了一步?
回复:更新 JMP 數據表我解決了循環的問題,以自動執行從列表中提取腳本名稱的過程,現在它將動態創建更新的表並將原始表中包含的任何腳本移動到新表中。
我已經評論了最終版本,並且如果其他人需要使用此解決方案,則將其包含在下面。
感謝你的幫助。
戴夫
//
// The purpose of this script is to create an updated JMP data table based on the same source
// data file used to create the JMP data table currently open.
//
// This script is used when you have created a JMP data table from a source data file that is
// updated over time and will continue to "grow" with new data as time progresses. Examples of
// this type of file is a monthly time accounting record or a periodic production report.
//
// This script is focused on source data that is "added to" as time progresses and is not intended
// for source data that contains only data for the given period with no historical data retained.
//
// The script utilzes the original "Open" command found within the "Source" script of the JMP data table
// and then copies over all of the scripts from the original data table into the new "updated" data table.
dtCurrent = Current Data Table();
// copy the Open command from the "Source" script of the main data table
// this is only required once as long as the name and location of the source data file remains unchanged
dtUpdate = Open(
"Z:\JMP Data Analysis\SLOC Metrics\Data Update Testing\Project_Metrics.xlsx",
Worksheets( "Code_Change_Metrics" ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
// end of the Open command from the "Source" script of the main data table
// don't forget to add the semicolon after the closing ")" above since we are added more commands below
// Get the list of scripts that are contained within the main data table
lstScriptNames = dtCurrent << Get Table Script Names;
// Loop through all the script names and move them to the updated dat table
For( i = 1, i <= N Items( lstScriptNames ), i++,
// pull each script name from the list of scripts
scriptName = lstScriptNames[ i ];
// By opening the updated data file with the copied Open command, we already created the "Source" script
IF(scriptName != "Source",
// Get the "contents" of this script from the main data table
scriptDef = dtCurrent << get table variable( scriptName );
// Insert this script into the updated data table
Eval(
Parse(
Eval Insert( "dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )" )
) // end Parse statement
); // end Eval statement
) // end IF statement
); // continue For Loop until all scripts in the main data table have been copied
// At the completion of this script, you will have two data tables open with exactly the same name.
//
// The first table is the "main" table that contains the old data and all the source scripts.
// When you attempt to close this table you will NOT be prompted to "save" the table since we made
// no changes to it. The "main" table must be closed prior to closing and saving the "updated" table since
// we are going to save the "updated" table in the same location with the same name as the original "main"
// table since we are "replacing" the old table with the update version.
//
// The second table is the "updated" table which we created with the above script.
// This table has been loaded with the "updated" data file found in the "Source" script. It now also
// contains all of the scripts that were contained in the "main" data table for continued use with the
// updated source data. You will note that is has exactly the same table name as the "main" table, but if you
// inspect the rows of data you will find the only difference between the two table is that the "updated" table
// contains the additional rows of data from the updated source data file.
//
// The objective is to close the "main" table which should not prompt for a save, then close the "updated" table
// save it at the prompt over the original "main" table. When closing the "updated" table, you do have the option
// save it to any location you desire with any name you desire. My goal for creating this script was to replace
// the original table with the updated table.
//
// I will note here that I assumed I could not add the close of the main table and the save
// of the updated table to this script since by closing the main table (which must be done first)
// I would be closing the table in which this executing script is located. As such I assume the close action
// would stop the script.回复:更新 JMP 數據表好的,
感謝您的快速回复。 我的問題與您提供的示例中的概念略有不同,但您給了我顯著前進所需的洞察力。
在上面的解決方案中,我現在可以將新數據文件的完整內容添加到舊數據文件中,但是,我的問題與“移動”到更新數據的字母版本有關,因為我的新文件僅具有超出的其他數據行首先。 這不是連接/關聯兩個單獨數據集的問題。
您的示例確實讓我了解到,當我在原始表中執行“源”腳本(實際上指向與原始數據同名和位置的新/更新的源數據文件)時,我得到一個新的數據表僅存在“源”腳本。 當我現在有了一個新表,其中包含所需的當前/更新數據,但沒有其他腳本時,我迷失了。
在您的示例中,您通過“現在將腳本從舊表複製到新表”結束了數據合併。
燈泡瞬間……你能做到嗎?
因此,在搜索論壇時,我發現了一些在一個表中列出腳本並將它們插入到另一個表中的示例。 在某些時候,我將弄清楚如何鏈接到其他討論,以便我能夠指向諸如此類的參考資料,但現在,這裡是示例中的代碼:
對於單個腳本:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
scriptName = "Oneway";
scriptDef = dt << get table variable( scriptName );
dt2 = New Table( "little class" );
Eval(
Parse(
Eval Insert(
"
dt2 << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
對於表中的所有腳本:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = New Table( "little class" );
Wait( 3 );
lstScriptNames = dt << Get Table Script Names;
Wait( 3 );
j = N Items( lstScriptNames );
For( i = 1, i <= N Items( lstScriptNames ), i++,
// scriptName = lstScriptNames;
scriptName = lstScriptNames( i );
scriptDef = dt << get table variable( scriptName );
Eval(
Parse(
Eval Insert( "dt2 << New Script( \!"^scriptName^\!", ^scriptDef^ )" )
)
);
);
現在 - 我製作了“源”腳本的副本,將表的分配添加到 dt 變量,然後嘗試使用循環遵循 open 命令來複製所有腳本。 我無法正確加載 scriptName 和 scriptDef 值。 scriptName 似乎加載了當前表中正確的腳本列表,但 scriptDef 調用不會提取定義。
因此,我通過重複的手動單個副本手動添加了每個測試腳本,效果非常好。 這是我的結果代碼:
dtCurrent = Current Data Table();
dtUpdate = Open(
"Z:\JMP Data Analysis\SLOC Metrics\Data Update Testing\Project_Metrics.xlsx",
Worksheets( "Code_Change_Metrics" ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
scriptName = "Mod vs Unmod Code Change Sample";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "Individual & Moving Range chart of % Code Change";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "Total Lines vs. Asset / Code Analyzed";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "% Code Change vs. Asset / Code Analyzed";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "UpdateDataTable";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "TestingTableUpdateScript";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "CopySingleScriptFromOldTable";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
scriptName = "CopyAllScriptsFromOldTable";
scriptDef = dtCurrent << get table variable( scriptName );
Eval(
Parse(
Eval Insert(
"
dtUpdate << New Script( \!"^scriptName^\!", ^scriptDef^ )
"
)
)
);
打開原始 JMP 表文件(使用源數據文件的最新版本創建)後,我現在可以執行此腳本,該腳本從更新的源數據文件創建一個新表,然後將所有腳本複製到新表。 然後,我打開兩個 JMP 表,兩個表都具有相同的標題,都具有相同的腳本,但一張包含舊數據,一張包含新數據(更多數據)。 現在,我關閉舊表,並將新表保存在其上方的同一位置。
繁榮! 使用所有可供執行的腳本更新了數據。 相同的文件位置和名稱,因此可以根據需要在每週或每月的報告更新中重複該過程。
我真的很想獲得自動循環來動態加載所有腳本,這樣我就可以在其他數據集上使用相同的腳本,而不必在實際代碼中管理腳本名稱。 目前,我正在繼續使用手動版本,直到找出循環問題為止。
非常感謝您的快速回復和示例,這最終引導我找到了解決方案。
回复:更新 JMP 數據表由於您有 JMP 13,您也可以這樣做:
NamesDefaultToHere(1);
// Make some 'new data' (imported from Excel)
dt2 = New Table( "New Data",
Add Rows( 10 ),
New Column( "x",
Numeric,
"Continuous",
Formula( Random Normal() )
),
New Column( "y",
Numeric,
"Continuous",
Formula( Random Integer(10, 20 ) )
)
);
dt2 << runFormulas;
Column(dt2, "x") << deleteFormula;
Column(dt2, "y") << deleteFormula;
// Make some 'old data' containing a saved script (stored as a JMP table)
dt1 = New Table( "Old Data",
Add Rows( 20 ),
New Script(
"y vs. x",
Graph Builder(
Variables( X( :x ), Y( :y ) ),
Elements( Points( X, Y, Legend( 5 ) ), Smoother( X, Y, Legend( 6 ) ) )
)
),
New Column( "x",
Numeric,
"Continuous",
Formula( Random Normal() )
),
New Column( "y",
Numeric,
"Continuous",
Formula( Random Integer(1, 10 ) )
)
);
dt1 << runFormulas;
Column(dt1, "x") << deleteFormula;
Column(dt1, "y") << deleteFormula;
// Update dt1 from dt2 using data table subscripting (requires JMP 13 or later)
Wait(3);
firstNewRow = NRows(dt1) + 1;
dt1 << addRows(NRows(dt2));
dt1[firstNewRow::NRow(dt1), 0] = dt2[0, 0];
回复:更新 JMP 數據表戴夫,
根據您的具體需求,更新平台可能是解決方案。 然而,JSL 將允許您執行幾乎任何您需要的操作,然後最終在您修改後的數據表中得到這些原始腳本。 這將是一段相當簡單的代碼,它將嵌入的腳本從原始表複製到新形成的表中。
回复:更新 JMP 數據表我發現這是一個舊線程,但它似乎是我能找到的與我遇到的問題相關的唯一線程。
我是一個新的 JMP 使用者,擁有 13.1。在學習如何使用 JMP 時,我一直在導入用於指標跟踪和報告的數據集。我可以導入 Excel 文件並創建腳本來執行分析。效果很好!
現在的問題是:
這項工作的源數據每週更新到每月一次。我的目標是設置 JMP,以便我每月對數據執行相同的初始分析,但將 JMP 表更新為最新的 Excel 數據。我嘗試使用“源”腳本,但這只是創建了一個新的 JMP 表,其中不包含我保存到原始 JMP 表中的腳本。
我已經閱讀過有關“更新”函數的內容,但這似乎是一個在表中的數據發生更改時更新表的函數。“更新”功能是“重新同步”或“導入”以及隨時間更新/增長源數據集的唯一可用方法嗎?
任何幫助將不勝感激。
戴夫
回复:更新 JMP 數據表根據您在本線程中的前兩篇文章,我不知道您指的是 JMP 中的表更新功能。 事實上,我最近經常使用 Update,但從來沒有印象過它可以與 JMP 數據表以外的任何東西一起使用;事實上,可以通過(數據)表工具欄或(數據)表菜單訪問它。 另外,您原來的帖子沒有提供您在做什麼的詳細描述,因此沒有人回复。
在您定期使用Excel 中的新數據更新JMP 中的表的情況下,我會編寫一個腳本,將數據從Excel 工作簿導入到JMP 中,然後使用從Excel 工作簿創建的數據表更新您維護的數據表。 也就是說,能夠與外部數據源進行連接(這就是連接、更新和連接函數執行的操作)可能是一個值得添加的有趣功能。 JMP 已經通過其 SQL 支持對外部數據庫提供了此功能,但這僅適用於 SQL 數據庫。 Excel 不是數據庫,更不是 SQL 數據庫,因此在您的情況下無法利用 SQL 查詢。 JMP 目前肯定沒有一鍵式功能來直接查詢 Excel 工作簿中的工作表以進行數據聯接。
回复:更新 JMP 數據表saitcopuroglu,我最終致電 JMP 技術支持。事實證明,我上面概述的“解決方法”是目前針對從 Excel 電子表格更新的情況的唯一解決方案。有人告訴我,更新功能是為從一個 JMP 數據表更新到另一個數據表而設計的。不過,該問題將作為 JMP 未來版本的想法提交。
回复:更新 JMP 數據表您能否提供 Excel/jmp/jsl 文件以便更好地理解? 我也很好奇
回复:更新 JMP 數據表任何人……任何人……任何人?
我對更新功能做了一些實驗。JMP 似乎覆蓋了數據表中保存為“源”的腳本。第一次更新時,一切正常。但是,當調用更新時,JMP 會立即使用該腳本覆蓋保存為“源”的腳本,以從新表更新原始表。下次您嘗試從“源”腳本進行更新時,不會發生任何情況。所以,我嘗試了這個:我將數據表中的“源”腳本重命名為“更新”,然後再次嘗試。這次,“Update”腳本沒有改變,但數據表中添加了一個名為“Source”的新腳本。這種“解決方法”顯然效率不高,也不應該是必要的。