Hal De 3 éve
szülő
commit
ce176a72db
2 módosított fájl, 18 hozzáadás és 4 törlés
  1. 16 2
      app/app.py
  2. 2 2
      app/cel.py

+ 16 - 2
app/app.py

@@ -405,13 +405,24 @@ async def getCDR(start=None,
     cdr.append(_cdr[_id])
   return cdr
 
-async def getCallInfo(linkedid):
+async def getCallInfo(callid):
+  pattern = re.compile("^[0-9]+\.[0-9]+")
+  #app.logger.warning('callid {}'.format(callid)) 
+  if (pattern.match(callid)):
+    linkedid=callid
+  else:
+    row = await db.fetch_one(query='SELECT linkedid FROM cdr WHERE userfield = :callid', values={'callid': callid})
+    if row:
+      linkedid = row['linkedid']
+    else:
+      return "{}"
+  #app.logger.warning('linkedid {}'.format(linkedid)) 
   _q = '''SELECT *
           FROM cel 
           WHERE linkedid=:linkedid and eventtype = :eventtype'''
   _v = {'linkedid': linkedid, 'eventtype': 'ATTENDEDTRANSFER'}
   _f = True
-  uniqueids = set(linkedid) #get ids of transferred calls
+  uniqueids = set((linkedid,)) #get ids of transferred calls
   async for row in db.iterate(query=_q, values=_v):
     extra  = json.loads(row['extra'])
     uniqueids.add(extra['channel2_uniqueid'])
@@ -421,14 +432,17 @@ async def getCallInfo(linkedid):
           WHERE linkedid=:linkedid or linkedid in (select distinct linkedid from cdr where uniqueid in :uniqueids)
           ORDER BY sequence;'''
   _v = {'linkedid': linkedid, 'uniqueids': uniqueids}
+  #app.logger.warning('values {}'.format(_v)) 
   _f = True
   unique_ids = set()
   events = CdrEvents()
   async for row in db.iterate(query=_q, values=_v):
     row = dict(row)
+    #app.logger.warning('row {}'.format(row)) 
     if row['recordingfile'] is not None and row['recordingfile']  != '':
       row['recordingfile'] = '/static/records/{d.year}/{d.month:02}/{d.day:02}/{filename}'.format(d=row['calldate'],
                                                                                             filename=row['recordingfile'])
+    #app.logger.warning('event row {}'.format(row))   
     events.add(row)
   record = events.simple()                                                     
   return record

+ 2 - 2
app/cel.py

@@ -55,7 +55,7 @@ class CdrEvents:
       event.cnum = event.src
     if (event.channel.id not in self._channels):
         self._channels[event.channel.id] = event
-    if (event.dstchannel.id not in self._dstchannels):
+    if (event.dstchannel and event.dstchannel.id not in self._dstchannels):
         self._dstchannels[event.dstchannel.id] = event.dst
     if (self._waitingchannel is not None) and (self._waitingchannel.id == event.channel.id): # if dial event after queue event
         for e in self._events:
@@ -72,7 +72,7 @@ class CdrEvents:
       if (event.disposition == 'ANSWERED'): #if it answered - fill duration and waitng based on answered dial event
         queueevent.disposition = 'ANSWERED'
         queueevent.dstchannel = event.dstchannel
-        if (event.dstchannel.id in self._channels): # if dial event before queue event
+        if (event.dstchannel and event.dstchannel.id in self._channels): # if dial event before queue event
           dialevent = self._channels[event.dstchannel.id]
           queueevent.duration = (dialevent.calldate-queueevent.calldate).total_seconds() +  dialevent.duration 
           queueevent.billsec = dialevent.billsec