def extract(self, snapshot_id):

        transactions = self.siptransactions.find({"snapshot_id": str(snapshot_id)})

        for transaction in transactions:
            key = transaction['call_id'] + transaction['local_tag'] + transaction['remote_tag']

            if key in self.dialogs.keys():
                # The dialog already exists, just add the message ids
                transaction['_id'] = str(transaction['_id'])
                self.dialogs[key]['transactions'].append(transaction)
            else:

                message = self.networkmessages.find({"_id": ObjectId(transaction['message_ids'][0])})
                sipmessage = SipMessage()
                sipmessage.load(message[0])

                # Parse the sender and receiver
                sender = sipmessage.get_sender()
                receiver = sipmessage.get_receiver()

                transaction['_id'] = str(transaction['_id'])

                # Need to create a new dialog
                self.dialogs[key] = {
                    'snapshot_id': str(snapshot_id),
                    'transactions': [transaction],
                    'sender':      sender,
                    'receiver':    receiver
                }
 def _group_transaction_messages(self, messages):
     ''' Group together the SIP transactions. '''
     transactions = {}
     for message in sorted(messages, key=itemgetter('utc')):
         if message['protocol'] == 'SIP':
             sipmessage = SipMessage()
             sipmessage.load(message)
             key = sipmessage.get_transaction_id()
             if key in transactions.keys():
                 transactions[key].append(sipmessage)
             else:
                 transactions[key] = [sipmessage]
     return transactions