def get_average(self, line, threehours): "Returns entries from the database, depending on the given line" if threehours is False: past = self.one_hours_past else: past = self.three_hours_past time_query = db.GqlQuery( "SELECT * " "FROM check_in_db " "WHERE ANCESTOR IS :1 AND time_sent > :2 AND line = :3 " "ORDER BY time_sent", check_in_db_key("check_in_database"), past, line, ) entries = time_query.fetch(500) if len(entries) == 0: if threehours is False: return self.get_average(line, True) else: return -1 else: if (len(entries) < 10) and (threehours is False): return self.get_average(line, True) else: return self.compute_averages(entries, threehours)
def add_to_check_in_db(self, user_id, check_in): "retreives the stored information and places it in the database" if check_in.get('modality') == 'tube': u = user_id o = check_in.get('origin') d = check_in.get('destination') t = check_in.get('time_stamp') l = get_lines(self, check_in.get('lines')) rd = check_in.get('delay') rc = check_in.get('crowd') rh = check_in.get('happy') longi = check_in.get('longitude') lat = check_in.get('latitude') t = datetime.strptime(t, '%Y-%m-%d %H:%M:%S') # This will need to be gotten rid of, but at the moment lines aren't sent so for other functionality this will have to do # l = find_line(self, o) + find_line(self, d) key = check_in_db_key('check_in_database') entry = check_in_db( parent = key, user = u, origin = o, destination = d, line = l, time_sent = t, rating_delay = rd, rating_crowded = rc, rating_happiness = rh, longitude = longi, latitude = lat ) entry.put()
def get(self): logging.info("start of get") entry_query = check_in_db.all().ancestor(check_in_db_key('check_in_database')).order("-time_sent") entries = entry_query.fetch(100) template_values = { 'entries': entries, # 'users' : get_understandable_users(self, entries), 'datastore' : datastore, 'url_home' : url_back_home, 'url_linktext' : url_text } path = os.path.join(os.path.dirname(__file__), 'print_check_in_layout.html') self.response.out.write(template.render(path, template_values))
def query_check_in_db(self, user_id, time_stamp): "commences the Check-In database search" query = db.GqlQuery("SELECT __key__ " "FROM check_in_db " "WHERE ANCESTOR IS :1 AND time_sent = :2 AND user = :3", check_in_db_key('check_in_database'), time_stamp, user_id ) entry = query.fetch(1) if (len(entry) > 0): return False else: return True
def get(self): "Gets datum from an encoded url - will not be used, ideally" u=self.request.GET.get('user') o=self.request.GET.get('origin') d=self.request.GET.get('destination') t=self.request.GET.get('time') rd=self.request.GET.get('delay') rc=self.request.GET.get('crowd') rh=self.request.GET.get('happy') longi=self.request.GET.get('long') lat=self.request.GET.get('lat') c=self.request.GET.get('comment') # /posted/here?&user=adam&origin=Euston&destination=Liverpool Street&time=2011-07-27 15:40:00&delay=300&crowd=100&happy=500&lat=34&long=-5 l = self.find_line(o) + self.find_line(d) database=check_in_db_key('check_in_database') check_in = check_in_db(parent=database, user=u, origin=o, destination=d, line=l, time_sent=t, rating_delay=rd, rating_crowded=rc, rating_happiness=rh, longitude=longi, latitude=lat, comment=c) check_in.put()