From 0c23956dd2b23a1bcd50bfaa9873d49b674cc816 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 21 Jan 2023 23:25:50 +0000 Subject: [PATCH] Report on hashtags, followed and unfollowed, complete. --- app/urma.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/urma.py b/app/urma.py index 2e98e46..2aff53d 100755 --- a/app/urma.py +++ b/app/urma.py @@ -311,6 +311,37 @@ def report(): f"({like * 100 / (like + dislike):.2f}% liked)" ) + # Find the least popular hashtags that we do follow + print() + print("Hashtags you follow that feature in posts you don't like") + print("--------------------------------------------------------") + bottom_followed_tags = ( + session.execute( + select(Hashtags, func.count(Hashtags.name)) + .join(PostTags).join(Posts) + .where(Posts.favourited == 0, Hashtags.followed == 1) + .group_by(Hashtags.name) + .order_by(func.count(Hashtags.name).desc()) + .limit(Config.TOP_HASHTAGS_TO_REPORT)) + .all() + ) + + # How many times was each hashtag in a post we did like? + for (hashtag, dislike) in bottom_followed_tags: + like = ( + session.execute( + select(func.count(Posts.id)) + .join(PostTags).join(Hashtags) + .where(Posts.favourited == 1, Hashtags.id == hashtag.id) + ).scalars() + .all()[0] + ) + + print( + f"Hashtag {hashtag.name} {like=}, {dislike=} " + f"({dislike * 100 / (like + dislike):.2f}% disliked)" + ) + def update_followed_accounts(session: Session, mastapi: MastodonAPI) -> None: """ @@ -374,8 +405,8 @@ def update_followed_hashtags(session: Session, mastapi: MastodonAPI) -> None: set(our_followed_hashtags_d.keys()) - set(mast_followed_hashtags_d.keys()) ): - hashtag = hashtags.get_or_create( - session, name, our_followed_hashtags_d[username].name) + hashtag = Hashtags.get_or_create( + session, name, our_followed_hashtags_d[name].name) hashtag.followed = False