当前位置: 首页>>代码示例>>Python>>正文


Python Comment.query方法代码示例

本文整理汇总了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
开发者ID:PreludeAndFugue,项目名称:prelude-hmpc,代码行数:16,代码来源:stats.py

示例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')
开发者ID:PreludeAndFugue,项目名称:prelude-hmpc,代码行数:98,代码来源:stats.py


注:本文中的model.Comment.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。