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))
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="")