예제 #1
0
def cmd_getconfig(data):
    if 'cacheid' in data:
        device = database.getDeviceId(data['cacheid'])
        email = database.getDeviceAccount(device)
    elif 'token' in data:
        email = database.verifyToken(data['token'])
    else:
        email = None

    if email is None:
        return {
            'config': None,
            'characters': None,
        }

    info = database.getAccountInfo(email)

    chars = {}
    for slot in database.getSlots(email):
        prof = database.getProfile(email, slot['id'])
        if prof:
            c = prof.get('character')
            if c is not None:
                chars[slot['id']] = c

    return {
        'config': info['config'],
        'characters': chars,
    }
예제 #2
0
def cmd_profileLoad(data):
    device = database.getDeviceId(data['cacheid'])
    email = database.getDeviceAccount(device)
    if email is None:
        return {
            'error': 'noaccount',
            'msg': 'No analytics account associated with this device.'
        }

    return {'data': database.getProfile(email, data['slot'])}
예제 #3
0
def cmd_profileSave(data):
    device = database.getDeviceId(data['cacheid'])
    email = database.getDeviceAccount(device)
    if email is None:
        return {
            'error': 'noaccount',
            'msg': 'No analytics account associated with this device.'
        }

    pd = data['data']
    ts = data['ts']
    database.putProfile(email, data['slot'], pd, ts)
    return {}
예제 #4
0
def cmd_analytics(data):
    maxid = None
    device = database.getDeviceId(data['cacheid'])

    for rec in data['events']:
        if rec['msg'] == 'device-ready' and rec['uuid']:
            database.groupDevices(data['cacheid'], rec['uuid'])
        database.reportAnalyticsEvent(data['cacheid'], rec)

        id = rec['msgid']
        if maxid is None or id > maxid:
            maxid = id

    return {
        'upto_id': maxid,
    }
예제 #5
0
def cmd_getlinkcode(data):
    device = database.getDeviceId(data['cacheid'])
    code = database.getLinkCode(device)
    return {
        'code': code,
    }
def fakemsg(msg):
    global msgid
    msg['msgid'] = msgid
    msgid += 1
    msg['ts'] = ts
    database.reportAnalyticsEvent(cacheid, msg)


# students
for slot in range(1, 7):
    cacheid = '20191201-120000-%08d' % slot

    cur.execute('delete from analytics where cacheid=%s', (cacheid, ))

    if linkemail:
        devid = database.getDeviceId(cacheid)
        code = database.getLinkCode(devid)
        if database.linkDevice(code, linkemail) == None:
            print('failed to link device')
            exit(1)
        print('linked cacheid %s to email %s' % (cacheid, linkemail))
        print()

    ts = time.time() - 86400 * (30 + random.random())
    msgid = 1
    diff = [0] * (26 * 2)

    # days
    for _ in range(30):

        # sessions