将 ID_HEX 列表与全局参考表匹配大家好,
我在 JMP 中使用两个表:
- TPMS_Sensor_install_DATA.jmp:包含单个关键列 ID_HEX。
- TableID Globale.jmp 包含关键列 ID 以及所有描述性列(Ref Produit、ProductName、Date、Operator 等)。
目标:过滤全局表,以便它仅保留 ID 出现在我的 ID_HEX 列表中的行,然后仅返回 Ref Produit 和 ProductName 列。
这是我尝试过的脚本——它最终返回未过滤的整个全局表:
// 1. Open both tables invisibly
dtSensor = Open( "D:\\Project JMP\\IDEnorme\\TPMS_Sensor_install_DATA.jmp", Invisible );
dtGlobal = Open( "D:\\Project JMP\\Tables Données\\TableID Globale.jmp", Invisible );
// 2. Extract the list of ID_HEX values from dtSensor
hexList = Column( dtSensor, "ID_HEX" ) << Get Values;
// 3. Subset dtGlobal: keep only rows where :ID is in hexList,
// and select only Ref Produit + ProductName
dtResult = dtGlobal << Subset(
Where( Contains( hexList, :ID ) ),
Select(
:"Ref Produit",
:"ProductName"
),
Output Table Name( "Résultats Correspondance" )
);
// 4. Show the result
dtResult << Show Window;
有人可以帮我修正这个脚本吗:实际上通过 ID_HEX 值的 hexList 过滤 TableID Globale,并且只返回 ID 匹配的 Ref Produit 和 ProductName 列。
如能提供任何指针或示例 JSL 片段,我们将不胜感激!
提前致谢 !
自动化和脚本视窗回复:将 ID_HEX 列表与全局参考表进行匹配你试过 join 是否足够了吗?另一个选择是使用 << Get Rows Where 获取感兴趣的行,并基于此进行子集化
rows_of_interest = dtGlobal << Get Rows Where(Contains(hexList, :ID));
dt_new = dtGlobal << Subset(Rows(rows_of_interest), Columns(:Ref Produit, :ProductName), Output table("Filtered"));
或类似的东西
回复:将 ID_HEX 列表与全局参考表进行匹配我试过了,但脚本运行时间非常长,而且没有任何输出,好像完全挂了。具体来说,dtGlobal 包含 1200 万行数据,dtSensor 包含 40 万行数据。
dtSensor = Open( "D:\\Project JMP\\IDEnorme\\TPMS_Sensor_install_DATA.jmp", Invisible );
dtGlobal = Open( "D:\\Project JMP\\Tables Données\\TableID Globale.jmp", Invisible );
hexList = Column( dtSensor, "ID_HEX" ) << Get Values;
rows_of_interest = dtGlobal << Get Rows Where(
Contains( hexList, :ID )
);
dtResult = dtGlobal << Subset(
Rows( rows_of_interest ),
Select(
:Ref Produit,
:ProductName
),
Output Table Name( "Résultats Correspondance" )
);
dtResult << Show Window;
回复:将 ID_HEX 列表与全局参考表进行匹配例如,您可以使用 Summarize 来删除 dtSensor 上的重复项,这会有所帮助
Summarize(dtSensor, hexList = By(:ID_HEX));
回复:将 ID_HEX 列表与全局参考表进行匹配using an associative array, you should see <2 minutes</CODE></P>
<PRE><CODE class=" language-jsl">dtSensor = Open( "$DESKTOP/TPMS_Sensor_install_DATA.jmp" );
hexList = Column( dtSensor, "ID_HEX" ) << Get Values; //1048575
lookup = Associative Array( hexList );//231356
hexList = lookup << getkeys; // the keep list.
// manufacture a 12 million row table with 50% matches
n = 12e6; // about 1/4 minute to build a test table...
dtGlobal = New Table( "Untitled",
Add Rows( n ),
New Column( "ID_HEX",
Character,
"Nominal",
Set Values( Transform Each( {v}, Repeat( {"1", "0"}, n / 2 ), If( v == "1", "badc0de", hexlist[Random Integer( 1, N Items( hexlist ) )] ) ) )
),
New Column( "Ref Produit", setvalues( 1 :: n ) ), // even rows match the keep list
New Column( "ProductName", setvalues( 1 :: n ) ) // odd rows are badc0de, not in keep list
);
unwantedrows = dtGlobal << get rows where( !(lookup << Contains( ID_HEX )) ); // about a minute to identify the rows
dtGlobal << deleterows( unwantedrows );
回复:将 ID_HEX 列表与全局参考表进行匹配我按照 Jthi 的建议从两个数据表中删除了重复项,并使用了关联数组方法,并且成功了!
非常感谢您的帮助!
回复:将 ID_HEX 列表与全局参考表进行匹配如果只使用列表并且值是字符串,我建议使用 Summarize。如果数据集较大,仅使用关联数组进行重复删除会很慢。汇总表在处理大型数据表时速度最快,但需要的代码量略多,但它确实有一些好处,例如将数字保留为数字。关联数组和汇总/汇总之间的顺序也可能不同。
查看更多...
Names Default To Here(1);
dttemp = Open("$DOWNLOADS/TPMS_Sensor_install_DATA.jmp");
hexList = Column(dttemp, "ID_HEX") << Get Values;
lookup = Associative Array(hexList);
hexList = lookup << getkeys;
n = 12e6;
dt = New Table("Untitled",
Add Rows(n),
New Column("ID_HEX",
Character,
"Nominal",
Set Values(
Transform Each({v}, Repeat({"1", "0"}, n / 2),
If(v == "1",
"badc0de",
uniq[Random Integer(1, N Items(uniq))]
)
)
)
),
Private
);
Close(dttemp, no save);
wait(0);
s = Tick Seconds();
Summarize(dt, uniq_summarize = By(:ID_HEX));
wait(0);
summarize_dur = Tick Seconds() - s;
wait(0);
s = Tick Seconds();
uniq_aa = Associative Array(:ID_HEX) << get keys;
wait(0);
aa_dur = Tick Seconds() - s;
wait(0);
s = Tick Seconds();
vals = Column(dt, "ID_HEX") << Get Values;
aa = Associative Array(vals);
uniq_aa2 = Associative Array(aa) << get keys;
wait(0);
aa2_dur = Tick Seconds() - s;
wait(0);
s = Tick Seconds();
dt_summary = dt << Summary(
Group(:ID_HEX),
Freq("None"),
Weight("None"),
output table name("Summary of Untitled grouped by ID_HEX"),
Private
);
uniq_summary = dt_summary[0, 1];
Close(dt_summary, no save);
wait(0);
summary_dur = Tick Seconds() - s;
Close(dt, no save);
Show(N Items(uniq_summarize), N Items(uniq_aa), N Items(uniq_aa2), N Items(uniq_summary));
Show(summarize_dur, aa_dur, aa2_dur, summary_dur);
N Items(uniq_summarize) = 231357;
N Items(uniq_aa) = 231357;
N Items(uniq_aa2) = 231357;
N Items(uniq_summary) = 231357;
summarize_dur = 2.36666666666861;
aa_dur = 32.5166666666628;
aa2_dur = 32.25;
summary_dur = 1.30000000000291;
根据实际数据,这很可能完成得相当快,因为 JMP 可以轻松处理的行数并不多。