更新 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”的新脚本。这种“解决方法”显然效率不高,也不应该是必要的。