Пример #1
0
def checkin_bike():
    db = sstoreclient.sstoreclient()
    proc = 'CheckinBike'
    user = int(request.form['user_id'])
    station = int(request.form['station_id'])
    args = [user, station]
    try:
        # Get data from S-Store.
        data = db.call_proc(proc,args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        nouserstr = 'Rider: ' + str(user) + ' does not exist'
        nobikestr = 'Rider ' + str(user) + ' does not have a bike checked out'
        nodockstr = 'Rider: ' + str(user) + ' was unable to checkin a bike'
        if re.search(nouserstr,data['error']):
            return '{}', 401 # Unauthorized
        elif re.search(nobikestr,data['error']):
            return '{}', 403 # Forbidden
        elif re.search(nodockstr,data['error']):
            return '{}', 503 # Service Unavailable
        else:
            log_procerr(proc,str(data['error']))
            return '{}', 500
    # Success case
    else:
        return jsonify(data['data'])
Пример #2
0
def send_bike_position():
    db = sstoreclient.sstoreclient()
    proc = 'RideBike'
    user = int(request.form['user_id'])
    lat = float(request.form['lat'])
    lon = float(request.form['lon'])
    args = [user, lat, lon]
    try:
        # Get data from S-Store.
        data = db.call_proc(proc, args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc, str(e)) 
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        nouserstr = 'Rider: ' + str(user) + ' does not exist'
        nobikestr = 'Rider: ' + str(user) + ' does not have a bike checked out'
        if re.search(nouserstr,data['error']):
            return '{}', 401 # Unauthorized
        elif re.search(nobikestr,data['error']):
            return '{}', 403 # Forbidden
        else:
            log_procerr(proc,str(data['error']))
            return '{}', 500
    # Success case
    else:
        return jsonify(data['data'])
Пример #3
0
def check_login():
    db = sstoreclient.sstoreclient()
    proc = 'FindUser'
    args = [request.form['user_name']]
    try:
        # Get data from S-Store.
        data = db.call_proc(proc,args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '{}', 500
    # Success case
    else:
        # TODO: Figure out what makes sense in the schema to use as a unique
        # token for login purposes.
        users = data['data']
        if len(users) > 0:
            return jsonify(subdict(data['data'][0],'USER_ID'))
        else:
            return '{}', 404
Пример #4
0
def get_anomalies():
    db = sstoreclient.sstoreclient()
    proc = 'GetAnomalies'
    try:
        data = db.call_proc(proc)
    except Exception as e:
        log_procerr(proc,str(e))
        return '{}', 500
    return jsonify({"anomalies" : data['data']})
Пример #5
0
def all_users():
    db = sstoreclient.sstoreclient()
    proc = 'Users'
    try:
        data = db.call_proc(proc)
    except Exception as e:
        log_procerr(proc,str(e))
        return '{}', 500
    return jsonify({"users" : data['data']})
Пример #6
0
def all_bikes():
    db = sstoreclient.sstoreclient()
    proc = 'Bikes'
    try:
        data = db.call_proc(proc)
    except Exception as e:
        log_procerr(proc,str(e))
        return '{}', 500
    return jsonify({"bikes" : data['data']})
Пример #7
0
def get_userstats():
    db = sstoreclient.sstoreclient()
    proc = 'Users'
    try:
        # Get data from S-Store.
        data = db.call_proc(proc)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '?'
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '?'
    # Success case
    else:
        return len(data['data'])
Пример #8
0
def active_bikes():
    db = sstoreclient.sstoreclient()
    proc = 'UserLocations'
    try:
        # Get data from S-Store.
        data = db.call_proc(proc)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '{}', 500
    # Success case
    else:
        return jsonify({"bikes" : data['data']})
Пример #9
0
def user_signup():
    db = sstoreclient.sstoreclient()
    proc = 'SignUpName'
    fname = request.form['first_name']
    lname = request.form['last_name']
    args = [fname,lname]
    try:
        # Get data from S-Store.
        data = db.call_proc(proc,args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '{}', 500
    # Success case
    else:
        users = data['data']
        return jsonify(users[0])
Пример #10
0
def get_bikestats():
    db = sstoreclient.sstoreclient()
    proc = 'Bikes'
    try:
        # Get data from S-Store.
        data = db.call_proc(proc)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '?'
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '?'
    # Success case
    else:
        bikes = data['data']
        active = 0
        for bike in bikes:
            if bike['CURRENT_STATUS'] == 2:
                active = active + 1
        return len(data['data']), active
Пример #11
0
def bike_info(user_id):
    db = sstoreclient.sstoreclient()
    proc = 'GetBikeStatus'
    args = [user_id]
    try:
        # Get data from S-Store.
        data = db.call_proc(proc,args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '{}', 500
    # Success case
    else:
        bikedata = data['data']
        if len(bikedata) > 0:
            return jsonify(bikedata[0])
        else:
            return '{}', 404
Пример #12
0
def user_info(user_name):
    db = sstoreclient.sstoreclient()
    proc = 'FindUser'
    args = [urllib2.unquote(user_name)]
    print args
    try:
        # Get data from S-Store.
        data = db.call_proc(proc,args)
    # Failure cases
    except Exception as e:
        # Client failed to connect to or get data from S-Store.
        log_procerr(proc,str(e))
        return '{}', 500
    if not data['success']:
        # DB procedure execution failed.
        log_procerr(proc,str(data['error']))
        return '{}', 500
    # Success case
    else:
        userdata = data['data']
        if len(userdata) > 0:
            return jsonify(userdata[0])
        else:
            return '{}', 404