sdf
This commit is contained in:
parent
2dca7d3bc6
commit
456741ac96
2 changed files with 36 additions and 27 deletions
|
@ -14,12 +14,13 @@ class Vote(Base):
|
||||||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
real = Column(Boolean, default=True)
|
real = Column(Boolean, default=True)
|
||||||
|
created_utc = Column(Integer)
|
||||||
|
|
||||||
user = relationship("User", lazy="subquery", viewonly=True)
|
user = relationship("User", lazy="subquery", viewonly=True)
|
||||||
post = relationship("Submission", lazy="subquery", viewonly=True)
|
post = relationship("Submission", lazy="subquery", viewonly=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -55,12 +56,13 @@ class CommentVote(Base):
|
||||||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
real = Column(Boolean, default=True)
|
real = Column(Boolean, default=True)
|
||||||
|
created_utc = Column(Integer)
|
||||||
|
|
||||||
user = relationship("User", lazy="subquery")
|
user = relationship("User", lazy="subquery")
|
||||||
comment = relationship("Comment", lazy="subquery", viewonly=True)
|
comment = relationship("Comment", lazy="subquery", viewonly=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -64,33 +64,40 @@ def participation_stats(v):
|
||||||
def stats():
|
def stats():
|
||||||
day = int(time.time()) - 86400
|
day = int(time.time()) - 86400
|
||||||
|
|
||||||
|
week = int(time.time()) - 604800
|
||||||
|
active_users = set()
|
||||||
|
posters = g.db.query(Submission.author_id).distinct(Submission.author_id).filter(Submission.created_utc > week).all()
|
||||||
|
commenters = g.db.query(Comment.author_id).distinct(Comment.author_id).filter(Comment.created_utc > week).all()
|
||||||
|
active_users = set(posters) | set(commenters)
|
||||||
|
|
||||||
return {"marseys": g.db.query(Marsey.name).count(),
|
return {"marseys": g.db.query(Marsey.name).count(),
|
||||||
"users": g.db.query(User.id).count(),
|
"users": g.db.query(User.id).count(),
|
||||||
"private_users": g.db.query(User.id).filter_by(is_private=True).count(),
|
"private users": g.db.query(User.id).filter_by(is_private=True).count(),
|
||||||
"banned_users": g.db.query(User.id).filter(User.is_banned > 0).count(),
|
"banned users": g.db.query(User.id).filter(User.is_banned > 0).count(),
|
||||||
"verified_email_users": g.db.query(User.id).filter_by(is_activated=True).count(),
|
"verified email users": g.db.query(User.id).filter_by(is_activated=True).count(),
|
||||||
"coins_in_circulation": g.db.query(func.sum(User.coins)).scalar(),
|
"coins in circulation": g.db.query(func.sum(User.coins)).scalar(),
|
||||||
"total_shop_sales": g.db.query(func.sum(User.coins_spent)).scalar(),
|
"total shop sales": g.db.query(func.sum(User.coins_spent)).scalar(),
|
||||||
"signups_last_24h": g.db.query(User.id).filter(User.created_utc > day).count(),
|
"signups last 24h": g.db.query(User.id).filter(User.created_utc > day).count(),
|
||||||
"total_posts": g.db.query(Submission.id).count(),
|
"total posts": g.db.query(Submission.id).count(),
|
||||||
"posting_users": g.db.query(Submission.author_id).distinct().count(),
|
"posting users": g.db.query(Submission.author_id).distinct().count(),
|
||||||
"listed_posts": g.db.query(Submission.id).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
|
"listed posts": g.db.query(Submission.id).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
|
||||||
"removed_posts": g.db.query(Submission.id).filter_by(is_banned=True).count(),
|
"removed posts": g.db.query(Submission.id).filter_by(is_banned=True).count(),
|
||||||
"deleted_posts": g.db.query(Submission.id).filter(Submission.deleted_utc > 0).count(),
|
"deleted posts": g.db.query(Submission.id).filter(Submission.deleted_utc > 0).count(),
|
||||||
"posts_last_24h": g.db.query(Submission.id).filter(Submission.created_utc > day).count(),
|
"posts last 24h": g.db.query(Submission.id).filter(Submission.created_utc > day).count(),
|
||||||
"total_comments": g.db.query(Comment.id).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
"total comments": g.db.query(Comment.id).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
||||||
"commenting_users": g.db.query(Comment.author_id).distinct().count(),
|
"commenting users": g.db.query(Comment.author_id).distinct().count(),
|
||||||
"removed_comments": g.db.query(Comment.id).filter_by(is_banned=True).count(),
|
"removed comments": g.db.query(Comment.id).filter_by(is_banned=True).count(),
|
||||||
"deleted_comments": g.db.query(Comment.id).filter(Comment.deleted_utc > 0).count(),
|
"deleted comments": g.db.query(Comment.id).filter(Comment.deleted_utc > 0).count(),
|
||||||
"comments_last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
"comments last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
||||||
"post_votes": g.db.query(Vote.id).count(),
|
"post votes": g.db.query(Vote.id).count(),
|
||||||
"post_voting_users": g.db.query(Vote.user_id).distinct().count(),
|
"post voting users": g.db.query(Vote.user_id).distinct().count(),
|
||||||
"comment_votes": g.db.query(CommentVote.id).count(),
|
"comment votes": g.db.query(CommentVote.id).count(),
|
||||||
"comment_voting_users": g.db.query(CommentVote.user_id).distinct().count(),
|
"comment voting users": g.db.query(CommentVote.user_id).distinct().count(),
|
||||||
"total_upvotes": g.db.query(Vote.id).filter_by(vote_type=1).count() + g.db.query(CommentVote.id).filter_by(vote_type=1).count(),
|
"total upvotes": g.db.query(Vote.id).filter_by(vote_type=1).count() + g.db.query(CommentVote.id).filter_by(vote_type=1).count(),
|
||||||
"total_downvotes": g.db.query(Vote.id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.id).filter_by(vote_type=-1).count(),
|
"total downvotes": g.db.query(Vote.id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.id).filter_by(vote_type=-1).count(),
|
||||||
"total_awards": g.db.query(AwardRelationship.id).count(),
|
"total awards": g.db.query(AwardRelationship.id).count(),
|
||||||
"awards_given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count()
|
"awards given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
|
||||||
|
"users who posted or commented in the past 7 days": len(active_users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.get("/chart")
|
@app.get("/chart")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue