伙计们,
我已经在非标准连接脚本上工作了很长时间,看起来我需要做很多事情。
此时我需要加入两个表。
第一个是对不同工具进行一系列测量。测量在会话中完成。但该表中只有以下内容: 工具,事件时间,结果 。
第二个表包含有关会话的所有信息:
工具,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()。