Beispiel #1
0
def get_place_trip_geoquery(geojson):
    if geojson is not None:
        place_gq = estg.GeoQuery(loc_field_list=['data.location'],
                                 poly_region=geojson)
        trip_gq = estg.GeoQuery(
            loc_field_list=['data.start_loc', 'data.end_loc'],
            poly_region=geojson)
    else:
        place_gq = None
        trip_gq = None
    return (place_gq, trip_gq)
def count_query():
    edb.pm_address = request.json['pm_address']
    # Dummy id used as a placeholder. It must be consistent for each user but
    # otherwise doesn't matter. An optimization would remove all instance of user_uuid.
    user_uuid = request.json['uuid']
    query = request.json['query']
    query_obj = saq.AE(1)
    cost = query_obj.generate_diff_priv_cost(query['alpha'], query['offset'])

    # Try and deduce from the privacy budget
    available_budget = safmt.deduct_budget(edb.pm_address, cost)
    if not available_budget:
        # Query could not complete, no budget remaining
        return {"success": False}

    start_time = query['start_ts']
    end_time = query['end_ts']
    time_query = estt.TimeQuery("data.ts", start_time, end_time)
    region = query['sel_region']
    if region is None:
        geo_query = None
    else:
        geo_query = estg.GeoQuery(["data.loc"], region)

    loc_entry_list = esda.get_entries(esda.CLEANED_LOCATION_KEY, user_uuid, 
                                    time_query=time_query, geo_query=geo_query)
    convert_objectid_to_string(loc_entry_list)
    if len(loc_entry_list) > 0:
        ret_val = 1
    else:
        ret_val = 0
    return {"success" : True, "results": ret_val}
Beispiel #3
0
def range_mode_heatmap(user_uuid, modes, time_query, region):

    if region is None:
        geo_query = None
    else:
        geo_query = estg.GeoQuery(["data.loc"], region)

    extra_query_list = []
    if modes is not None:
        mode_enum_list = [ecwm.MotionTypes[mode] for mode in modes]
        extra_query_list.append(esdlq.get_mode_query(mode_enum_list))

    loc_entry_list = esda.get_entries(esda.CLEANED_LOCATION_KEY,
                                      user_id=user_uuid,
                                      time_query=time_query,
                                      geo_query=geo_query,
                                      extra_query_list=extra_query_list)
    return {"lnglat": [e.data.loc.coordinates for e in loc_entry_list]}
Beispiel #4
0
def range_mode_heatmap(modes, from_ld, to_ld, region):
    time_query = esttc.TimeComponentQuery("data.local_dt", from_ld, to_ld)

    if region is None:
        geo_query = None
    else:
        geo_query = estg.GeoQuery(["data.loc"], region)

    if modes is None:
        extra_query_list = None
    else:
        mode_enum_list = [ecwm.MotionTypes[mode] for mode in modes]
        extra_query_list = [esdlq.get_mode_query(mode_enum_list)]

    loc_entry_list = esda.get_entries(esda.CLEANED_LOCATION_KEY,
                                      user_id=None,
                                      time_query=time_query,
                                      geo_query=geo_query,
                                      extra_query_list=extra_query_list)
    return {"lnglat": [e.data.loc.coordinates for e in loc_entry_list]}
Beispiel #5
0
def Berkeley_pop_route(start_ts, end_ts):
    berkeley_json = {
        "geometry": {
            "type":
            "Polygon",
            "coordinates":
            [[[-122.267443, 37.864693], [-122.267443, 37.880687],
              [-122.250985, 37.880687], [-122.250985, 37.864693],
              [-122.267443, 37.864693]]]
        }
    }
    # box = [ [-122.267443, 37.864693], [-122.250985, 37.880687] ]
    start_dt = esdl.get_local_date(start_ts, "UTC")
    end_dt = esdl.get_local_date(end_ts, "UTC")
    time_query = esttc.TimeComponentQuery("data.ts", start_dt, end_dt)
    geo_query = estg.GeoQuery(["data.loc"], berkeley_json)
    loc_entry_list = esda.get_entries(esda.CLEANED_LOCATION_KEY,
                                      user_id=None,
                                      time_query=time_query,
                                      geo_query=geo_query)
    return {"lnglat": [e.data.loc.coordinates for e in loc_entry_list]}
Beispiel #6
0
def incident_heatmap(user_uuid, modes, time_query, region):
    """
    Return a list of geojson points with properties for the time and the stress level
    related to incidents. This should not return full entries because that can
    expose the user_id in the aggregate case. Maybe it can return the data part only?
    Or should we put the other entries into the properties?
    :param modes: The modes that we want to query for
    :param time_query: The time query, in either local date or timestamp
    :param region: The region of interest
    :return: list of `incident` objects, with all metadata stripped out
    """

    if region is None:
        geo_query = None
    else:
        geo_query = estg.GeoQuery(["data.loc"], region)

    extra_query_list = []
    if modes is not None:
        mode_enum_list = [ecwm.MotionTypes[mode] for mode in modes]
        extra_query_list.append(esdlq.get_mode_query(mode_enum_list))

    if user_uuid is None:
        incident_entry_list = esda.get_entries(
            MANUAL_INCIDENT_KEY,
            user_id=None,
            time_query=time_query,
            geo_query=geo_query,
            extra_query_list=extra_query_list)
    else:
        # We don't support aggregate queries on the usercache. And that is
        # actually fine, because we don't expect immediate results for the
        # aggregate case. We just want to query the usercache to ensure that
        # the incidents don't magically disappear just because they got pushed
        # to the server but are not yet processed
        incident_entry_list = estc.find_entries([MANUAL_INCIDENT_KEY],
                                                time_query)
    return {"incidents": [e.data for e in incident_entry_list]}
def uuid_list_query(modes, time_query, region):
    if region is None:
        geo_query = None
    else:
        geo_query = estg.GeoQuery(["data.loc"], region)

    extra_query_list = []
    if modes is not None:
        mode_enum_list = [ecwm.MotionTypes[mode] for mode in modes]
        extra_query_list.append(esdlq.get_mode_query(mode_enum_list))

    loc_entry_df = esda.get_data_df(esda.CLEANED_LOCATION_KEY,
                                    user_id=None,
                                    time_query=time_query,
                                    geo_query=geo_query,
                                    extra_query_list=extra_query_list)
    if len(loc_entry_df) == 0:
        logging.info("No points found matching query, returning empty list")
        return []

    unique_uuid_list = loc_entry_df.user_id.unique().tolist()
    logging.info("Found %d points with %d unique uuids" %
                 (len(loc_entry_df), len(unique_uuid_list)))
    return unique_uuid_list