Пример #1
0
def test_update_daily_stat1(session, client):
    '''test with empty tracks 

    '''
    site1 = Wifisite.query.filter_by(id=1).first()
    now = arrow.utcnow()
    update_daily_stat(site1, now)

    assert 1 == Sitestat.query.count(), 'Sitestat is not created '
Пример #2
0
def test_update_daily_stat2(session, populate_analytics_tracks):
    '''Check if time validation is fine

    '''
    site1 = Wifisite.query.filter_by(id=1).first()
    now = arrow.utcnow()
    update_daily_stat(site1, now)

    sitestat = Sitestat.query.get(1)
    assert 20 == sitestat.num_visits
Пример #3
0
def rebuild_monthly_stats():
    from unifispot.core.models import User, Account, Admin, Client, Wifisite, Landingpage
    from unifispot.modules.analytics.methods import update_daily_stat
    site1 = Wifisite.query.get(1)
    now = arrow.now()
    month_start = now.floor('month')
    days = (now.ceil('month') - month_start).days
    for d in range(days):
        day_start = month_start.replace(days=d).floor('day')
        logger.warn('-------Generating analytics data for :%s' % day_start)
        update_daily_stat(site1, day_start)
Пример #4
0
def test_client_nositeid(session, populate_analytics_logins,
                         populate_analytics_logins_site3):

    client = loggin_as_client()
    site1 = Wifisite.query.filter_by(id=1).first()
    site3 = Wifisite.query.filter_by(id=3).first()
    now = arrow.utcnow()
    update_daily_stat(site1, now)
    update_daily_stat(site3, now)

    resp = client.get('/s/analytics/api/').json

    assert resp['maxsocial'] == 20
Пример #5
0
def test_update_daily_stat3(session, populate_analytics_logins):
    '''Check if stat counting is fine

    '''
    site1 = Wifisite.query.filter_by(id=1).first()
    now = arrow.utcnow()
    update_daily_stat(site1, now)

    sitestat = Sitestat.query.get(1)
    assert 40 == sitestat.num_visits
    assert 20 == sitestat.num_newlogins
    assert 20 == sitestat.num_repeats
    assert {'auth_email': 20, 'auth_facebook': 20, 'fbcheckedin': 20,
            'fbliked': 10,'newguest': 20, u'num_visits': 40}\
                         == sitestat.login_stat
Пример #6
0
def init_demo():
    with app.app_context():
        from sqlalchemy.exc import OperationalError
        from flask_security.utils import encrypt_password
        from unifispot.core.models import User, Account, Admin, Client, Wifisite, Landingpage
        from unifispot.core.guestutils import init_track, assign_guest_entry
        from unifispot.modules.analytics.methods import update_daily_stat
        from tests.helpers import randomMAC, randomGuestEmailForm
        from random import randint

        account = Account.query.filter_by(id=1).first()
        enc_pass = encrypt_password('password')

        client1 = Client.query.filter_by(email='*****@*****.**').first()
        if not client1:
            #add a client
            client1 = Client(email='*****@*****.**',
                             password=enc_pass,
                             displayname="Client User",
                             active=1)
            client1.account_id = account.id
            client1.save()

        site1 = Wifisite.query.get(1)
        if not site1:
            site1 = Wifisite(name='Site1', sitekey='site1')
            site1.client_id = client1.id
            site1.account_id = account.id
            site1.save()
            landing1 = Landingpage()
            landing1.siteid = site1.id
            landing1.save()

        now = arrow.now()
        month_start = now.replace(days=-30)
        days = (now - month_start).days
        for d in range(days):
            day_start = month_start.replace(days=d).floor('day')
            logger.warn('-------Generating data for :%s' % day_start)
            for i in range(randint(5, 10)):
                track = init_track(site1,
                                   guestmac=randomMAC(),
                                   apmac=randomMAC())
                track.timestamp = day_start.replace(minutes=+i * 1).naive
                track.loginstat = {'num_visits': 1, 'auth_email': 1}
                track.save()
                if i % 2:
                    f = randomGuestEmailForm()
                    g = assign_guest_entry(site1, track, f)
                    g.createdat = day_start.replace(minutes=+i * 1).naive
                    g.save()
                track.save()
                logger.warn('track added for email ID;%s for :%s' %
                            (track.id, day_start))

            #create random
            #half of them new user
            for i in range(randint(5, 10)):
                track = init_track(site1,
                                   guestmac=randomMAC(),
                                   apmac=randomMAC())
                track.timestamp = day_start.replace(minutes=+i * 1).naive
                track.loginstat = {
                    'num_visits': 1,
                    'auth_facebook': 1,
                    'fbcheckedin': 1
                }
                track.save()
                if i % 2:
                    g = assign_guest_entry(site1, track, f)
                    g.createdat = day_start.replace(minutes=+i * 1).naive
                    g.save()
                    track.updatestat('fbliked', 1)
                    track.save()
                track.save()
                logger.warn('track added for FB ID;%s for :%s' %
                            (track.id, day_start))
            update_daily_stat(site1, day_start)