Ejemplo n.º 1
0
def update_positions(request):
    """ View for calls by ISRProxy backend on taxi positions updates. """
    raw_data = request.raw_post_data
    logging.info("isrproxy update_positions: %s" % raw_data)
    update_positions_data = simplejson.loads(raw_data)

    # redirect update to dev server in production environment
    if not settings.DEV:
        dev_positions = filter(lambda p: p.get("Operator_ID") == WB_DEV_OPERATOR_ID, update_positions_data)
        if dev_positions:
            deferred.defer(safe_fetch, url="http://dev.latest.waybetter-app.appspot.com/fleet/isrproxy/update/positions/", payload=simplejson.dumps(dev_positions), method=POST, notify=False)
            update_positions_data = filter(lambda p: p.get("Operator_ID") != WB_DEV_OPERATOR_ID, update_positions_data)


    ride_positions = []
    for rp_data in update_positions_data:
        station_id = rp_data.get("Operator_ID")
        taxi_id = rp_data.get("Vehicle_ID")
        lat = rp_data.get("Lat")
        lon = rp_data.get("Lon")
        timestamp = rp_data.get("Timestamp")

        ride_uuid = ISRProxy.get_taxi_assignment(taxi_id, station_id)

        if all([station_id, ride_uuid, taxi_id, lat, lon, timestamp]):
            timestamp = dateutil_parser.parse(timestamp)
            timestamp = normalize_naive_israel_dt(timestamp)
            ride_positions.append(TaxiRidePosition(station_id, taxi_id, ride_uuid, lat, lon, timestamp))

    fleet_manager.update_positions(ride_positions)
    return HttpResponse("OK")
Ejemplo n.º 2
0
def update_status(request):
    """ View for calls by ISRProxy backend on ride status updates. """
    raw_data = request.raw_post_data
    logging.info("isrproxy update_status: %s" % raw_data)

    update_status_data = simplejson.loads(raw_data)

    # redirect update to dev server in production environment
    if update_status_data.get('Operator_ID') == WB_DEV_OPERATOR_ID and not settings.DEV:
        deferred.defer(safe_fetch, url="http://dev.latest.waybetter-app.appspot.com/fleet/isrproxy/update/status/", payload=raw_data, method=POST, notify=False)
        return HttpResponse("OK")

    fmr = ISRProxy._create_fmr(update_status_data)
    fleet_manager.update_ride(fmr)

    mcns = "ga_isrproxy_ride_updates"
    getkey = lambda fmr: str(fmr.id)

    now = datetime.datetime.now()
    last_update_dt = memcache.get(getkey(fmr), namespace=mcns)
    val = (now - last_update_dt).seconds if last_update_dt else 0
    memcache.set(getkey(fmr), now, namespace=mcns)

   # Log status position as a position update
    if fmr.lat and fmr.lon:
        taxi_position = TaxiRidePosition(fmr.station_id, fmr.taxi_id, fmr.id, fmr.lat, fmr.lon, fmr.timestamp)
        fleet_manager.update_positions([taxi_position])
    else:
        logging.warning("ride update with no location info received: %s" % fmr.serialize())

    ga_track_event(request, "isr", "update_ride", fmr.id)
    ga_track_event(request, "isr", fmr.raw_status, fmr.id, val)

    return HttpResponse("OK")
Ejemplo n.º 3
0
def update_status(request):
    """ View for calls by ISRProxy backend on ride status updates. """
    raw_data = request.raw_post_data
    logging.info("isrproxy update_status: %s" % raw_data)

    update_status_data = simplejson.loads(raw_data)

    # redirect update to dev server in production environment
    if update_status_data.get(
            'Operator_ID') == WB_DEV_OPERATOR_ID and not settings.DEV:
        deferred.defer(
            safe_fetch,
            url=
            "http://dev.latest.waybetter-app.appspot.com/fleet/isrproxy/update/status/",
            payload=raw_data,
            method=POST,
            notify=False)
        return HttpResponse("OK")

    fmr = ISRProxy._create_fmr(update_status_data)
    fleet_manager.update_ride(fmr)

    mcns = "ga_isrproxy_ride_updates"
    getkey = lambda fmr: str(fmr.id)

    now = datetime.datetime.now()
    last_update_dt = memcache.get(getkey(fmr), namespace=mcns)
    val = (now - last_update_dt).seconds if last_update_dt else 0
    memcache.set(getkey(fmr), now, namespace=mcns)

    # Log status position as a position update
    if fmr.lat and fmr.lon:
        taxi_position = TaxiRidePosition(fmr.station_id, fmr.taxi_id, fmr.id,
                                         fmr.lat, fmr.lon, fmr.timestamp)
        fleet_manager.update_positions([taxi_position])
    else:
        logging.warning("ride update with no location info received: %s" %
                        fmr.serialize())

    ga_track_event(request, "isr", "update_ride", fmr.id)
    ga_track_event(request, "isr", fmr.raw_status, fmr.id, val)

    return HttpResponse("OK")
Ejemplo n.º 4
0
def update_positions(request):
    """ View for calls by ISRProxy backend on taxi positions updates. """
    raw_data = request.raw_post_data
    logging.info("isrproxy update_positions: %s" % raw_data)
    update_positions_data = simplejson.loads(raw_data)

    # redirect update to dev server in production environment
    if not settings.DEV:
        dev_positions = filter(
            lambda p: p.get("Operator_ID") == WB_DEV_OPERATOR_ID,
            update_positions_data)
        if dev_positions:
            deferred.defer(
                safe_fetch,
                url=
                "http://dev.latest.waybetter-app.appspot.com/fleet/isrproxy/update/positions/",
                payload=simplejson.dumps(dev_positions),
                method=POST,
                notify=False)
            update_positions_data = filter(
                lambda p: p.get("Operator_ID") != WB_DEV_OPERATOR_ID,
                update_positions_data)

    ride_positions = []
    for rp_data in update_positions_data:
        station_id = rp_data.get("Operator_ID")
        taxi_id = rp_data.get("Vehicle_ID")
        lat = rp_data.get("Lat")
        lon = rp_data.get("Lon")
        timestamp = rp_data.get("Timestamp")

        ride_uuid = ISRProxy.get_taxi_assignment(taxi_id, station_id)

        if all([station_id, ride_uuid, taxi_id, lat, lon, timestamp]):
            timestamp = dateutil_parser.parse(timestamp)
            timestamp = normalize_naive_israel_dt(timestamp)
            ride_positions.append(
                TaxiRidePosition(station_id, taxi_id, ride_uuid, lat, lon,
                                 timestamp))

    fleet_manager.update_positions(ride_positions)
    return HttpResponse("OK")