def populate_sitestats(request): """fixture used to populate sitestat to test monthly/weekly analytics gathering """ site1 = Wifisite.query.filter_by(unifi_id="site1").first() now = arrow.now() month_start = now.floor("month") days = (now.ceil("month") - month_start).days for i in range(days): day_key = month_start.replace(days=i).floor("day").naive daystat = Sitestat(site_id=site1.id, date=day_key) daystat.num_visits = 15 daystat.num_likes = 1 daystat.num_checkins = 2 daystat.num_newlogins = 7 daystat.num_repeats = 3 daystat.num_emails = 3 daystat.num_fb = 4 daystat.num_vouchers = 2 daystat.num_phones = 1 db.session.add(daystat) db.session.commit()
def demo_init(): with app.app_context(): from sqlalchemy.exc import OperationalError from flask_security.utils import encrypt_password from unifispot.models import User from unifispot.superadmin.models import Account from unifispot.admin.models import Admin from unifispot.client.models import Client, Wifisite, Landingpage, Voucherdesign from unifispot.guest.models import Guest import arrow from random import randint from unifispot.analytics.models import Sitestat from unifispot.base.utils.helper import get_random_integers from faker import Factory fake = Factory.create() try: account = Account.query.filter_by(id=1).first() except: app.logger.debug( "No Account table Entry found,could be running migration ") else: if not account: #create default admin user enc_pass = encrypt_password('password') account = Account() db.session.add(account) admin_user = Admin(email='*****@*****.**', password=enc_pass, displayname="Admin User1", active=1) admin_user2 = Admin(email='*****@*****.**', password=enc_pass, displayname="Admin User2", active=1) admin_user3 = Admin(email='*****@*****.**', password=enc_pass, displayname="Admin User3", active=1) admin_user.account = account admin_user2.account = account admin_user3.account = account db.session.add(admin_user) db.session.add(admin_user2) db.session.add(admin_user3) client_user1 = Client(email='*****@*****.**', password=enc_pass, displayname="client1", active=1) db.session.add(client_user1) client_user1.account = account site1 = Wifisite(name='Client1 Site1', unifi_id='site1', auth_fb_like=1, timezone="Europe/Copenhagen", auth_method=AUTH_TYPE_ALL, smsauth=1) db.session.add(site1) site1.account = account site1.client = client_user1 landing1 = Landingpage() landing1.site = site1 site1.landingpages.append(landing1) db.session.add(landing1) db.session.commit() site1.default_landing = landing1.id design1 = Voucherdesign() design1.site = site1 db.session.add(design1) db.session.commit() site2 = Wifisite(name='Client1 Site2', unifi_id='site1', auth_fb_like=1, timezone="Europe/Copenhagen", auth_method=AUTH_TYPE_ALL, smsauth=1) db.session.add(site2) site2.account = account site2.client = client_user1 landing2 = Landingpage() landing2.site = site2 site1.landingpages.append(landing2) db.session.add(landing2) db.session.commit() design2 = Voucherdesign() design2.site = site2 db.session.add(design2) site1.default_landing = landing2.id db.session.commit() ##-----------------------Stats for site1 now = arrow.now() month_start = now.floor('month') days = (now.ceil('month') - month_start).days for i in range(days): day_key = month_start.replace(days=i).floor('day').naive daystat = Sitestat(site_id=site1.id, date=day_key) num_visits = randint(10, 50) num_logins = randint(5, num_visits) num_newlogins = randint(5, num_logins) logins = get_random_integers(4, num_logins) daystat.num_visits = num_visits daystat.num_likes = randint(1, 10) daystat.num_checkins = randint(1, 10) daystat.num_newlogins = num_newlogins daystat.num_repeats = num_logins - num_newlogins daystat.num_emails = logins[0] daystat.num_fb = logins[1] daystat.num_vouchers = logins[2] daystat.num_phones = logins[3] db.session.add(daystat) db.session.commit() ##-----------------------Stats for site2 for i in range(days): day_key = month_start.replace(days=i).floor('day').naive daystat = Sitestat(site_id=site2.id, date=day_key) num_visits = randint(10, 50) num_logins = randint(5, num_visits) num_newlogins = randint(5, num_logins) logins = get_random_integers(4, num_logins) daystat.num_visits = num_visits daystat.num_likes = randint(1, 10) daystat.num_checkins = randint(1, 10) daystat.num_newlogins = num_newlogins daystat.num_repeats = num_logins - num_newlogins daystat.num_emails = logins[0] daystat.num_fb = logins[1] daystat.num_vouchers = logins[2] daystat.num_phones = logins[3] db.session.add(daystat) db.session.commit() ##------------------guests for site1 for i in range(100): db.session.add( Guest(firstname=fake.first_name(), lastname=fake.last_name(), email=fake.email())) db.session.commit()
def demo_init(): with app.app_context(): from sqlalchemy.exc import OperationalError from flask_security.utils import encrypt_password from unifispot.models import User from unifispot.superadmin.models import Account from unifispot.admin.models import Admin from unifispot.client.models import Client,Wifisite,Landingpage from unifispot.guest.models import Guest import arrow from random import randint from unifispot.analytics.models import Sitestat from unifispot.base.utils.helper import get_random_integers from faker import Factory fake = Factory.create() try: account = Account.query.filter_by(id=1).first() except : app.logger.debug( "No Account table Entry found,could be running migration ") else: if not account: #create default admin user enc_pass = encrypt_password('password') account = Account() db.session.add(account) admin_user = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User1",active=1) admin_user2 = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User2",active=1) admin_user3 = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User3",active=1) admin_user.account = account admin_user2.account = account admin_user3.account = account db.session.add(admin_user) db.session.add(admin_user2) db.session.add(admin_user3) client_user1 = Client(email='*****@*****.**',password=enc_pass,displayname= "client1",active=1) db.session.add(client_user1) client_user1.account = account site1 = Wifisite(name='Client1 Site1',unifi_id='site1',auth_fb_like=1,timezone="Europe/Copenhagen", auth_method= AUTH_TYPE_ALL,smsauth=1) db.session.add(site1) site1.account = account site1.client = client_user1 landing1 = Landingpage() landing1.site = site1 site1.landingpages.append(landing1) db.session.add(landing1) db.session.commit() site1.default_landing = landing1.id db.session.commit() site2 = Wifisite(name='Client1 Site2',unifi_id='site1',auth_fb_like=1,timezone="Europe/Copenhagen", auth_method= AUTH_TYPE_ALL,smsauth=1) db.session.add(site2) site2.account = account site2.client = client_user1 landing2 = Landingpage() landing2.site = site2 site1.landingpages.append(landing2) db.session.add(landing2) db.session.commit() site1.default_landing = landing2.id db.session.commit() ##-----------------------Stats for site1 now = arrow.now() month_start = now.floor('month') days = (now.ceil('month') - month_start).days for i in range(days): day_key = month_start.replace(days=i).floor('day').naive daystat = Sitestat(site_id=site1.id,date=day_key) num_visits = randint(10,50) num_logins = randint(5,num_visits) num_newlogins = randint(5,num_logins) logins = get_random_integers(4,num_logins) daystat.num_visits = num_visits daystat.num_likes = randint(1,10) daystat.num_checkins = randint(1,10) daystat.num_newlogins = num_newlogins daystat.num_repeats = num_logins - num_newlogins daystat.num_emails = logins[0] daystat.num_fb = logins[1] daystat.num_vouchers = logins[2] daystat.num_phones = logins[3] db.session.add(daystat) db.session.commit() ##-----------------------Stats for site2 for i in range(days): day_key = month_start.replace(days=i).floor('day').naive daystat = Sitestat(site_id=site2.id,date=day_key) num_visits = randint(10,50) num_logins = randint(5,num_visits) num_newlogins = randint(5,num_logins) logins = get_random_integers(4,num_logins) daystat.num_visits = num_visits daystat.num_likes = randint(1,10) daystat.num_checkins = randint(1,10) daystat.num_newlogins = num_newlogins daystat.num_repeats = num_logins - num_newlogins daystat.num_emails = logins[0] daystat.num_fb = logins[1] daystat.num_vouchers = logins[2] daystat.num_phones = logins[3] db.session.add(daystat) db.session.commit() ##------------------guests for site1 for i in range(100): db.session.add(Guest(firstname=fake.first_name(),lastname=fake.last_name(),email=fake.email())) db.session.commit()
def populate_sitestats(request): '''fixture used to populate sitestat to test monthly/weekly analytics gathering ''' site1 = Wifisite.query.filter_by(unifi_id='site1').first() now = arrow.now() month_start = now.floor('month') days = (now.ceil('month') - month_start).days for i in range(days): day_key = month_start.replace(days=i).floor('day').naive daystat = Sitestat(site_id=site1.id, date=day_key) daystat.num_visits = 15 daystat.num_likes = 1 daystat.num_checkins = 2 daystat.num_newlogins = 7 daystat.num_repeats = 3 daystat.num_emails = 3 daystat.num_fb = 4 daystat.num_vouchers = 2 daystat.num_phones = 1 db.session.add(daystat) db.session.commit()