Example #1
0
    def testCallSync(self):
        self.deleteAllLogs()
        self.assertEqual(self.getCallLogCount(), 0)
        self.assertEqual(self.getCallCount(), 0)

        # Test Create
        call = Call()
        self.setRandomCallValues(call)
        call.save()

        sleep(1)
        self.assertEqual(self.getCallLogCount(), 1)
        self.assertEqual(self.getCallCount(), 1)

        calllog = CallLog.get(call.couch_id)
        self.checkFieldValues(calllog, call, Call._migration_get_fields())
        self.assertTrue(CallLog.get_db().get_rev(calllog._id).startswith('2-'))

        # Test Update
        self.setRandomCallValues(call)
        call.save()

        sleep(1)
        self.assertEqual(self.getCallLogCount(), 1)
        self.assertEqual(self.getCallCount(), 1)
        callog = CallLog.get(call.couch_id)
        self.checkFieldValues(callog, call, Call._migration_get_fields())
        self.assertTrue(CallLog.get_db().get_rev(callog._id).startswith('3-'))
Example #2
0
def get_data(ids):
    """
    returns the data in the format:
    {
        '2015-03': {
            'domain1': {
                'KOOKOO': {'calls': 40, 'minutes': 45}
            },
            'domain2': {
                'KOOKOO': {'calls': 20, 'minutes': 25}
                'TELERIVET': {'calls': 5, 'minutes': 0}
            }
        }
    }
    """
    data = {}
    for doc in iter_docs(CallLog.get_db(), ids):
        call = CallLog.wrap(doc)
        month_data = get_month_data(data, call.date)
        domain_data = get_domain_data(month_data, call.domain)
        backend_api = get_backend_api(call)
        backend_data = get_backend_data(domain_data, backend_api)
        backend_data['calls'] += 1
        duration = (call.duration or 0) / 60.0
        duration = int(ceil(duration))
        backend_data['minutes'] += duration
    return data
Example #3
0
def get_data(ids, timezone=None):
    """
    returns the data in the format:
    {
        '2015-03': {
            'domain1': {
                'KOOKOO': {
                    'I': {'calls': 2, 'minutes': 3},
                    'O': {'calls': 40, 'minutes': 45},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            },
            'domain2': {
                'KOOKOO': {
                    'I': {'calls': 1, 'minutes': 1},
                    'O': {'calls': 20, 'minutes': 25},
                    '?': {'calls': 0, 'minutes': 0},
                 },
                'TELERIVET': {
                    'I': {'calls': 10, 'minutes': 0},
                    'O': {'calls': 0, 'minutes': 0},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            }
        }
    }
    """
    data = {}
    for doc in iter_docs(CallLog.get_db(), ids):
        call = CallLog.wrap(doc)
        date = get_naive_user_datetime(call.date, timezone=timezone)
        month_data = get_month_data(data, date)
        domain_data = get_domain_data(month_data, call.domain)
        backend_api = get_backend_api(call)
        backend_data = get_backend_data(domain_data, backend_api)
        direction = get_direction(call)
        backend_data[direction]['calls'] += 1
        duration = (call.duration or 0) / 60.0
        duration = int(ceil(duration))
        backend_data[direction]['minutes'] += duration
    return data
Example #4
0
def get_data(ids, timezone=None):
    """
    returns the data in the format:
    {
        '2015-03': {
            'domain1': {
                'KOOKOO': {
                    'I': {'calls': 2, 'minutes': 3},
                    'O': {'calls': 40, 'minutes': 45},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            },
            'domain2': {
                'KOOKOO': {
                    'I': {'calls': 1, 'minutes': 1},
                    'O': {'calls': 20, 'minutes': 25},
                    '?': {'calls': 0, 'minutes': 0},
                 },
                'TELERIVET': {
                    'I': {'calls': 10, 'minutes': 0},
                    'O': {'calls': 0, 'minutes': 0},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            }
        }
    }
    """
    data = {}
    for doc in iter_docs(CallLog.get_db(), ids):
        call = CallLog.wrap(doc)
        date = get_naive_user_datetime(call.date, timezone=timezone)
        month_data = get_month_data(data, date)
        domain_data = get_domain_data(month_data, call.domain)
        backend_api = get_backend_api(call)
        backend_data = get_backend_data(domain_data, backend_api)
        direction = get_direction(call)
        backend_data[direction]['calls'] += 1
        duration = (call.duration or 0) / 60.0
        duration = int(ceil(duration))
        backend_data[direction]['minutes'] += duration
    return data
    def delete_models(self, delete_interval):
        print 'Deleting SMSLogs...'
        count = iter_bulk_delete_with_doc_type_verification(SMSLog.get_db(), self.get_sms_couch_ids(), 'SMSLog',
            wait_time=delete_interval, max_fetch_attempts=5)
        print 'Deleted %s documents' % count

        print 'Deleting CallLogs...'
        count = iter_bulk_delete_with_doc_type_verification(CallLog.get_db(), self.get_call_couch_ids(), 'CallLog',
            wait_time=delete_interval, max_fetch_attempts=5)
        print 'Deleted %s documents' % count

        print 'Deleting ExpectedCallbackEventLogs...'
        count = iter_bulk_delete_with_doc_type_verification(ExpectedCallbackEventLog.get_db(),
            self.get_callback_couch_ids(), 'ExpectedCallbackEventLog', wait_time=delete_interval,
            max_fetch_attempts=5)
        print 'Deleted %s documents' % count

        print 'Deleting LastReadMessages...'
        count = iter_bulk_delete_with_doc_type_verification(LastReadMessage.get_db(),
            self.get_lastreadmessage_couch_ids(), 'LastReadMessage', wait_time=delete_interval,
            max_fetch_attempts=5)
        print 'Deleted %s documents' % count
Example #6
0
    def delete_models(self, delete_interval):
        print('Deleting SMSLogs...')
        count = iter_bulk_delete_with_doc_type_verification(SMSLog.get_db(), self.get_sms_couch_ids(), 'SMSLog',
            wait_time=delete_interval, max_fetch_attempts=5)
        print('Deleted %s documents' % count)

        print('Deleting CallLogs...')
        count = iter_bulk_delete_with_doc_type_verification(CallLog.get_db(), self.get_call_couch_ids(), 'CallLog',
            wait_time=delete_interval, max_fetch_attempts=5)
        print('Deleted %s documents' % count)

        print('Deleting ExpectedCallbackEventLogs...')
        count = iter_bulk_delete_with_doc_type_verification(ExpectedCallbackEventLog.get_db(),
            self.get_callback_couch_ids(), 'ExpectedCallbackEventLog', wait_time=delete_interval,
            max_fetch_attempts=5)
        print('Deleted %s documents' % count)

        print('Deleting LastReadMessages...')
        count = iter_bulk_delete_with_doc_type_verification(LastReadMessage.get_db(),
            self.get_lastreadmessage_couch_ids(), 'LastReadMessage', wait_time=delete_interval,
            max_fetch_attempts=5)
        print('Deleted %s documents' % count)
Example #7
0
 def delete_call_logs(self, domain):
     calls = CallLog.by_domain_asc(domain).all()
     if calls:
         CallLog.get_db().bulk_delete([
             call.to_json() for call in calls
         ])