伙計們,
我已經在非標準連接腳本上工作了很長時間,看起來我需要做很多事情。
此時我需要加入兩個表。
第一個是對不同工具進行一系列測量。測量在會話中完成。但該表中只有以下內容: 工具,事件時間,結果 。
第二個表包含有關會話的所有信息:
工具,sessionid,starttime,endtime
我需要對測量結果進行分析會話ID
基本上,我需要加入獨特的會話ID 到第一個表中的每一行。
我目前這樣做的方法是迭代第一個表中的每一行,並在第二個表中搜索相應的行工具匹配和 EVENTTIME 介於兩者之間開始時間和時間結束使用這個:
currentStartEndInfoindex=dt2 << Get Rows Where(:tool==thisTool & :measstart < thisEventtime & :measend > thisEventtime);
哪裡 thisTool 和 thisEventtime 是我正在迭代的第一個表的工具和時間。我得到了唯一的列表會話ID 從匹配此條件的第二個表中,然後組裝一個列表,在循環結束時使用它來填充第一個表中的新列。這個“Get Rows Where”行佔用了腳本運行時間的85%。
現在,第一個表中有幾百萬行,第二個表中有幾十萬行需要8到16個小時。
我經不起這麼久。
因此,問題:
有什麼方法可以優化嗎?畢竟,對於第一個表中的每一行,它一遍又一遍地查看第二個表 - 效率不高。
我的一個想法是通過工具將第二個表分成子列表,然後對與該特定工具對應的子列表中的每一行執行“獲取行”。但是不知道如何最好地實現它。
任何幫助將不勝感激。
謝謝!
這是第一個近似值
aaa = New Table( "aaa", // the "event" table
Add Rows( 6 ),
New Column( "tool", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [100, 100, 100, 200, 200, 200] ) ),
New Column( "eventtime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 21, 12, 31, 41, 42] ) ),
New Column( "result", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1, 1, 1, 0, 0] ) ),
New Column( "sessionID_added", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [., ., ., ., ., .] ) )
);
bbb = New Table( "bbb", // the start-end table
Add Rows( 4 ),
New Column( "tool", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [100, 100, 200, 200] ) ),
New Column( "sessionID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [111, 222, 333, 444] ) ),
New Column( "startTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [10, 20, 30, 40] ) ),
New Column( "endTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [19, 29, 39, 49] ) )
);
// build two lookup tables that find all the rows associated with a tool
aaaRowsFromTool = Associative Array();
For( irow = 1, irow <= N Rows( aaa ), irow++,
If( !(aaaRowsFromTool << Contains( aaa:tool[irow] )), //
aaaRowsFromTool[aaa:tool[irow]] = Eval List( {irow} )//
, //
Insert Into( aaaRowsFromTool[aaa:tool[irow]], irow ) //
)
);
bbbRowsFromTool = Associative Array();
For( irow = 1, irow <= N Rows( bbb ), irow++,
If( !(bbbRowsFromTool << Contains( bbb:tool[irow] )), //
bbbRowsFromTool[bbb:tool[irow]] = Eval List( {irow} )//
, //
Insert Into( bbbRowsFromTool[bbb:tool[irow]], irow ) //
)
);
toolList = bbbRowsFromTool << getkeys;
For( itool = 1, itool <= N Items( toolList ), itool += 1,
toolno = toolList[itool];
// build a sorted list of event times+row numbers for this tool
aaaRowList = aaaRowsFromTool[toolno];
aaa << selectrows( aaaRowList );
aaasub = aaa << Subset( Selected Rows( 1 ), Selected columns only( 0 ), link to original data table( 1 ) );
//aaasub << sort( by( eventTime ), replace table );
timeMatrix = aaasub:eventtime << getAsMatrix;
bbbRowList = bbbRowsFromTool[toolno];
For( irow = 1, irow <= N Items( bbbRowList ), irow += 1,
bbbRow = bbbRowList[irow];
start = bbb:startTime[bbbRow];
end = bbb:endTime[bbbRow];
id = bbb:sessionID[bbbRow];
// find the eventTimes between start and end, for this tool
//aaasub<<SELECTWHERE></SELECTWHERE>
它可以工作,但是速度太慢,你可能想利用eventTime對“事件”表進行排序,並用二進制查找替換loc()。