Exemplo n.º 1
0
    def get(self):
        results_template = JINJA_ENVIRONMENT.get_template('templates/profile.html')
        all_posts = Post.query().fetch()
        user_key = Key('User', self.session.get('user_key_id'))
        user_posts = Post.query(Post.author_key == user_key).order(-Post.date_time).fetch()
        all_comments = Comment.query().order(Comment.date_time).fetch()

        for post in all_posts:
            author = post.author_key.get()
            post.author_name = author.first_name + ' ' + author.last_name
            post.author_pic = author.dp_url
            author.put()

        for comment in all_comments:
            author = comment.author_key.get()
            comment.author_name = author.first_name + ' ' + author.last_name
            author.put()

        info = {
            'first_name' : self.session.get('f_name'),
            'last_name' : self.session.get('l_name'),
            'email' : self.session.get('email'),
            'dp_url' : self.session.get('dp_url'),
            'user_posts' : user_posts,
            'all_comments' : all_comments
        }
        self.response.write(results_template.render(info))
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    def get(self):
        if (self.session.get('email') == None):
            self.redirect('/')

        results_template = JINJA_ENVIRONMENT.get_template('templates/index.html')

        user = User(first_name = self.session.get('f_name'),
                    last_name = self.session.get('l_name'),
                    dp_url = self.session.get('dp_url'),
                    email = self.session.get('email'),)
        if not (User.query(User.email == user.email).fetch()):
            self.session['user_key_id'] = user.put().id()
        else:
            self.session['user_key_id'] = User.query(User.email == user.email).fetch()[0].key.id()
        all_users = User.query().fetch()
        all_posts = Post.query().order(-Post.date_time).fetch()
        all_comments = Comment.query().order(Comment.date_time).fetch()

        for post in all_posts:
            author = post.author_key.get()
            post.author_name = author.first_name + ' ' + author.last_name
            post.author_pic = author.dp_url
            author.put()

        for comment in all_comments:
            author = comment.author_key.get()
            comment.author_name = author.first_name + ' ' + author.last_name
            author.put()

        info = {
            'first_name' : self.session.get('f_name'),
            'last_name' : self.session.get('l_name'),
            'dp_url' : self.session.get('dp_url'),
            'email' : self.session.get('email'),
            'all_posts' : all_posts,
            'all_users' : all_users,
            'all_comments' : all_comments
        }

        self.response.write(results_template.render(info))
Exemplo n.º 4
0
    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')