將 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 可以輕鬆處理的行數並不多。