def calcular_cantidad_llamadas(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula la cantidad de llamadas procesads teniendo en cuenta los
        eventos de fin de conexión con un Cliente """

        eventos_llamadas = list(LlamadaLog.EVENTOS_FIN_CONEXION)
        agentes_id = [agente.id for agente in agentes]

        logs_time = LlamadaLog.objects.obtener_count_evento_agente(
            eventos_llamadas,
            fecha_inferior,
            fecha_superior,
            agentes_id)

        for log in logs_time:
            cantidad = int(log[1])
            agente = AgenteProfile.objects.get(pk=int(log[0]))
            agente_en_lista = list(filter(lambda x: x.agente == agente,
                                          self.agentes_tiempo))
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._cantidad_llamadas_procesadas = cantidad
            else:
                agente_nuevo = AgenteTiemposReporte(
                    agente, timedelta(0), timedelta(0), timedelta(0), cantidad, 0, 0, 0)
                self.agentes_tiempo.append(agente_nuevo)
Esempio n. 2
0
 def calcular_tiempo_agente(self, agente, fecha_desde, fecha_hasta,
                            campana):
     ahora = now()
     if fecha_hasta.date() == ahora.date():
         # estamos calculando hasta el día actual
         fecha_hasta = ahora
     logs_actividad_agente = ActividadAgenteLog.objects.filter(
         agente_id=agente.id,
         time__range=(fecha_desde, fecha_hasta)).order_by('time')
     logs_llamadas_agente = LlamadaLog.objects.filter(
         time__range=(fecha_desde, fecha_hasta),
         campana_id=campana.pk,
         agente_id=agente.pk)
     tiempo_sesion, tiempo_pausa = self._obtener_actividad_agente(
         logs_actividad_agente)
     (tiempo_en_llamada, tiempo_en_llamada_manual,
      cantidad_llamadas_procesadas, cantidad_llamadas_perdidas,
      cantidad_llamadas_manuales
      ) = self._obtener_estadisticas_llamadas_agente(logs_llamadas_agente)
     # los valores de las variables 'tiempo_en_llamada_manual' y 'cantidad_llamadas_manuales'
     # y las estadísticas que a partir de estos se generan no son relevantes en los reportes
     # actualmente, se mantiene su cálculo previendo su uso a futuro
     agente_tiempos = AgenteTiemposReporte(agente, tiempo_sesion,
                                           tiempo_pausa, tiempo_en_llamada,
                                           cantidad_llamadas_procesadas,
                                           cantidad_llamadas_perdidas,
                                           tiempo_en_llamada_manual,
                                           cantidad_llamadas_manuales)
     return agente_tiempos
Esempio n. 3
0
    def calcular_intentos_fallidos(self, agentes, fecha_inferior,
                                   fecha_superior):
        """ Calcula la cantidad de intentos fallido para el tipo de llamada
        Manual NO CONNECT(NOANSWER, CANCEL, BUSY, CHANUNAVAIL, FAIL, OTHER,
        AMD, BLACKLIST, 'CONGESTION', 'NONDIALPLAN')"""

        eventos_llamadas = list(LlamadaLog.EVENTOS_NO_CONTACTACION)
        agentes_id = [agente.id for agente in agentes]

        logs_time = LlamadaLog.objects.obtener_count_evento_agente(
            eventos_llamadas, fecha_inferior, fecha_superior, agentes_id)

        for log in logs_time:

            cantidad = int(log[1])
            agente = AgenteProfile.objects.get(pk=int(log[0]))
            agente_en_lista = list(
                filter(lambda x: x.agente == agente, self.agentes_tiempo))
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._cantidad_intentos_fallidos = cantidad
            else:
                agente_nuevo = AgenteTiemposReporte(agente, timedelta(0),
                                                    timedelta(0), timedelta(0),
                                                    0, cantidad, 0, 0)
                self.agentes_tiempo.append(agente_nuevo)
    def calcular_tiempo_llamada(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula el tiempo de llamada teniendo en cuenta los eventos
        de finalizacion de conexion con Cliente"""

        eventos_llamadas = list(LlamadaLog.EVENTOS_FIN_CONEXION)
        agentes_id = [agente.id for agente in agentes]

        logs_time = LlamadaLog.objects.obtener_tiempo_llamadas_agente(
            eventos_llamadas,
            fecha_inferior,
            fecha_superior,
            agentes_id)

        for log in logs_time:

            tiempo_llamada = timedelta(seconds=int(log[1]))
            agente = AgenteProfile.objects.get(pk=int(log[0]))
            agente_en_lista = list(filter(lambda x: x.agente == agente,
                                          self.agentes_tiempo))
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._tiempo_llamada = tiempo_llamada
            else:
                agente_nuevo = AgenteTiemposReporte(
                    agente, timedelta(0), timedelta(0), tiempo_llamada, 0, 0, 0, 0)
                self.agentes_tiempo.append(agente_nuevo)
Esempio n. 5
0
    def calcular_tiempo_llamada_agente_fecha(self, agente, fecha_inferior,
                                             fecha_superior, agente_fecha):
        """ Calcula el tiempo de llamada teniendo en cuenta los eventos
        COMPLETECALLER y COMPLETEOUTNUM, por fecha dia a dia para el agente"""

        eventos_llamadas = list(LlamadaLog.EVENTOS_FIN_CONEXION)

        logs_time = LlamadaLog.objects.obtener_tiempo_llamada_agente(
            eventos_llamadas, fecha_inferior, fecha_superior, agente.id)

        for log in logs_time:

            date_time_actual = fecha_local(log.time)
            agente_en_lista = list(
                filter(lambda x: x.agente == date_time_actual, agente_fecha))
            duracion_llamada = timedelta(seconds=log.duracion_llamada)
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._tiempo_llamada += duracion_llamada
                agente_nuevo._cantidad_llamadas_procesadas += 1
            else:
                agente_nuevo = AgenteTiemposReporte(date_time_actual,
                                                    timedelta(0), timedelta(0),
                                                    duracion_llamada, 1, 0, 0,
                                                    0)
                agente_fecha.append(agente_nuevo)
        return agente_fecha
    def calcular_intentos_fallidos_fecha_agente(self, agente, fecha_inferior,
                                                fecha_superior, agente_fecha):
        """ Calcula la cantidad de intentos fallido para el tipo de llamada
        Manual NO CONNECT(NOANSWER, CANCEL, BUSY, CHANUNAVAIL, FAIL, OTHER,
        AMD, BLACKLIST, 'CONGESTION', 'NONDIALPLAN') por fecha dia a dia para el agente"""

        eventos_llamadas = list(LlamadaLog.EVENTOS_NO_CONTACTACION)

        logs_time = LlamadaLog.objects.obtener_count_evento_agente_agrupado_fecha(
            eventos_llamadas,
            fecha_inferior,
            fecha_superior,
            agente.id)
        for log in logs_time:
            date_time_actual = log['fecha']
            agente_en_lista = list(filter(lambda x: x.agente == date_time_actual,
                                          agente_fecha))
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._cantidad_intentos_fallidos = int(log['cantidad'])
            else:
                agente_nuevo = AgenteTiemposReporte(
                    date_time_actual, timedelta(0), timedelta(0), timedelta(0),
                    0, int(log['cantidad']), 0, 0)
                agente_fecha.append(agente_nuevo)
        return agente_fecha
 def _genera_tiempos_totales_agentes(self):
     for agente in self.datos_agentes.values():
         agente.calcula_totales()
         self.tiempos.append(AgenteTiemposReporte(
             agente.agente, agente.tiempo_sesion,
             agente.tiempo_pausa,
             agente.tiempo_llamada, agente.llamadas_procesadas, agente.intentos_fallidos, 0, 0,
             agente.tiempo_hold, agente.transferidas_a_agente))
Esempio n. 8
0
    def calcular_tiempo_session_fecha_agente(self, agente, fecha_inferior,
                                             fecha_superior, agente_fecha):
        """ Calcula el tiempo de session teniendo en cuenta los eventos
        ADDMEMBER, REMOVEMEMBER por fecha dia a dia"""

        eventos_sesion = ['ADDMEMBER', 'REMOVEMEMBER']

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_sesion, fecha_inferior, fecha_superior, [agente.id])

        time_actual = None
        is_remove = False
        len_log_agente = len(logs_time) - 1
        error = False

        for logs in logs_time:
            calculo_ok = False
            # primer elemento addmember
            if logs_time.index(logs) == 0 and logs[2] == 'ADDMEMBER':
                agente_nuevo = None
                is_remove = False
                time_actual = None
                error = True
            # ultimo elemento removemember
            if len_log_agente == logs_time.index(
                    logs) and logs[2] == 'REMOVEMEMBER':
                agente_nuevo = None
                is_remove = False
                time_actual = None
                error = True

            if is_remove and logs[2] == 'ADDMEMBER':
                resta = time_actual - logs[1]
                calculo_ok = True

            if logs[2] == 'REMOVEMEMBER':
                time_actual = logs[1]
                is_remove = True
            if calculo_ok:
                date_time_actual = cast_datetime_part_date(time_actual)
                agente_en_lista = filter(
                    lambda x: x.agente == date_time_actual, agente_fecha)
                if agente_en_lista:
                    agente_nuevo = agente_en_lista[0]
                    if agente_nuevo.tiempo_sesion:
                        agente_nuevo._tiempo_sesion += resta
                    else:
                        agente_nuevo._tiempo_sesion = resta
                else:
                    agente_nuevo = AgenteTiemposReporte(
                        cast_datetime_part_date(time_actual), resta, 0, 0, 0,
                        0, 0, 0)
                    agente_fecha.append(agente_nuevo)
                agente_nuevo = None
                is_remove = False
                time_actual = None

        return agente_fecha, error
    def calcular_tiempo_hold_tipo_fecha(self, agente, fecha_inferior,
                                        fecha_superior, agente_fecha):
        evento_hold = ['HOLD']
        evento_unhold = ['UNHOLD']
        tiempo_hold = timedelta(0)
        hold_fecha = [hold for hold in LlamadaLog.objects.obtener_evento_hold_fecha(
            evento_hold,
            fecha_inferior,
            fecha_superior,
            agente.id)]

        primer_unhold = LlamadaLog.objects.obtener_evento_hold_fecha(evento_unhold, fecha_inferior,
                                                                     fecha_superior, agente.id
                                                                     ).first()
        if hold_fecha:
            primer_hold = hold_fecha[0]
            if primer_unhold and primer_unhold.time < primer_hold.time:
                tiempo_hold += primer_unhold.time - fecha_inferior

        for log in hold_fecha:
            fecha_actual = fecha_local(log.time)
            agente_en_lista = list(filter(lambda x: x.agente == fecha_actual,
                                          agente_fecha))
            inicio_hold = log.time
            callid = log.callid
            fecha_desde = datetime_hora_minima_dia(fecha_actual)
            fecha_hasta = datetime_hora_maxima_dia(fecha_actual)
            unhold_fecha = LlamadaLog.objects.filter(agente_id=agente.id, callid=callid,
                                                     event='UNHOLD',
                                                     time__range=(log.time, fecha_hasta)
                                                     ).order_by('time').first()
            if unhold_fecha:
                # Si existen varios unhold dentro de una llamada se elige el primero
                fin_hold = unhold_fecha.time
            else:
                # Si se corta la llamada sin haber podido hacer unhold o por otro motivo
                log_llamada = LlamadaLog.objects.filter(agente_id=agente.id, callid=callid,
                                                        time__range=(fecha_desde, fecha_hasta)
                                                        ).last()
                if log_llamada and log_llamada.event != 'HOLD':
                    fin_hold = log_llamada.time
                else:
                    fin_hold = now() \
                        if datetime_hora_maxima_dia(fecha_superior) >= now() else fecha_superior

            tiempo_hold += fin_hold - inicio_hold

            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._tiempo_hold = tiempo_hold
            else:

                agente_nuevo = AgenteTiemposReporte(fecha_local(fecha_inferior), timedelta(0),
                                                    timedelta(0), timedelta(0), 0, 0, 0, 0,
                                                    tiempo_hold, 0)
                agente_fecha.append(agente_nuevo)
        return agente_fecha
Esempio n. 10
0
    def calcular_tiempo_session(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula el tiempo de session teniendo en cuenta los eventos
        ADDMEMBER, REMOVEMEMBER"""

        eventos_sesion = ['ADDMEMBER', 'REMOVEMEMBER']
        agentes_id = [agente.id for agente in agentes]

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_sesion, fecha_inferior, fecha_superior, agentes_id)

        for agente in agentes:
            agente_nuevo = None
            is_remove = False
            time_actual = None
            log_agente = self._filter_query_por_agente(logs_time, agente.id)
            len_log_agente = len(log_agente) - 1
            for logs in log_agente:
                calculo_ok = False
                # primer elemento addmember
                if log_agente.index(logs) == 0 and logs[2] == 'ADDMEMBER':
                    fecha_hoy = timezone.now()
                    time_actual = datetime_hora_maxima_dia(logs[1])
                    if cast_datetime_part_date(
                            logs[1]) == cast_datetime_part_date(fecha_hoy):
                        time_actual = fecha_hoy
                    resta = time_actual - logs[1]
                    calculo_ok = True
                # ultimo elemento removemember
                if len_log_agente == log_agente.index(
                        logs) and logs[2] == 'REMOVEMEMBER':
                    time_actual = datetime_hora_minima_dia(logs[1])
                    resta = logs[1] - time_actual
                    calculo_ok = True

                if is_remove and logs[2] == 'ADDMEMBER':
                    resta = time_actual - logs[1]
                    calculo_ok = True

                if logs[2] == 'REMOVEMEMBER':
                    time_actual = logs[1]
                    is_remove = True
                if calculo_ok:
                    agente_en_lista = filter(lambda x: x.agente == agente,
                                             self.agentes_tiempo)
                    if agente_en_lista:
                        agente_nuevo = agente_en_lista[0]
                        if agente_nuevo.tiempo_sesion:
                            agente_nuevo._tiempo_sesion += resta
                        else:
                            agente_nuevo._tiempo_sesion = resta
                    else:
                        agente_nuevo = AgenteTiemposReporte(
                            agente, resta, 0, 0, 0, 0, 0, 0)
                        self.agentes_tiempo.append(agente_nuevo)
                    agente_nuevo = None
                    is_remove = False
                    time_actual = None
    def _computar_tiempo_session_fecha(self, tiempos_fechas, inicio, fin):
        """ Computa la duracion de la sesion en la lista de tiempos por fecha """
        fecha_inicio = fecha_local(inicio)
        fecha_fin = fecha_local(fin)

        if tiempos_fechas and tiempos_fechas[-1].agente == fecha_inicio:
            tiempos = tiempos_fechas[-1]
        else:
            tiempos = AgenteTiemposReporte(
                fecha_inicio, timedelta(0), timedelta(0), timedelta(0), 0, 0, 0, 0)
            tiempos_fechas.append(tiempos)

        if fecha_fin == tiempos.agente:
            tiempos._tiempo_sesion += fin - inicio
        else:
            fin_dia = datetime_hora_maxima_dia(fecha_inicio)
            tiempos._tiempo_sesion += fin_dia - inicio
            inicio_dia = datetime_hora_minima_dia(fecha_fin)
            duracion = fin - inicio_dia
            tiempos = AgenteTiemposReporte(
                fecha_fin, duracion, timedelta(0), timedelta(0), 0, 0, 0, 0)
            tiempos_fechas.append(tiempos)
    def calcular_tiempo_pausa_fecha_agente(self, agente, fecha_inferior,
                                           fecha_superior, agente_fecha):
        """ Calcula el tiempo de pausa teniendo en cuenta los eventos PAUSEALL,
        UNPAUSEALL y REMOVEMEMBER por fecha dia a dia para el agente"""

        eventos_pausa = ['PAUSEALL', 'UNPAUSEALL', 'REMOVEMEMBER']

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_pausa,
            fecha_inferior,
            fecha_superior,
            [agente.id])

        # Establezco un limite hasta al cual calcular la ultima pausa no finalizada
        hora_limite = now()
        hora_maxima = datetime_hora_maxima_dia(fecha_superior)
        if hora_maxima < hora_limite:
            hora_limite = hora_maxima

        TIME = 1
        EVENT = 2
        time_actual = hora_limite
        for log in logs_time:
            agente_nuevo = None

            # Descarto Pausas sin log de finalización
            if log[EVENT] == 'PAUSEALL':

                resta = time_actual - log[TIME]
                date_time_actual = fecha_local(time_actual)
                agente_en_lista = list(filter(lambda x: x.agente == date_time_actual,
                                              agente_fecha))
                if agente_en_lista:
                    agente_nuevo = agente_en_lista[0]
                    agente_nuevo._tiempo_pausa += resta
                else:
                    agente_nuevo = AgenteTiemposReporte(
                        fecha_local(time_actual), timedelta(0), resta, timedelta(0), 0, 0, 0, 0,
                        timedelta(0), 0)
                    agente_fecha.append(agente_nuevo)
                time_actual = log[TIME]

            if log[EVENT] == 'UNPAUSEALL' or log[EVENT] == 'REMOVEMEMBER':
                time_actual = log[TIME]
        return agente_fecha
    def calcular_tiempo_llamada_agente_fecha(self, agente, fecha_inferior,
                                             fecha_superior, agente_fecha):
        """ Calcula el tiempo de llamada teniendo en cuenta los eventos
        COMPLETECALLER y COMPLETEOUTNUM, por fecha dia a dia para el agente"""

        eventos_llamadas = list(LlamadaLog.EVENTOS_FIN_CONEXION)

        logs_time = LlamadaLog.objects.obtener_tiempo_llamada_agente(
            eventos_llamadas,
            fecha_inferior,
            fecha_superior,
            agente.id).exclude(campana_id=0)

        campanas_ids = set()
        for log in logs_time:
            campanas_ids.add(log.campana_id)
            date_time_actual = fecha_local(log.time)
            agente_en_lista = list(filter(lambda x: x.agente == date_time_actual,
                                          agente_fecha))
            duracion_llamada = timedelta(seconds=log.duracion_llamada)
            if agente_en_lista:
                agente_nuevo = agente_en_lista[0]
                agente_nuevo._tiempo_llamada += duracion_llamada
                agente_nuevo._cantidad_llamadas_procesadas += 1
            else:
                agente_nuevo = AgenteTiemposReporte(
                    date_time_actual, timedelta(0), timedelta(0), duracion_llamada, 1, 0, 0, 0,
                    timedelta(0), 0)
                agente_fecha.append(agente_nuevo)

        for datos_fecha in agente_fecha:
            fecha = datos_fecha.agente
            fecha_inicial = datetime_hora_minima_dia(fecha)
            fecha_final = datetime_hora_maxima_dia(fecha)
            transferencias = LlamadaLog.objects.obtener_cantidades_de_transferencias_recibidas(
                fecha_inicial, fecha_final, [agente.id], campanas_ids)
            cant_transfers = 0
            transferencias_por_camp = transferencias.get(agente.id, {})
            for cant in transferencias_por_camp.values():
                cant_transfers += cant
            datos_fecha._cantidad_llamadas_procesadas -= cant_transfers
            datos_fecha._transferidas_a_agente = cant_transfers

        return agente_fecha
    def calcular_tiempo_pausa(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula el tiempo de pausa teniendo en cuenta los eventos PAUSEALL,
        UNPAUSEALL y REMOVEMEMBER"""

        eventos_pausa = ['PAUSEALL', 'UNPAUSEALL', 'REMOVEMEMBER']
        agentes_id = [agente.id for agente in agentes]

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_pausa,
            fecha_inferior,
            fecha_superior,
            agentes_id)

        # Establezco un limite hasta al cual calcular la ultima pausa no finalizada
        hora_limite = now()
        hora_maxima = datetime_hora_maxima_dia(fecha_superior)
        if hora_maxima < hora_limite:
            hora_limite = hora_maxima

        TIME = 1
        EVENT = 2
        for agente in agentes:
            time_actual = hora_limite

            logs_agente = self._filter_query_por_agente(logs_time, agente.id)

            for log in logs_agente:
                # Asumo que si la pausa no esta finalizada, es porque el agente esta online
                if log[EVENT] == 'PAUSEALL':
                    resta = time_actual - log[TIME]
                    agente_en_lista = list(filter(lambda x: x.agente == agente,
                                                  self.agentes_tiempo))
                    if agente_en_lista:
                        agente_nuevo = agente_en_lista[0]
                        agente_nuevo._tiempo_pausa += resta
                    else:
                        agente_nuevo = AgenteTiemposReporte(
                            agente, timedelta(0), resta, timedelta(0), 0, 0, 0, 0)
                        self.agentes_tiempo.append(agente_nuevo)
                    time_actual = log[TIME]
                if log[EVENT] == 'UNPAUSEALL' or log[EVENT] == 'REMOVEMEMBER':
                    time_actual = log[TIME]
Esempio n. 15
0
    def calcular_tiempo_pausa_fecha_agente(self, agente, fecha_inferior,
                                           fecha_superior, agente_fecha):
        """ Calcula el tiempo de pausa teniendo en cuenta los eventos PAUSEALL,
        UNPAUSEALL y REMOVEMEMBER por fecha dia a dia para el agente"""

        eventos_pausa = ['PAUSEALL', 'UNPAUSEALL', 'REMOVEMEMBER']

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_pausa, fecha_inferior, fecha_superior, [agente.id])

        TIME = 1
        EVENT = 2
        time_actual = None
        is_unpause = False
        for log in logs_time:
            agente_nuevo = None

            if is_unpause and log[EVENT] == 'PAUSEALL':

                resta = time_actual - log[TIME]
                date_time_actual = fecha_local(time_actual)
                agente_en_lista = list(
                    filter(lambda x: x.agente == date_time_actual,
                           agente_fecha))
                if agente_en_lista:
                    agente_nuevo = agente_en_lista[0]
                    agente_nuevo._tiempo_pausa += resta
                else:
                    agente_nuevo = AgenteTiemposReporte(
                        fecha_local(time_actual), timedelta(0), resta,
                        timedelta(0), 0, 0, 0, 0)
                    agente_fecha.append(agente_nuevo)
                is_unpause = False
                time_actual = None

            if log[EVENT] == 'UNPAUSEALL' or log[EVENT] == 'REMOVEMEMBER':
                time_actual = log[TIME]
                is_unpause = True
        return agente_fecha
Esempio n. 16
0
    def calcular_tiempo_pausa(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula el tiempo de pausa teniendo en cuenta los eventos PAUSEALL,
        UNPAUSEALL y REMOVEMEMBER"""

        eventos_pausa = ['PAUSEALL', 'UNPAUSEALL', 'REMOVEMEMBER']
        agentes_id = [agente.id for agente in agentes]

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_pausa, fecha_inferior, fecha_superior, agentes_id)

        TIME = 1
        EVENT = 2
        for agente in agentes:
            agente_nuevo = None
            is_unpause = False
            time_actual = None

            logs_agente = self._filter_query_por_agente(logs_time, agente.id)

            for log in logs_agente:
                if is_unpause and log[EVENT] == 'PAUSEALL':
                    resta = time_actual - log[TIME]
                    agente_en_lista = list(
                        filter(lambda x: x.agente == agente,
                               self.agentes_tiempo))
                    if agente_en_lista:
                        agente_nuevo = agente_en_lista[0]
                        agente_nuevo._tiempo_pausa += resta
                    else:
                        agente_nuevo = AgenteTiemposReporte(
                            agente, timedelta(0), resta, timedelta(0), 0, 0, 0,
                            0)
                        self.agentes_tiempo.append(agente_nuevo)
                    agente_nuevo = None
                    is_unpause = False
                    time_actual = None
                if log[EVENT] == 'UNPAUSEALL' or log[EVENT] == 'REMOVEMEMBER':
                    time_actual = log[TIME]
                    is_unpause = True
Esempio n. 17
0
    def devuelve_reporte_agente_campana(self, agente, fecha_inicio, fecha_fin, campana):
        self.genera_tiempos_pausa([agente], fecha_inicio, fecha_fin)
        self.calcula_total_intentos_fallidos([agente], fecha_inicio, fecha_fin)
        eventos_llamadas = list(LlamadaLog.EVENTOS_FIN_CONEXION)

        logs_time = LlamadaLog.objects.obtener_agentes_campanas_total(
            eventos_llamadas, fecha_inicio, fecha_fin, [agente.id],
            [campana])
        cantidades_transferencias = LlamadaLog.objects. \
            obtener_cantidades_de_transferencias_recibidas(
                fecha_inicio, fecha_fin, [agente.id], [campana.id])
        for log in logs_time:
            agente_id = int(log[0])
            transferencias = cantidades_transferencias.get(agente_id, {}).get(campana.id, 0)
            if agente_id in self.datos_agentes:
                self.datos_agentes[agente_id].obtener_tiempo_total_llamada_campana(
                    campana, log, transferencias)

        self._genera_tiempos_totales_agentes()
        if len(self.tiempos) == 0:
            return AgenteTiemposReporte(agente.id, 0, 0, 0, 0, 0, 0, 0, 0, 0)

        return self.tiempos[0]
Esempio n. 18
0
    def calcular_tiempo_session(self, agentes, fecha_inferior, fecha_superior):
        """ Calcula el tiempo de session teniendo en cuenta los eventos
        ADDMEMBER, REMOVEMEMBER"""

        eventos_sesion = ['ADDMEMBER', 'REMOVEMEMBER']
        agentes_id = [agente.id for agente in agentes]

        logs_time = ActividadAgenteLog.objects.obtener_tiempos_event_agentes(
            eventos_sesion, fecha_inferior, fecha_superior, agentes_id)

        TIME = 1
        EVENT = 2
        for agente in agentes:

            tiempos_agente = list(
                filter(lambda x: x.agente == agente, self.agentes_tiempo))
            if tiempos_agente:
                agregar_tiempos = False
                tiempos_agente = tiempos_agente[0]
            else:
                agregar_tiempos = True
                tiempos_agente = AgenteTiemposReporte(agente, timedelta(0),
                                                      timedelta(0),
                                                      timedelta(0), 0, 0, 0, 0)

            datos_ultima_sesion = {
                'inicio': None,
                'fin': None,
            }
            logs_agente = self._filter_query_por_agente(logs_time, agente.id)
            for log in reversed(logs_agente):

                if log[EVENT] == 'REMOVEMEMBER':
                    if datos_ultima_sesion['inicio'] is None:
                        # Si la ultima sesion no esta iniciada descarto el REMOVEMEMBER.
                        pass
                    elif datos_ultima_sesion['fin'] is None:
                        # Si no esta finalizada, contabilizo la sesion.
                        datos_ultima_sesion['fin'] = log[TIME]
                        duracion = datos_ultima_sesion[
                            'fin'] - datos_ultima_sesion['inicio']
                        tiempos_agente._tiempo_sesion += duracion
                    # Si la ultima sesion ya esta finalizada, descarto el REMOVEMEMBER

                if log[EVENT] == 'ADDMEMBER':
                    # Si la ultima sesion esta iniciada
                    if datos_ultima_sesion['inicio'] is not None:
                        #  Si no esta finalizada Contabilizo una sesion. y Arranco otra.
                        if datos_ultima_sesion['fin'] is None:
                            # ATENCION: Se podria estimar mejor poniendo un maximo.
                            duracion = log[TIME] - datos_ultima_sesion['inicio']
                            tiempos_agente._tiempo_sesion += duracion
                            datos_ultima_sesion['inicio'] = log[TIME]
                            datos_ultima_sesion['fin'] = None
                        # Si esta finalizada, solamente arranco otra
                        else:
                            datos_ultima_sesion['inicio'] = log[TIME]
                            datos_ultima_sesion['fin'] = None
                    else:
                        datos_ultima_sesion['inicio'] = log[TIME]

                    # Si el ultimo log es ADDMEMBER, se ignora esa sesion.

            if agregar_tiempos and tiempos_agente._tiempo_sesion:
                self.agentes_tiempo.append(tiempos_agente)