svetlana 3 anos atrás
pai
commit
919ff0e461
2 arquivos alterados com 63 adições e 6 exclusões
  1. 19 0
      app/app.py
  2. 44 6
      app/cel.py

+ 19 - 0
app/app.py

@@ -331,6 +331,10 @@ async def getCDR(start=None,
     cdr.append(_cdr[_id])
   return cdr
 
+async def getCallInfo(linked_id):
+    return []
+
+    
 async def getUserCDR(user,
                      start=None,
                      end=None,
@@ -1247,6 +1251,21 @@ class UserCalls(Resource):
                            request.args.get('offset', None),
                            request.args.get('order', 'ASC'))
     return successReply(cdr)
+    
+@app.route('/call/<call_id>')
+class CallInfo(Resource):
+  @authRequired
+  @app.param('call_id', 'call_id for ', 'query')
+  @app.response(HTTPStatus.OK, 'JSON data {"status":status,"data":data,"message":message}')
+  @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
+  async def get(self, call_id):
+    '''Returns call info.
+    '''
+    if (user != request.user) and (not request.admin):
+      abort(401)
+    call = await getCallInfo(user,
+                           request.args.get('call_id', None))
+    return successReply(call)
 
 @app.route('/device/<device>/callback')
 class DeviceCallback(Resource):

+ 44 - 6
app/cel.py

@@ -35,13 +35,37 @@ class CdrEvent:
     return None
 
 class CdrEvents:
-  def __init__(self):
+  def __init__(self,linkedid):
     self._events = []
+    self._channels = []
+    self._dstchannels = []
+    self.start = 0
+    self.linkedid = linkedid
+    
   def add(self, event):
-    if isinstance(event, CdrEvent):
-      self._events.append(event)
-    else:
-      self._events.append(CdrEvent(event))
+    if not isinstance(event, CdrEvent):
+      event = CdrEvent(event)
+    if not self.start:
+        self.start = event.calldate
+    if event.channel not in self._channels:
+        self._channels[event.channel] = event
+    if event.dstchannel not in self._dstchannels:
+        self._dstchannels[event.dstchannel] = event.dst
+    if (event.lastapp == 'Queue'):
+      for e in self._events:
+        if (e.lastapp == 'Queue') and (e.uniqueid == event.uniqueid):
+          if (event.disposition == 'ANSWERED'):
+            e.disposition = 'ANSWERED'
+            if event.dstchannel in self._channels:
+              dialevent = self._channels[event.dstchannel]
+              e.duration = e.start-dialevent.start +  dialevent.duration 
+              e.billsec = dialevent.billsec
+          return # if it not fiars queue event - miss it
+    if (event.lastapp == 'Dial' and event.dstchannel in self._dstchannels):
+        event.dst = self._dstchannels[event.dstchannel]
+    self.end = event.calldate + td(seconds=event.duration)
+    self._events.append(event)
+
   @property
   def all(self):
     return self._events
@@ -67,6 +91,20 @@ class CdrEvents:
     return False
   def __len__(self):
     return len(self._events)
+  def simple(self):
+    res = []
+    for event in self._events:
+        simple_event = {'start': event.calldate,
+            'answered': event.disposition=='ANSWERED',
+            'duration': event.billsec,
+            'waiting': event.duration = event.billsec,
+            'application': event.lastapp,
+            'src': event.src,
+            'dst': event.dst,
+            'uniqueid': event.uniqueid,
+            'file': event.recordingfile}
+        res.append(simple_event)
+    return res
 
 class CdrUserEvents(CdrEvents):
   def __init__(self, user):
@@ -241,7 +279,7 @@ class CdrUserCall(CdrCall):
             'did': self.did,
             'linkedid': self.linkedid,
             'file': self.file,
-            'events': self.events.simple()}
+            }#'events': self.events.simple()}
 
 class CelCall:
   def __init__(self, event=None):