Exemple #1
0
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()
Exemple #2
0
    def test_login(self):
        global user
        url = site_url + 'user/login/{0}'.format(facebook_token)
        requests.post(url)

        # Check if user has been registered
        user = User.all().filter('facebook_token', facebook_token).get()
        if user is not None:
            self.assertTrue(user.facebook_token == facebook_token)
        else:
            self.assertTrue(False)
Exemple #3
0
    def test_login(self):
        global user
        url = site_url + "user/login/{0}".format(facebook_token)
        requests.post(url)

        # Check if user has been registered
        user = User.all().filter("facebook_token", facebook_token).get()
        if user is not None:
            self.assertTrue(user.facebook_token == facebook_token)
        else:
            self.assertTrue(False)
Exemple #4
0
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()