Example #1
0
def get_neighbor(data):
  neighbor_uid_list = []
  if KEY.ID not in data:
    return neighbor_uid_list
  user = get_user_information(data)
  if user is None:
    return neighbor_uid_list
  DISTANCE = 15.0 # 15000m
  location_range = haversine.get_range(user[KEY.LONGITUDE], user[KEY.LATITUDE], DISTANCE)
  sql = "select id from user where " \
        "longitude > %f and longitude < %f " \
        "and latitude > %f and latitude < %f"
  sql_result = dbhelper.execute_fetchall(
    sql%(location_range[0], location_range[1], location_range[2], location_range[3]))

  if KEY.TYPE in data:
    for each_result in sql_result:
      user = {}
      user[KEY.ID] = each_result[0]
      user = get_user_information(user)
      if user is not None:
        neighbor_uid_list.append(user)
  else:
    for each_result in sql_result:
      user = {}
      user[KEY.ID] = each_result[0]
      user = get_user_information(user)
      if user is not None:
        neighbor_uid_list.append(user[KEY.IDENTITY_ID])
  return neighbor_uid_list
Example #2
0
def get_nearby_event(data):
  nearby_event_list = []
  if KEY.ID not in data:
    return nearby_event_list
  user = get_user_information(data)
  DISTANCE = 2.0 # 2000m
  location_range = haversine.get_range(user[KEY.LONGITUDE], user[KEY.LATITUDE], DISTANCE)
  sql = "select id from event where " \
        "longitude > %f and longitude < %f " \
        "and latitude > %f and latitude < %f"\
        %(location_range[0], location_range[1], location_range[2], location_range[3])
  if KEY.TYPE in data:
    sql += " and type = %d"%data[KEY.TYPE]
  if KEY.STATE in data:
    sql += " and state = %d"%data[KEY.STATE]
  if KEY.LAST_TIME in data:
    sql += " and last_time > '%s'"%data[KEY.LAST_TIME]
  sql += " order by time DESC"
  sql_result = dbhelper.execute_fetchall(sql)
  for each_result in sql_result:
    for each_id in each_result:
      nearby_event_list.append(each_id)
  return nearby_event_list