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))
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))
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)
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)
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)
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)