def run(self): lastIP = None #上一个发送者的IP while not self.shouldStop: if self.importQueue.empty(): continue # elements = [] # for i in range(0, DataProcessor.BATCH_DATA_SIZE): # element = self.importQueue.get() # print '\nI`ve got an element type = %d, remaining element size :%d' %(element.type, self.importQueue.qsize()) # elements.append(element) #self.importQueue.task_done() #TODO: PROCESS DATA RIGHT HERE element = self.importQueue.get() eventElem, classElem = self.get_full_elements(element)#self.get_valid_elems(elements) if (eventElem, classElem) == (None, None): continue #尚未填满 print ' > > > I`m full...' eveContent = eventElem.content clsContent = classElem.content timestamp = eveContent.timestamp ip = eveContent.senderip emoState = clsContent.result posRate = clsContent.positive_rate posdiff = 0 negdiff = 0 if emoState == ClassifierData.RESULT_POSITIVE: posdiff = 1 else: negdiff = 1 duration = eveContent.dur if not self.has_participant(ip): #如果没有这个参与者,则新建一条记录 participant = Participant(ip, duration, posdiff, negdiff) participant.latest_pos_val = posRate # 判断为positive的rate self.participants[ip] = participant else: #如果有记录,则在之前的基础上加上时间和相关的东西 self.participants[ip].totalTime += duration self.participants[ip].posCount += posdiff self.participants[ip].negCount += negdiff self.participants[ip].latest_pos_val = posRate # 判断为positive的rate self.participants[ip].latest_timestamp = timestamp #消息发送时间 self.participants[ip].ip = ip #IP地址还是要的 if self.nicknames.has_key(ip): self.participants[ip].nickname = self.nicknames[ip] # 设置昵称 if (lastIP is not None) and (lastIP != ip): #构造Conversation (排除上个人的ip是自己的情况!) convContent = ConvContent(lastIP, timestamp, duration, emoState) if not self.participants[ip].conversations.has_key(lastIP): self.participants[ip].conversations[lastIP] = [] #新建一个列表,存放与这个人的conversations self.participants[ip].conversations[lastIP].append(convContent) #TODO: PUT PROCESSED DATA TO EXPORT QUEUE #exportQueue里面是完整的participants数据 self.exportQueue.put(self.participants) lastIP = ip # Update lastIP to current ip