class QuestionAnswerer(db.Model): answerer = db.UserProperty() question = db.ReferenceProperty(Question) correct_count = db.IntegerProperty() total_count = db.IntegerProperty() last_done = db.DateTimeProperty() importance_rating = db.RatingProperty() importance_width = db.IntegerProperty() # used for the pixel width of the actual stars difficulty_rating = db.RatingProperty() difficulty_width = db.IntegerProperty() # used for the pixel width of the actual stars quality_rating = db.RatingProperty() quality_width = db.IntegerProperty() # used for the pixel width of the actual stars flag = ChoiceProperty(enumerate(['inappropriate', 'spam', 'miscategorized']))
class ItemRating(db.Model): contents = db.TextProperty() item = db.ReferenceProperty(Item) rating = db.RatingProperty() time = db.DateTimeProperty(auto_now_add=True) def apply(self): if self.rating == 0: return #assume zero rating is no numerical rating associated self.item.avg_rating = ( self.item.avg_rating * float(self.item.rating_count) + float(self.rating)) / (float(self.item.rating_count + 1)) self.item.rating_count += 1 self.item.put() def unapply(self): if self.rating == 0: return item = self.item item.avg_rating = (float(item.rating_count) * float(item.avg_rating)) - float(self.rating) item.rating_count -= 1 item.avg_rating /= float(item.rating_count) item.put() def deletion_memcache_key(self): return "rating-deleted-%s" % str(self.key())
class Course(db.Model): name = db.StringProperty(required=True) description = db.TextProperty(required=True) importance = db.RatingProperty(required=False) def render(self): return render_str("course.html", courseToDisplay=self)
class Article(db.Model): title = db.StringProperty(required=True, default="no title") content = db.TextProperty(required=True) tags = db.ListProperty(db.Category) author_mail = db.EmailProperty() link = db.LinkProperty(required=True) rating = db.RatingProperty()
class Responder(db.Model): """Represents a particular RDM product / device.""" manufacturer = db.ReferenceProperty(Manufacturer, required=True) # The Device Model ID field from DEVICE_INFO device_model_id = db.IntegerProperty() # Description can't be required, as DEVICE_MODEL_DESCRIPTION is not a # mandatory PID. model_description = db.StringProperty(default=None) # The product category product_category = db.ReferenceProperty(ProductCategory, collection_name='responder_set') # link to the responder product page link = db.LinkProperty() # url of the source image image_url = db.LinkProperty() # the blob for the image data image_data = blobstore.BlobReferenceProperty() # the url we're serving the image on image_serving_url = db.LinkProperty() # the scoring rank score = db.IntegerProperty() # the score penalty, used to demote responders score_penalty = db.IntegerProperty() # test score, this is updated with the latest score rdm_responder_rating = db.RatingProperty()
class Site(db.Model): # RPC private/protected properties: read-only for ALL _deleted = db.BooleanProperty(default=False) _dateCreated = db.DateTimeProperty(auto_now_add=True) _dateModified = db.DateTimeProperty(auto_now=True) _dateAccessed = db.DateTimeProperty() _userLastAccessed = db.UserProperty() _rating = db.RatingProperty() # RPC public properties: writable by creator/admin userCreator = db.UserProperty(required=True) # creator or admin may change creator name = db.StringProperty(required=True) latlng = db.GeoPtProperty(required=True) address = db.PostalAddressProperty() description = db.TextProperty() pay = db.BooleanProperty() # pay access only? restricted = db.BooleanProperty() # authorized access only? # List of Service entries in the DB services = db.ListProperty(db.Key) # List of keys to Service entities #db.BlobProperty() # images, etc #db.ListProperty() # images, history, ... # ReferenceProperty? # Related sites? contactName = db.StringProperty() contactAddress = db.PostalAddressProperty() contactPhone = db.PhoneNumberProperty() contactEmail = db.EmailProperty() contactURL = db.LinkProperty() contactIM = db.IMProperty() evcmid = db.StringProperty() # ID, if imported from EVChargerMaps.com
class Post(db.Model): subject = db.StringProperty(required=True) content = db.TextProperty(required=True) user = db.StringProperty() likes = db.RatingProperty() created = db.DateTimeProperty(auto_now_add=True) last_modified = db.DateTimeProperty(auto_now=True) def render(self): self._render_text = self.content.replace('\n', '<br>') return render_str("post.html", p=self) def upvote(self, currentUser): p = self u = currentUser # count number of likes in db on this post and with current logged in # user all_likes = db.GqlQuery("select * from Like where user= :user \ and post_reference= :post_ref", user=u, post_ref=p.subject) # update likes attribute on post if all_likes.count() < 1: l = Like(post_reference=p.subject, user=u) l.put() p.likes = p.likes + 1 p.put()
class AllPropertiesModel(db.Model): """Property names are ugly, yes.""" prop_string = db.StringProperty() prop_byte_string = db.ByteStringProperty() prop_boolean = db.BooleanProperty() prop_integer = db.IntegerProperty() prop_float = db.FloatProperty() prop_date_time = db.DateTimeProperty() prop_date = db.DateProperty() prop_time = db.TimeProperty() prop_list = db.ListProperty(int) prop_string_list = db.StringListProperty() prop_reference = db.ReferenceProperty() prop_self_refeference = db.SelfReferenceProperty() prop_user = db.UserProperty() prop_blob = db.BlobProperty() prop_text = db.TextProperty() prop_category = db.CategoryProperty() prop_link = db.LinkProperty() prop_email = db.EmailProperty() prop_geo_pt = db.GeoPtProperty() prop_im = db.IMProperty() prop_phone_number = db.PhoneNumberProperty() prop_postal_address = db.PostalAddressProperty() prop_rating = db.RatingProperty()
class SiteReport( db.Model ): creationDate = db.DateTimeProperty(auto_now_add = True) name = db.StringProperty() description = db.StringProperty() url = db.StringProperty() score = db.RatingProperty() def __str__( self ): return '<SiteReport url=%s>' % self.url @classmethod def get_recent_report_urls(cls): reports = db.Query(cls, projection = ('url',)).order('-creationDate').run(limit = 20) urls = (report.url for report in reports) unique_urls = remove_duplicates(urls) return unique_urls @classmethod def get_best_scored_report_urls(cls): all_reports = db.Query(cls, projection = ('url', 'score')).order('-score').run(limit = 20) reports = OrderedDict() for report in all_reports: if report.url not in reports: reports[ report.url ] = report.score return reports
class service(db.Model): """All the data we store for a service""" Title = db.StringProperty() Description = db.StringProperty() Requester = db.ReferenceProperty(user, collection_name="requested_services") TimeNeeded = db.IntegerProperty() Skill = db.ReferenceProperty(skill, collection_name="linked_services") Geoloc = db.BooleanProperty() StartDate = db.DateTimeProperty(auto_now_add=True) EndDate = db.DateTimeProperty(auto_now_add=True) Grade = db.RatingProperty() Feedback = db.StringProperty() Responder = db.ReferenceProperty(user, collection_name="responded_service") Attachments = db.StringListProperty() Comments = db.ListProperty(int) CreatedTime = db.DateTimeProperty(auto_now_add=True) ModifiedTime = db.DateTimeProperty(auto_now_add=True) #@property #Category = def get_category(self): return self.Skill.Category.get() def to_dict(self): tempdict1 = { "Id": self.key().id(), "Title": self.Title, "Description": self.Description, "Category": self.Skill.Category.Name, "Skill": self.Skill.Name, "StartDate": self.StartDate.strftime("%Y-%m-%d %H:%M:%S"), "EndDate": self.EndDate.strftime("%Y-%m-%d %H:%M:%S"), "Requester": { "Type": "Small", "User": self.Requester.to_small_dict() }, "Grade": self.Grade, "TimeNeeded": self.TimeNeeded, "Done": "false", "Feedback": self.Feedback, "CreatedTime": self.CreatedTime.strftime("%Y-%m-%d %H:%M:%S"), "ModifiedTime": self.ModifiedTime.strftime("%Y-%m-%d %H:%M:%S"), "Address": self.Requester.Address, "Icons": { "Geoloc": "True" if self.Requester.Address else "False", "Friends": "True", "Time": "True" if (self.EndDate - self.StartDate) < datetime.timedelta(days=7) else "False", "FriendsofFriends": "False" }, "Applied": False } return tempdict1
class UserTechnology(db.Model): """La UserTechnology serve per poter associare un rating ad una determinata tecnologia per un determinato utente, il calcolo viene fatto in modalita' batch leggendo i referrer. Periodicamente un cron aggiorna i rating per tecnologia sugli utenti che hanno referrer da parte di altri utenti""" technology = db.ReferenceProperty(Technology) rating = db.RatingProperty()
class Invitation(db.Model): """ An Invitation happens when a user is invited as a guest to a meal cooked by another user. """ date = db.DateTimeProperty( ) # the meal referent already has a date, however, the date field of Invitation is not redundant. We need a quick way of querying invitations for one day, and since GAE does not support JOIN queries, this is way one to do this. meal = db.ReferenceProperty(Meal, collection_name="invitations") guest = db.ReferenceProperty(User) attending = db.StringProperty(choices=set(["yes", "no", "maybe"])) food_rating = db.RatingProperty()
class QuestionAnswer(db.Model): """Risposta ad una risposta da parte di un altro utente, il rating e' una sorta di "like" alla facebook """ body = db.TextProperty() rating = db.RatingProperty() dateTime = db.DateTimeProperty() # Risposta a cui il commento fa riferimento relatedTo = db.SelfReference() who = db.ReferenceProperty(User)
class Refer(db.Model): """Permette agli utenti di dare referenze ad altri utenti su determinate tecnologie""" user = db.ReferenceProperty(User) technology = db.ReferenceProperty(Technology, collection_name="rTechnology") stars = db.RatingProperty() who = db.ReferenceProperty(User, collection_name="rUser") description = db.StringProperty()
class Winery(db.Model): """Models a winery""" name = db.StringProperty() description = db.TextProperty() rating = db.RatingProperty() email = db.EmailProperty() phone = db.PhoneNumberProperty() hours = db.ReferenceProperty(WeeklyHours) address = db.PostalAddressProperty() location = db.GeoPtProperty() image = db.BlobProperty()
class Book(db.Model): title = db.StringProperty(required=True) authors = db.StringProperty() isbn = db.IntegerProperty(required=True) publishers = db.StringProperty() #date = db.DateTimeProperty() pages = db.StringProperty() language = db.StringProperty() rating = db.RatingProperty() cover = db.StringProperty() description = db.TextProperty()
class Picograph(db.Model): searchEntry = db.ReferenceProperty(SearchEntry, collection_name='picographs') srcUrl = db.LinkProperty() funcName = db.StringProperty() title = db.StringProperty() content = db.TextProperty() rating = db.RatingProperty() date = db.DateTimeProperty()
class FlashCard(search.SearchableModel): question = db.TextProperty(required=True) answer = db.TextProperty(required=True) tags = db.StringProperty(required=True) importance = db.RatingProperty() url = db.LinkProperty() reference = db.ReferenceProperty(Reference) # hidden user = db.UserProperty() mtime = db.DateTimeProperty(auto_now_add=True) display = db.ReferenceProperty(DisplayCard)
class RaterRating(db.Model): created_at = db.DateTimeProperty(auto_now_add=True) modified_at = db.DateTimeProperty(auto_now=True) rater_id = db.StringProperty(required=True) rating = db.RatingProperty(required=True) comment = db.TextProperty(required=False) tags = db.StringListProperty(default=[]) activated = db.BooleanProperty(default=False) @classmethod def create_rater_id(cls): random.seed() return sha.sha("DT%s R%s" % (datetime.datetime.now(), random.random())).hexdigest() @classmethod def create(cls, tags): rater_id = cls.create_rater_id() Unique.check("rater_id", rater_id) rater_rating = cls(rater_id=rater_id, rating=0, comment="", tags=tags) rater_rating.activated = False; rater_rating.put() return rater_rating @classmethod def rating_for_rater(cls, rater_id): return cls.all().filter('rater_id =', rater_id).get() @classmethod def update(cls, rater_id, rating, comment): rater_rating = cls.rating_for_rater(rater_id) if rater_rating is not None: rater_rating.rating = rating rater_rating.comment = comment rater_rating.activated = True rater_rating.put() else: logging.warning("Rater id not found: %s") return rater_rating @classmethod def ratings_for_tags(cls, days=7, tags=[]): ratings_query = cls.all().filter('activated =', True).filter('modified_at >', datetime.datetime.now() - datetime.timedelta(days=days)) for tag in tags: ratings_query.filter('tags =', tag) return [rating.rating for rating in ratings_query] @classmethod def average_rating_for_tags(cls, tags, days=7): ratings = cls.ratings_for_tags(int(days), tags) average = 0 if ratings: average = float(sum(ratings)) / len(ratings) return average
class Question(db.Model): author = db.UserProperty() subject = db.ReferenceProperty(Subject) question_text = db.TextProperty() correct_choice_text = db.TextProperty() incorrect_1 = db.TextProperty() incorrect_2 = db.TextProperty() incorrect_3 = db.TextProperty() incorrect_4 = db.TextProperty() incorrect_5 = db.TextProperty() answer_text = db.TextProperty() date_created = db.DateTimeProperty(auto_now_add=True) published = db.BooleanProperty() not_completed = db.BooleanProperty() # Test's if the user actually didn't completed the creation process answer_count = db.IntegerProperty() correct_count = db.IntegerProperty() avg_importance = db.RatingProperty() avg_difficulty = db.RatingProperty() avg_quality = db.RatingProperty() hint_text = db.TextProperty()
class Rating(db.Model): #eid= db.IntegerProperty() tech = db.ReferenceProperty(Technology) rating = db.RatingProperty() @staticmethod def newFromDictionary(dct): logging.debug(dct) # si deve recuperare l'id della tecnologia che poi deve essere caricata return Rating(tech=str(dct['tech']), rating=int(dct['rating'])) def serializeToJSON(self): pyData = {'tech': self.tech, 'rating': self.rating, '_key': self.key()} return json.dumps(pyData)
class SocialReview(db.Model): user = db.ReferenceProperty(SocialUser) social_account = db.ReferenceProperty(SocialAccount) social_account_item_id = db.StringProperty() full_business_name = db.StringProperty() social_account_business_id = db.StringProperty() business_category_list = db.StringListProperty() business_address = db.PostalAddressProperty() review_rating = db.RatingProperty( ) #every rating is normalized to 1 out of 100 review_date = db.DateTimeProperty() review_text = db.TextProperty() checkin_count = db.IntegerProperty()
class Park(db.Model): """ Park model for the App Engine data store. """ guid = db.StringProperty(required=True) name = db.StringProperty(required=True) address = db.PostalAddressProperty(required=True) neighbourhood = db.StringProperty(required=True) geolocation = db.GeoPtProperty(required=True) dogs = db.BooleanProperty(default=False) leashed = db.BooleanProperty(default=False) restrictions = db.BooleanProperty(default=False) notes = db.StringProperty(multiline=True) overallRating = db.RatingProperty(default=0) amountVotes = db.IntegerProperty(default=0) overallBayesian = db.RatingProperty(default=0) facilityVotes = db.IntegerProperty(default=0) facilityVotesTotal = db.IntegerProperty(default=0) facilityRating = db.RatingProperty(default=0) facilityBayesian = db.RatingProperty(default=0) cleanlinessVotes = db.IntegerProperty(default=0) cleanlinessVotesTotal = db.IntegerProperty(default=0) cleanlinessRating = db.RatingProperty(default=0) cleanlinessBayesian = db.RatingProperty(default=0) friendlinessVotes = db.IntegerProperty(default=0) friendlinessVotesTotal = db.IntegerProperty(default=0) friendlinessRating = db.RatingProperty(default=0) friendlinessBayesian = db.RatingProperty(default=0) def getmarker(self): if not self.dogs: return app.config.markerbase + 'dogs-no.png' else: if not self.restrictions: if not self.leashed: return app.configmarkerbase + 'dogs-free.png' else: return app.configmarkerbase + 'dogs-leashed.png' else: return app.configmarkerbase + 'dogs-restrictions.png'
class Dialogue(db.Model): title = db.StringProperty() short = db.StringProperty() alias = db.StringProperty() tweet_id_list = db.StringListProperty() authors = db.StringProperty() author_list = db.StringListProperty() author_id_list = db.StringListProperty() quoted_by = db.UserProperty() quoter_ip = db.StringProperty() quoter_user_agent = db.StringProperty() tags = db.ListProperty(db.Category) created_date = db.DateTimeProperty(auto_now_add=True) updated_date = db.DateTimeProperty(auto_now=True) json = db.TextProperty() rating = db.RatingProperty() # not real time latest_rating_update = db.DateTimeProperty()
class Meal(db.Model): """ A Meal represents one instance where a User prepares and devours a Meal. """ date = db.DateTimeProperty() recipe = db.ReferenceProperty(Recipe) user = db.ReferenceProperty(User, collection_name="meals") rating = db.RatingProperty() preparation_time = db.IntegerProperty() cooking_time = db.IntegerProperty() @property def guests(self): return [i.guest for i in self.invitations] def to_dict(self): return dict([(p, unicode(getattr(self, p))) for p in self.properties()])
class WhitListItem(db.Model): whitList = db.ReferenceProperty(WhitList, collection_name='whitListItems') name = db.StringProperty() added = db.DateTimeProperty(auto_now_add=True) sortOrder = db.IntegerProperty() desc = db.TextProperty() tag = db.StringListProperty(default=[])#unicode,default=['Adventure','Career','Community','Culture and Arts','Education','Entertainment','Family','Fitness','Health and Wellness','Hobbies','Home Improvement','Issues and Causes','Literature','Music','Outdoor Recreation','Relationships','Spiritual','Sports','Travel','Wealth and Finance']) accomplishBy = db.DateProperty() rank = db.RatingProperty() cost = db.FloatProperty() status = db.StringProperty(choices=('open', 'completed')) accomplishDate = db.DateProperty() private = db.BooleanProperty(default=False) flickrImage = db.TextProperty(default="") location = db.StringProperty(default="") referringItem = db.StringProperty(default=None) addedTotal = db.IntegerProperty(default=1) completedTotal = db.IntegerProperty(default=0)
class Everything(db.Model): str = db.StringProperty() bool = db.BooleanProperty() int = db.IntegerProperty() float = db.FloatProperty() datetime = db.DateTimeProperty() date = db.DateProperty() time = db.TimeProperty() list = db.ListProperty(types.IntType) strlist = db.StringListProperty() user = db.UserProperty() blob = db.BlobProperty() text = db.TextProperty() category = db.CategoryProperty() link = db.LinkProperty() email = db.EmailProperty() geopt = db.GeoPtProperty() im = db.IMProperty() phonenumber = db.PhoneNumberProperty() postaladdress = db.PostalAddressProperty() rating = db.RatingProperty()
class QuoteURLUser(db.Model): name = db.StringProperty() description = db.StringProperty() screen_name = db.StringProperty() profile_image_url = db.LinkProperty() url = db.LinkProperty() twitter_screen_name = db.LinkProperty() github_screen_name = db.LinkProperty() email = db.EmailProperty() secondary_emails = db.ListProperty(unicode) location = db.StringProperty() geo_point = db.GeoPtProperty() quotes_created = db.IntegerProperty(default=0) birthday = db.DateTimeProperty() created_date = db.DateTimeProperty(auto_now_add=True) updated_date = db.DateTimeProperty(auto_now=True) membership_type = db.StringProperty() google_user = db.UserProperty() twitter_user = db.ReferenceProperty(TwitterUser) #requires claim github_user = db.ReferenceProperty(GitHubUser) #requires claim rating = db.RatingProperty() # not real time latest_rating_update = db.DateTimeProperty()
class Comment(db.Model): created_at = db.DateTimeProperty(auto_now_add=True) comment = db.TextProperty(required=True) rating = db.RatingProperty(required=True) tags = db.StringListProperty(default=[]) @classmethod def create(cls, comment, rating, tags): new_comment = cls(comment=comment, rating=rating, tags=tags) new_comment.put() return new_comment @classmethod def comments_for_tags(cls, tags=[], limit=20): comments = cls.all() for tag in tags: comments.filter('tags =', tag) comments.order('-created_at') return [{ 'comment': comment.comment, 'rating': comment.rating, 'subtag': comment.tags[-1] } for comment in comments.fetch(limit)]
class SurveyResponse(db.Model): def __init__(self, *args, **kwargs): kwargs['key_name'] = "%s-%s" % (kwargs['candidacy'].name(), kwargs['refined_issue'].name()) super(SurveyResponse, self).__init__(*args, **kwargs) candidacy = db.ReferenceProperty(Candidacy, required=True) refined_issue = db.ReferenceProperty(RefinedIssue, required=True) national = db.BooleanProperty() # 100 = strongly agree, 0 = strongly disagree agreement = db.RatingProperty(required=True) more_explanation = db.StringProperty( multiline=True) # maximum 500 characters, indexed def deleted(self): return self.refined_issue.deleted or self.candidacy.deleted def verb(self): return agreement_verb[self.agreement] def verb_you(self): return agreement_verb_you[self.agreement]