Added user reports

This commit is contained in:
Keith Edmunds 2023-01-21 23:37:16 +00:00
parent 0c23956dd2
commit d40579e695

View File

@ -342,6 +342,68 @@ def report():
f"({dislike * 100 / (like + dislike):.2f}% disliked)"
)
# Find the most popular users that we don't follow
print()
print("Users you don't follow that feature in posts you like")
print("-----------------------------------------------------")
top_unfollowed_users = (
session.execute(
select(Accounts, func.count(Accounts.username))
.join(Posts)
.where(Posts.favourited == 1, Accounts.followed == 0)
.group_by(Accounts.username)
.order_by(func.count(Accounts.username).desc())
.limit(Config.TOP_POSTS_TO_REPORT))
.all()
)
# How many times was each user in a post we didnt' like?
for (user, like) in top_unfollowed_users:
dislike = (
session.execute(
select(func.count(Posts.id))
.join(Accounts)
.where(Posts.favourited == 0, Accounts.id == user.id)
).scalars()
.all()[0]
)
print(
f"User {user.username} {like=}, {dislike=} "
f"({like * 100 / (like + dislike):.2f}% liked)"
)
# Find the most unpopular users that we do follow
print()
print("Users you follow that feature in posts you don't like")
print("-----------------------------------------------------")
bottom_followed_users = (
session.execute(
select(Accounts, func.count(Accounts.username))
.join(Posts)
.where(Posts.favourited == 0, Accounts.followed == 1)
.group_by(Accounts.username)
.order_by(func.count(Accounts.username).desc())
.limit(Config.TOP_POSTS_TO_REPORT))
.all()
)
# How many times was each user in a post we did like?
for (user, dislike) in bottom_followed_users:
like = (
session.execute(
select(func.count(Posts.id))
.join(Accounts)
.where(Posts.favourited == 1, Accounts.id == user.id)
).scalars()
.all()[0]
)
print(
f"User {user.username} {like=}, {dislike=} "
f"({dislike * 100 / (like + dislike):.2f}% disliked)"
)
def update_followed_accounts(session: Session, mastapi: MastodonAPI) -> None:
"""