예제 #1
0
    def get(self):
        dist = Counter.get_by_key_name('distance')
        #        if not dist:
        #            dist = Counter(key_name='distance', value=0)
        #            dist.put()
        totaldistance = dist.value

        number = Counter.get_by_key_name('number')
        #        if not number:
        #            number = Counter(key_name='number', value=0)
        #            number.put()
        totaltracks = number.value

        my_n = 0
        my_m = 0
        if self.request.get('uid'):
            trk_q = db.GqlQuery("SELECT * FROM Track WHERE uuid='%s'" %
                                self.request.get('uid'))
            trks = trk_q.fetch(1000)
            if not trks:
                logging.warn('no tracks for this uid (yet)')

            for trk in trks:
                my_m += trk.distance
                my_n += 1

            self.response.out.write(
                '{"totalDistance":%d, "totalTracks":%d, "myDistance":%d, "myTracks":%d}'
                % (totaldistance, totaltracks, my_m, my_n))

        else:
            self.response.out.write('{"totalDistance":%d, "totalTracks":%d}' %
                                    (totaldistance, totaltracks))
예제 #2
0
    def get(self):
        dist = Counter.get_by_key_name('distance')
#        if not dist:
#            dist = Counter(key_name='distance', value=0)
#            dist.put()
        totaldistance = dist.value

        number = Counter.get_by_key_name('number')
#        if not number:
#            number = Counter(key_name='number', value=0)
#            number.put()
        totaltracks = number.value

        my_n = 0
        my_m = 0
        if self.request.get('uid'):
            trk_q = db.GqlQuery("SELECT * FROM Track WHERE uuid='%s'" % self.request.get('uid'))
            trks = trk_q.fetch(1000)
            if not trks:
                logging.warn('no tracks for this uid (yet)')

            for trk in trks:
                my_m += trk.distance
                my_n += 1

            self.response.out.write('{"totalDistance":%d, "totalTracks":%d, "myDistance":%d, "myTracks":%d}' % (totaldistance, totaltracks, my_m, my_n))


        else:
            self.response.out.write('{"totalDistance":%d, "totalTracks":%d}' % (totaldistance, totaltracks))
예제 #3
0
    def post(self):
        try:
            decoder = json.JSONDecoder()
            trk = self.request.get('track')
            if not trk:
                raise Err("no track found")
                            
            data = decoder.decode(trk)
            uploadtime = datetime.datetime.now()
            
            distance = int(data['distance'])
            track = Track(uuid=data['uuid'], uploadtime=uploadtime, distance=distance)
            
            counter = Counter.get_by_key_name('distance')
            if not counter:
                counter = Counter(key_name='distance',value=24000)
            counter.value += distance
            counter.put()

            number = Counter.get_by_key_name('number')
            if not number:
                number = Counter(key_name='number',value=130)
            number.value += 1
            number.put()

            track.raw = trk
            track.put()

#            for p in data['track']:
#                point = Point(parent=track, lat=p['lat'], lng=p['long'], acc=p['acc'], ts=datetime.datetime.fromtimestamp(p['ts']))
#                point.put()

            self.response.out.write('{"success":true}')
        except Err, e:
            self.response.out.write('{"success":false, "error":"%s"}' % e.message)
예제 #4
0
    def post(self):
        try:
            decoder = json.JSONDecoder()
            trk = self.request.get('track')
            if not trk:
                raise Err("no track found")

            data = decoder.decode(trk)
            uploadtime = datetime.datetime.now()

            distance = int(data['distance'])
            track = Track(uuid=data['uuid'],
                          uploadtime=uploadtime,
                          distance=distance)

            counter = Counter.get_by_key_name('distance')
            if not counter:
                counter = Counter(key_name='distance', value=24000)
            counter.value += distance
            counter.put()

            number = Counter.get_by_key_name('number')
            if not number:
                number = Counter(key_name='number', value=130)
            number.value += 1
            number.put()

            track.raw = trk
            track.put()

            #            for p in data['track']:
            #                point = Point(parent=track, lat=p['lat'], lng=p['long'], acc=p['acc'], ts=datetime.datetime.fromtimestamp(p['ts']))
            #                point.put()

            self.response.out.write('{"success":true}')
        except Err, e:
            self.response.out.write('{"success":false, "error":"%s"}' %
                                    e.message)
예제 #5
0
    def get(self):

        template = Template(filename="index.html",
                            input_encoding='utf8',
                            output_encoding='utf8')

        distance = Counter.get_by_key_name('distance')

        if not distance:
            km = 0
        else:
            km = distance.value / 1000

        output = template.render(kilometers=km)
        self.response.out.write(output)
예제 #6
0
    def get(self):

        
        template = Template(filename="index.html",
                            input_encoding='utf8',
                            output_encoding='utf8')
        
        distance = Counter.get_by_key_name('distance')

        if not distance:
            km = 0
        else:
            km = distance.value/1000

        output = template.render(kilometers=km)
        self.response.out.write(output)