コード例 #1
0
        def decorated_function(*args, **kwargs):
            res = request.get_json(force=True)
            if "location" in res and "lat"in res["location"] and "lng" in res["location"]:
                lat = res["location"]["lat"]
                lng = res["location"]["lng"]

                if Location.isValid(lat,lng):
                    return f(lat=lat, lng=lng)
                return jsonify(info="Location coordinates not acceptable; Latitude (S-N): -90 to +90; Longitude (W-E): -180 to +180"),400
コード例 #2
0
def suppose_assignment():
    # import all not taken deliveries
    now = datetime.datetime.now()

    cond = {
        "conditions" :  {
            # "start" : datetime.datetime(now.year,now.month,now.day,0,0,0).strftime("%Y-%m-%d %H:%M:%S"),
            # "end" : (datetime.datetime(now.year,now.month,now.day,0,0,0) + datetime.timedelta(days=1, seconds=-1)).strftime("%Y-%m-%d %H:%M:%S"),
            "state" : "not assigned"
        }
    }

    deliveries = get_all_deliveries(company_id=session["user"]["company_id"], conditions=cond , return_obj=True, get_locations=True)

    # import drivers
    drivers = get_all_drivers(session["user"]["company_id"], return_obj=True, vehicles=True)


    suggestions = []
    no_registered = []

    for delivery in deliveries:
        best_distance = None
        best_driver = None

        for driver in drivers:
            if is_assignable(driver, delivery):
                distance = Location.getDistance(delivery.getSenderLocation(), driver.getLocation())
                if best_distance is not None:
                    if distance["distance"]["value"]< best_distance["distance"]["value"] :
                        best_distance = distance
                        best_driver = driver
                else:
                    best_distance = distance
                    best_driver = driver


        if best_distance is None or best_driver is None:
            no_registered.append(delivery)

        else :
            best = {"delivery" : delivery, "distance": best_distance["distance"], "duration" : best_distance["duration"]}
            append_suggestion(suggestions, best_driver, best)

            #update driver position
            best_driver.update_location(**delivery.getSenderLocation())


    return jsonify(suggestions=suggestions),200
コード例 #3
0
def address_to_geocode():
    addr = "850 Avenue de Londres, Z.A.C du Grand Saint Charles, 66000 Perpignan, FR"

    geo = Location.getGeocode(addr=addr)
    print(geo)
コード例 #4
0
def geocode_to_address():
    addr = Location.getGeocode(lat=52.370402, lng=4.894948)
    print(addr)