本文整理汇总了Python中model.Comment.query方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.query方法的具体用法?Python Comment.query怎么用?Python Comment.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Comment
的用法示例。
在下文中一共展示了Comment.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _photo_with_most_comments
# 需要导入模块: from model import Comment [as 别名]
# 或者: from model.Comment import query [as 别名]
def _photo_with_most_comments(self, data):
'''Find the photograph with the most comments.'''
comment_count = defaultdict(int)
for comment in Comment.query():
comment_count[comment.photo] += 1
if not comment_count:
return
max_comments = max(comment_count.values())
for photo, comments in comment_count.items():
if comments == max_comments:
user_id = photo.get().user.id()
data[user_id].most_comments_photo = 1
示例2: get
# 需要导入模块: from model import Comment [as 别名]
# 或者: from model.Comment import query [as 别名]
def get(self):
logging.info('stats calculator...starting')
# create a UserStat object for all Users in the db
users = list(User.query().fetch())
data = dict(
(user.key.id(), UserStats(user=user.key))
for user in users
)
for user in users:
user_stat = data[user.key.id()]
user_stat.logins = user.login_count
user_stat.logouts = user.logout_count
user_stat.bio = 1 if user.bio else 0
for photo in Photo.query().fetch():
user_id = photo.user.id()
user_stat = data[user_id]
if photo.competition is None:
user_stat.extra_photos += 1
else:
if photo.competition.get().status != COMPLETED:
# not interested in competition photos for incomplete
# competitions
continue
user_stat.comp_photos += 1
user_stat.total_points += photo.total_score
if photo.position == 1:
user_stat.first_place += 1
user_stat.medals += 1
elif photo.position == 2:
user_stat.second_place += 1
user_stat.medals += 1
elif photo.position == 3:
user_stat.third_place += 1
user_stat.medals += 1
completed_comp_count = Competition.count()
for user_stat in data.values():
if user_stat.comp_photos == completed_comp_count:
user_stat.all_comps = 1
for comment in Comment.query().fetch():
# give
data[comment.user.id()].comments_give += 1
# receive
receiver = comment.photo.get().user.id()
data[receiver].comments_receive += 1
for score in Scores.query().fetch():
receiver = score.photo.get().user.id()
if score.score == 10:
# give 10
data[score.user_from.id()].score_10_give += 1
# receive 10
data[receiver].score_10_receive += 1
elif score.score == 0:
# give 0
data[score.user_from.id()].score_0_give += 1
# receive 0
data[receiver].score_0_recieve += 1
for note in Note.query().fetch():
data[note.user.id()].notes += 1
# is this person a GIVER
for user in data.values():
if user.comments_give > user.comments_receive:
user.giver += 1
if user.score_10_give > user.score_10_receive:
user.giver += 1
# last place finishers
self._last_positions(data)
self._photo_with_most_comments(data)
self._photo_with_high_score(data)
self._houses(data)
self._most(data, 'comments_give')
self._most(data, 'comments_receive')
self._most(data, 'notes')
self._most(data, 'logins')
self._most(data, 'logouts')
self._most(data, 'medals')
self._most(data, 'first_place')
self._most(data, 'second_place')
self._most(data, 'third_place')
self._most(data, 'last_place')
UserStats.delete_all()
for stat in data.values():
stat.put()
logging.info(data)
logging.info('stats calculator...finished')