我正在编写一个pyqt5gui应用程序来解析具有以下结构的特定日志文件。每一行都已在列表中拆分为字符串并存储为自动呼叫. 此列表存储约60K行数据。你知道吗
目标是使用用户输入字符串进行搜索,找到行中包含输入字符串的所有调用ID(1、2、3等)。然后找到与该调用ID相关的所有消息,并使用qlistwidget按顺序显示它们(我喜欢qlistwidget干净的外观)。我试过Qplaintext,但它花了很长时间才显示出来自动呼叫)你知道吗
我可以使用qlistwidget addItem和一个简单的for循环来显示所有50K行自动呼叫,需要几秒钟(可以接受)。你知道吗
for call in self.calls:
self.output.addItem(call)
我的问题是,当我实现我的搜索功能时,如果有大量的行匹配,应用程序会非常困难,需要很长时间来显示数据,即使它是来自自动呼叫. 我尝试使用嵌套for循环和条件、列表理解,以及for循环和regex。所有这些都大致执行相同的操作,10万行解析数据可能需要20-30秒。你知道吗
希望有人能给我一个更快的方式来显示数据使用qlistwidget指针。你知道吗
数据:
Oct 12 18:38:34 user.info server1 host:server: INFO : call 1: allocated for "Web client" conference participation
Oct 12 18:38:34 user.info server1 host:server: INFO : call 1: setting up combined RTP session for DTLS (combined media and control)
Oct 12 18:38:34 user.info server1 host:server: INFO : call 1: starting DTLS combined media negotiation (as initiator)
Oct 12 18:38:35 user.info server1 host:server: INFO : call 1: completed DTLS combined media negotiation
Oct 12 18:38:35 user.info server1 host:server: INFO : call 1: media framework reporting rx video RTP frequency 0 - fixed up to 90000
Oct 12 18:38:35 user.info server1 host:server: INFO : call 1: starting DTLS combined media negotiation (as initiator)
Oct 12 18:38:36 user.info server1 host:server: INFO : call 1: completed DTLS combined media negotiation
Oct 12 18:38:59 user.info server1 host:server: INFO : call 1: tearing down (conference media)
Oct 12 18:51:27 user.info server1 host:server: INFO : call 2: recognised as Avaya
Oct 12 18:51:27 user.info server1 host:server: INFO : call 2: incoming SIP audio call from
Oct 12 18:51:40 user.info server1 host:server: INFO : call 3: outgoing encrypted SIP call to
Oct 12 18:51:40 user.info server1 host:server: INFO : call 3: setting up peer to peer media instantiation
Oct 12 18:51:40 user.info server1 host:server: INFO : call 3: setting up UDT RTP session for DTLS (combined media and control)
Oct 12 18:51:40 user.info server1 host:server: INFO : call 3: SIP call ringing
Oct 12 18:51:40 user.info server1 host:server: INFO : call 3: determined far end good lip sync status, 1
Oct 12 18:51:42 user.info server1 host:server: INFO : call 3: remote layout version supported by peer now 6
Oct 12 18:51:44 user.info server1 host:server: INFO : call 4: allocated for "Web client" conference participation
Oct 12 18:51:44 user.info server1 host:server: INFO : call 4: setting up combined RTP session for DTLS (combined media and control)
Oct 12 18:51:44 user.info server1 host:server: INFO : call 4: starting DTLS combined media negotiation (as initiator)
Oct 12 18:51:44 user.info server1 host:server: INFO : call 4: completed DTLS combined media negotiation
Oct 12 18:52:47 user.info server1 host:server: INFO : call 3: ending; local teardown - connected for 1:07
代码:
if len(self.searchbar.text()) > 2:
self.output_filtered.setHidden(False)
#Regex compiles
re_searchstring = re.compile(r"(^.*?%s.*?$)" % self.searchbar.text(), re.IGNORECASE)
re_callindex = re.compile(r"call\s(\d+):")
#Get results of all calls matching searchbar input
result = list(filter(re_searchstring.match, self.calls))
#Build a temp list with call index number
call_list_temp = []
for item in result:
callindex = re_callindex.findall(item)
call_list_temp.append(callindex)
#Merge the call list, remove dups, and sort
call_list_temp = list(itertools.chain(*call_list_temp))
call_list = list(OrderedDict.fromkeys(call_list_temp))
##############################
# For loops with conditional
for index in call_list:
for calls in self.calls:
if "call " + str(index) + ":" in calls:
self.output_filtered.addItem(calls)
# List Comprehension
test = [calls for index in call_list for calls in self.calls if "call " + str(index) + ":" in calls]
for call in test:
self.output_filtered.addItem(call)
# For loops with regex
for index in call_list:
re_callfinder = re.compile(r"(^.*call\s%s.*$)" % index)
for item in self.calls:
call = re_callfinder.findall(item)
for line in call:
self.output_filtered.addItem(line)
您可以切换到Model/View system,并使用QListView而不是QListWidget。这样,您就可以利用QModel类,它是专为这类工作设计的。。。你知道吗
相关问题 更多 >
编程相关推荐