def JourneyBatch(request): user = User.all().filter('facebook_id', request.session['facebook_id']).get() for point in json.loads(request.body): # Date sent date = datetime.fromtimestamp(int( point['date'])).replace(tzinfo=pytz.UTC) if 'journey' in point: if point['journey'] != 'Stop': journey = Journey(user=user, travel_type=TravelType.all().filter( 'name', point['journey']).get(), start_date=date) journey.put() logging.info('Journey started for ' + point['journey']) user.active_trip_id = journey.key().id() else: logging.info('Journey ended') journey = Journey.get_by_id(user.active_trip_id) journey.end_date = date journey.put() # Remove active trip user.active_trip_id = -1 user.put() elif 'distance' in point and user.active_trip_id != -1: # Get the current journey and save point Point(journey=Journey.get_by_id(user.active_trip_id), latitude=float(point['x']), longitude=float(point['y']), speed=float(point['speed']), time=date, distance=float(point['distance'])).put() return HttpResponse()
def get_context_data(self, **kwargs): context = super(JourneyMap, self).get_context_data(**kwargs) journey = Journey.get_by_id(long(kwargs['journey_id'])) points = Point.all().filter('journey', journey) if points.count() > 0: context.update({ 'journey_points': points.order('-time'), }) return context
def JourneyBatch(request): user = User.all().filter('facebook_id', request.session['facebook_id']).get() for point in json.loads(request.body): # Date sent date = datetime.fromtimestamp(int(point['date'])).replace(tzinfo=pytz.UTC) if 'journey' in point: if point['journey'] != 'Stop': journey = Journey( user=user, travel_type=TravelType.all().filter('name', point['journey']).get(), start_date=date ) journey.put() logging.info('Journey started for ' + point['journey']) user.active_trip_id = journey.key().id() else: logging.info('Journey ended') journey = Journey.get_by_id(user.active_trip_id) journey.end_date = date journey.put() # Remove active trip user.active_trip_id = -1 user.put() elif 'distance' in point and user.active_trip_id != -1: # Get the current journey and save point Point( journey=Journey.get_by_id(user.active_trip_id), latitude=float(point['x']), longitude=float(point['y']), speed=float(point['speed']), time=date, distance=float(point['distance']) ).put() return HttpResponse()