Example #1
0
def get_package_update(uuid):
    # print "Trying to get Package update..."
    data = json.loads(request.get_data().replace("[", "{").replace("]", "}"))
    # print data
    if "delivered" in data:
        database_storage.make_delivered(uuid)
        del packages[uuid]
        # print "uuid:", uuid, "delivered:", data['delivered']
    else:
        # print "response:", data
        lat = float(data['lat'])
        lon = float(data['lon'])
        elevation = int(data['ele'])
        timestamp = data['time']
        coord = (float(lat), float(lon), float(elevation), parse_time(timestamp))
        database_storage.insert_location(uuid, coord[0], coord[1], coord[2], coord[3])
        # print "uuid:", uuid, "lat:", lat, "long:", lon,
        #                "ele:", elevation, "time:", time
        # print package_data
        if packages[uuid] is None:
            print "death by yaegan"
            packages[uuid] = packop.Package(
                coord, database_storage.get_destination_of_package(uuid))
        else:
            packages[uuid].add_point(coord)
    return ''
Example #2
0
def recover():
    global packages
    undelivered = database_storage.get_undelivered_packages()
    for uuid in undelivered:
        convert_coord = lambda coord: coord["coords"] + (coord["ele"], coord["time"])
        start = convert_coord(database_storage.get_first_data(uuid))
        dest = database_storage.get_destination_of_package(uuid)
        packages[uuid] = packop.Package(start, dest)
        coords = database_storage.get_locations(uuid, start[-1])
        for coord in coords:
            packages[uuid].add_point(convert_coord(coord))
Example #3
0
def send_data():
    global begin, initial_data, package_data
    a = request.args.get('dt', "", type=str)
    uuid = request.args.get('uuid', "", type=str)
    if a == 'isValidUUID':
        return jsonify(results=database_storage.is_valid_uuid(uuid))
    elif a == 'initialData':
        return jsonify({"name": database_storage.get_name(uuid),
                        "end_coords": database_storage.get_destination_of_package(uuid),
                        "start_coords": database_storage.get_first_data(uuid)['coords'],
                        "curr_coords": database_storage.get_current_data(uuid)['coords']})
    elif a == 'isDelivered':
        return jsonify(results=database_storage.is_delivered(uuid))
    elif a == 'getNewPoints':
        prev_time = request.args.get('time', 0, type=int)
        return jsonify(results=database_storage.get_locations(uuid, prev_time))
    elif a == 'undeliveredPackages':
        return jsonify(results=database_storage.get_undelivered_packages())
    elif a == 'deliveredPackages':
        return jsonify(results=database_storage.get_delivered_packages())
    elif a == 'getETR':
        try:
            return jsonify(results=packages[uuid].etr())
        except KeyError:
            return jsonify(results=database_storage.get_current_data(uuid)['time'] - time.time())
    elif a == 'getPOI':
        try:
            return jsonify(results=packages[uuid].poi)
        except KeyError:
            return jsonify(results=[])
    elif a == 'getDistance':
        try:
            return jsonify(results=packages[uuid].dist)
        except KeyError:
            return jsonify(results=[])
    return jsonify(results="")