Esempio n. 1
0
def update_location(request):
    '''Store the vehicle location to DB'''
    if not request.GET.has_key('lat') or not request.GET.has_key('lon') or not request.GET.has_key('utc') \
        or not request.GET.has_key('spkn') or not request.GET.has_key('id'):
        return HttpResponse("Error!!! Please supply correct parameters : latitude, longitude, time, speed, id", "text/html")

    lat = request.GET.get('lat', None)
    northsouth = request.GET.get('ns', None)
    
    latitude = None
    if lat != None:
        latitude = float(lat[0:2]) + float(lat[2:])/60.0

    if northsouth == 's' and latitude:
        latitude = latitude * -1.00

    lng = request.GET.get('lon', None)
    eastwest = request.GET.get('ew', None)

    longitude = None
    
    if (lng != None):
        longitude = float(lng[0:3]) + float(lng[3:])/60.0
    
    if ((eastwest == 'w' or eastwest == 'W')) and longitude != None:
        longitude = longitude * -1.00

    utc_date = request.GET.get('date', None)
    utc_time = request.GET.get('utc', None)
    
    spkn = request.GET.get('spkn', None)
    speed = 0.0
    
    if spkn != None :
        speed =float(spkn)*NMI/1000.0
         
    vehicleid = request.GET.get('id', None)
    timestamp = datetime.datetime.now()
    
    if utc_date != None:
        year    = 2000 + int(utc_date[4:])
        month   = int(utc_date[2:4])
        day     = int(utc_date[0:2])
        hour    = int(utc_time[0:2])
        minute  = int(utc_time[2:4])
        sec     = int(utc_time[4:6])
        
        timestamp = datetime.datetime(year, month, day, hour, minute, sec)
    

    logging.info('lat: %f, %f, %d, %s, %s' % (latitude, longitude, speed, str(timestamp), vehicleid))
    
    #if not latitude or not longitude or not timestamp or not speed or not vehicleid:
    #    return HttpResponse("Error!!! Please supply correct parameters : latitude:%s, longitude:%s, time:%s, speed:%s, id:%s" %(str(latitude), str(longitude), timestamp, str(speed), vehicleid), "text/html")
    
    try:
        vloc = VehiclePosition(latitude=latitude, longitude=longitude, when=timestamp, speed=speed, vehicle_id=vehicleid)
        vloc.put()
    except Exception, e:
        raise e
Esempio n. 2
0
def get_vehicle_track(request):
    vehicleid = None
    vtrack = []
    offset = int(request.GET.get('offset', 0))
    _status = 200
    if request.GET.get('id', None):
        vehicleid = request.GET.get('id')
    else:
        raise Http404
    try:
        vtrack = VehiclePosition.all().filter('vehicle_id = ' , vehicleid ).order('when').fetch(1000, offset=offset)
    except Exception, e:
        _status = 500