Example #1
0
def jump():
    if not hasattr(request, 'json'):
        print 'Aborting: request does not have json data.'
        abort(400)
    elif 'source' not in request.json or 'destinations' not in request.json:
        print 'Aborting: request does not have source and\or destination.'
        abort(400)

    highonly = False
    nohigh = False

    if 'avoidance' in request.json:
        if request.json['avoidance'] == 'high':
            nohigh = True
        elif request.json['avoidance'] == 'highonly':
            highonly = True
        elif request.json['avoidance'] != 'none':
            print 'Aborting: unknown avoidance value: %s' % request.json[
                'avoidance']

    g = None
    source = location_lookup(request.json['source'])
    results = []

    for dest in request.json['destinations']:
        try:
            destid = location_lookup(dest)
        except LookupError:
            print 'Did not find ' + dest
            results.append({'destination': dest, 'jumps': -1})
            continue

        avoidance_key = ''
        if highonly:
            avoidance_key = '_highonly'
        elif nohigh:
            avoidance_key = '_nohigh'

        cache_key = str(source) + '_' + str(destid) + avoidance_key

        cv = cache.get(cache_key)
        if cv is not None:
            results.append({'destination': dest, 'jumps': cv})
        else:
            if g is None:
                g = SystemGraph(highonly, nohigh)

            try:
                jumps = len(g.route(source, destid)) - 1
                cache.set(cache_key, jumps)
                results.append({'destination': dest, 'jumps': jumps})
            except LookupError:
                results.append({'destination': dest, 'jumps': -1})

    return jsonify(source=request.json['source'], destinations=results)
Example #2
0
def jump():
    if not hasattr(request, 'json'):
        print 'Aborting: request does not have json data.'
        abort(400)
    elif 'source' not in request.json or 'destinations' not in request.json:
        print 'Aborting: request does not have source and\or destination.'
        abort(400)

    highonly = False
    nohigh = False

    if 'avoidance' in request.json:
        if request.json['avoidance'] == 'high':
            nohigh = True
        elif request.json['avoidance'] == 'highonly':
            highonly = True
        elif request.json['avoidance'] != 'none':
            print 'Aborting: unknown avoidance value: %s' % request.json['avoidance']

    g = None
    source = location_lookup(request.json['source'])
    results = []

    for dest in request.json['destinations']:
        try:
            destid = location_lookup(dest)
        except LookupError:
            print 'Did not find ' + dest
            results.append({ 'destination': dest, 'jumps': -1 })
            continue

        avoidance_key = ''
        if highonly:
            avoidance_key = '_highonly'
        elif nohigh:
            avoidance_key = '_nohigh'

        cache_key = str(source) + '_' + str(destid) + avoidance_key

        cv = cache.get(cache_key)
        if cv is not None:
            results.append({ 'destination': dest, 'jumps': cv })
        else:
            if g is None:
                g = SystemGraph(highonly, nohigh)

            try:
                jumps = len(g.route(source, destid)) - 1
                cache.set(cache_key, jumps)
                results.append({ 'destination': dest, 'jumps': jumps })
            except LookupError:
                results.append({ 'destination': dest, 'jumps': -1 })

    return jsonify(source=request.json['source'], destinations=results)
Example #3
0
def jump_ii(source, destination, highonly, nohigh):
    g = SystemGraph(highonly, nohigh)
    jumps = g.distance(source, destination)
    return jsonify(jumps=jumps)
Example #4
0
def route_ii(source, destination, highonly, nohigh):
    g = SystemGraph(highonly, nohigh)
    route = g.route(source, destination)
    route = sysid_list_to_object(route)
    count = len(route) - 1
    return jsonify(route=route, count=count)
Example #5
0
def jump_ii(source, destination, highonly, nohigh):
    g = SystemGraph(highonly, nohigh)
    jumps = g.distance(source, destination)
    return jsonify(jumps=jumps)
Example #6
0
def route_ii(source, destination, highonly, nohigh):
    g = SystemGraph(highonly, nohigh)
    route = g.route(source, destination)
    route = sysid_list_to_object(route)
    count = len(route) - 1
    return jsonify(route=route, count=count)