Esempio n. 1
0
def generate_sample_gps_data(lat, lng, userPK, numMins, makeStop, heading, timeStamp):

  # Number of minute intervals to generate data. Initially set at every 1 minute generate a data point
  # This should be 1, normally. Changed to 0 to generate a LOT of data points at one time stamp
  timeInterval = 0
  
  # A maxDisctanceInterval of 0.0001 is roughly 11 meters. 
  # So, we're saying this data can't move faster than 11 meters/interval (initially set at 11m/minute)
  # This could change with car rides, etc. 
  maxDistanceInterval = 0.0001

  user = User.objects.get(pk = userPK)

  # If we need to make a stop (makeStop = True) then we need a boolean flag to keep track of whether
  # we've made that stop yet. We only want one stop per trip.
  stopMade = False
  # The stop will be anywhere from 10-60 minutes long
  stopLength = random.randint(10,60)

  while (numMins > 0):
    tmpLat = random.uniform(0.0, maxDistanceInterval)
    tmpLat = ceil(tmpLat*1000000)/1000000
    lat = round(lat, 6)
    tmpLng = random.uniform(0.0, maxDistanceInterval)
    tmpLng = ceil(tmpLng*1000000)/1000000
    lng = round(lng , 6)

    # Make next data point in the general direction of the heading chosen
    # The 'adjustInt' will be -1, 0 or 1. That will make the long/lat increase,
    # decrease or not change. 
    if heading == 'N':
      lat = float(lat) + tmpLat
      adjustInt = random.randint(-1,1)
      lng = float(lng) - (adjustInt * tmpLng)
    elif heading == 'E':
      lng = float(lng) + tmpLng
      adjustInt = random.randint(-1,1)
      lat = float(lat) + (adjustInt * tmpLat)
    elif heading == 'S':
      lat = float(lat) - tmpLat
      adjustInt = random.randint(-1,1)
      lng = float(lng) - (adjustInt * tmpLng)
    elif heading == 'W':
      lng = float(lng) - tmpLng
      adjustInt = random.randint(-1,1)
      lat = float(lat) + (adjustInt * tmpLat)
    elif heading == 'A':
      adjustInt = random.randint(-1,1)
      lng = float(lng) + (adjustInt * tmpLng)
      lat = float(lat) + (adjustInt * tmpLat)

    timeStamp = timeStamp + datetime.timedelta(minutes = timeInterval)

    newLoc = Location(user = user, latitude = lat, longitude = lng, timeStamp = timeStamp)
    newLoc.save()
    
    numMins -= 1

  return 0
Esempio n. 2
0
            country_name=loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(
                raw_geodata=raw_geodata,
                longitude=loc.get('longitude', None),
                latitude=loc.get('latitude', None),
                address=loc.get('address', ' '),
                region=loc.get('region', ' '),
                locality=loc.get('locality', ' '),
                postal_code=loc.get('postal_code', ' '),
                country_name=loc.get('country_name', ' '),
            )
            _loc.save()
        original.location = _loc
    else:
        original.location = None

    if 'working_locations' in org:
        for loc in org['working_locations']:
            raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(
                loc.get("raw_geodata"), dict) else loc.get("raw_geodata")
            if raw_geodata not in [
                    l.raw_geodata for l in original.working_locations.all()
            ]:
                locs = Location.objects.filter(
                    raw_geodata=raw_geodata,
                    longitude=loc.get('longitude', None),
                    latitude=loc.get('latitude', None),
Esempio n. 3
0
def update_user(request):
    if 'user' not in request.POST:
        return HttpResponseBadRequest()
    user = json.loads(request.POST['user'])

    if 'location' in user and user['location']:
        loc = user['location']
        raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(loc.get("raw_geodata"), dict) else loc.get("raw_geodata")

        #Until we fix duplicate locations we have to do the following...lame.
        _locs = Location.objects.filter(raw_geodata = raw_geodata,
            longitude = loc.get('longitude', None),
            latitude = loc.get('latitude', None),
            address = loc.get('address', ' '),
            region = loc.get('region', ' '),
            locality = loc.get('locality', ' '),
            postal_code = loc.get('postal_code', ' '),
            country_name = loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(raw_geodata = raw_geodata,
                longitude = loc.get('longitude', None),
                latitude = loc.get('latitude', None),
                address = loc.get('address', ' '),
                region = loc.get('region', ' '),
                locality = loc.get('locality', ' '),
                postal_code = loc.get('postal_code', ' '),
                country_name = loc.get('country_name', ' '),)
            _loc.save()
        request.user.location = _loc
    else:
        request.user.location = None

    str_fields = [
                    'first_name', 'last_name', 'email', 'gender', 'bio',
                    'url', 'twitter_id', 'flickr_id', 'youtube_id', 'vimeo_id', 'blog_url',
                 ]

    settings_fields = [
                    'enable_jumo_updates', 'email_stream_frequency', 'post_to_fb',
                  ]

    int_fields = [
                    'birth_year',
                 ]

    if 'enable_followed_notification' in user:
        try:
            sub = request.user.subscriptions.get(id=NOTIFICATIONS_PUB)
        except Subscription.DoesNotExist:
            sub = Subscription.get_or_create(user=request.user, pub_id=NOTIFICATIONS_PUB)

        if sub.subscribed <> user['enable_follow_notification']:
            sub.subscribed = user['enable_follow_notification']
            sub.save()

    for f in str_fields:
        if f in user and user[f] != getattr(request.user, f):
            setattr(request.user, f, user[f])

    for f in settings_fields:
        settings = user['settings']
        if f in settings:
            setattr(request.user, f, settings[f])

    for f in int_fields:
        if f in user and user[f] != getattr(request.user, f):
            if user[f] == '':
                user[f] = None
            setattr(request.user, f, user[f])

    if 'password' in user and user['password'] != '':
        request.user.password = hash_password(user['password'])
    if 'username' in user and user['username'] != request.user.username:
        _username = request.user.username
        request.user.username = create_handle(user['username'])
        cache.bust_on_handle(request.user, _username, False)

    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({'result' : request.user.username})
Esempio n. 4
0
def update_user(request):
    if 'user' not in request.POST:
        return HttpResponseBadRequest()
    user = json.loads(request.POST['user'])

    if 'location' in user and user['location']:
        loc = user['location']
        raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(
            loc.get("raw_geodata"), dict) else loc.get("raw_geodata")

        #Until we fix duplicate locations we have to do the following...lame.
        _locs = Location.objects.filter(
            raw_geodata=raw_geodata,
            longitude=loc.get('longitude', None),
            latitude=loc.get('latitude', None),
            address=loc.get('address', ' '),
            region=loc.get('region', ' '),
            locality=loc.get('locality', ' '),
            postal_code=loc.get('postal_code', ' '),
            country_name=loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(
                raw_geodata=raw_geodata,
                longitude=loc.get('longitude', None),
                latitude=loc.get('latitude', None),
                address=loc.get('address', ' '),
                region=loc.get('region', ' '),
                locality=loc.get('locality', ' '),
                postal_code=loc.get('postal_code', ' '),
                country_name=loc.get('country_name', ' '),
            )
            _loc.save()
        request.user.location = _loc
    else:
        request.user.location = None

    str_fields = [
        'first_name',
        'last_name',
        'email',
        'gender',
        'bio',
        'url',
        'twitter_id',
        'flickr_id',
        'youtube_id',
        'vimeo_id',
        'blog_url',
    ]

    settings_fields = [
        'enable_jumo_updates',
        'email_stream_frequency',
        'post_to_fb',
    ]

    int_fields = [
        'birth_year',
    ]

    if 'enable_followed_notification' in user:
        try:
            sub = request.user.subscriptions.get(id=NOTIFICATIONS_PUB)
        except Subscription.DoesNotExist:
            sub = Subscription.get_or_create(user=request.user,
                                             pub_id=NOTIFICATIONS_PUB)

        if sub.subscribed <> user['enable_follow_notification']:
            sub.subscribed = user['enable_follow_notification']
            sub.save()

    for f in str_fields:
        if f in user and user[f] != getattr(request.user, f):
            setattr(request.user, f, user[f])

    for f in settings_fields:
        settings = user['settings']
        if f in settings:
            setattr(request.user, f, settings[f])

    for f in int_fields:
        if f in user and user[f] != getattr(request.user, f):
            if user[f] == '':
                user[f] = None
            setattr(request.user, f, user[f])

    if 'password' in user and user['password'] != '':
        request.user.password = hash_password(user['password'])
    if 'username' in user and user['username'] != request.user.username:
        _username = request.user.username
        request.user.username = create_handle(user['username'])
        cache.bust_on_handle(request.user, _username, False)

    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({'result': request.user.username})
Esempio n. 5
0
            locality = loc.get('locality', ' '),
            postal_code = loc.get('postal_code', ' '),
            country_name = loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(raw_geodata = raw_geodata,
                longitude = loc.get('longitude', None),
                latitude = loc.get('latitude', None),
                address = loc.get('address', ' '),
                region = loc.get('region', ' '),
                locality = loc.get('locality', ' '),
                postal_code = loc.get('postal_code', ' '),
                country_name = loc.get('country_name', ' '),)
            _loc.save()
        original.location = _loc
    else:
        original.location = None

    if 'working_locations' in org:
        for loc in org['working_locations']:
            raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(loc.get("raw_geodata"), dict) else loc.get("raw_geodata")
            if raw_geodata not in [l.raw_geodata for l in original.working_locations.all()]:
                locs = Location.objects.filter(raw_geodata = raw_geodata,
                        longitude = loc.get('longitude', None),
                        latitude = loc.get('latitude', None),
                        address = loc.get('address', ' '),
                        region = loc.get('region', ' '),
                        locality = loc.get('locality', ' '),
                        postal_code = loc.get('postal_code', ' '),