diff --git a/app/models.py b/app/models.py index e9413237..c09a9745 100644 --- a/app/models.py +++ b/app/models.py @@ -687,7 +687,7 @@ class User(UserMixin, db.Model): bounces = db.Column(db.SmallInteger, default=0) timezone = db.Column(db.String(20)) reputation = db.Column(db.Float, default=0.0) - attitude = db.Column(db.Float, default=1.0) # (upvotes cast - downvotes cast) / (upvotes + downvotes). A number between 1 and -1 is the ratio between up and down votes they cast + attitude = db.Column(db.Float, default=None) # (upvotes cast - downvotes cast) / (upvotes + downvotes). A number between 1 and -1 is the ratio between up and down votes they cast post_count = db.Column(db.Integer, default=0) post_reply_count = db.Column(db.Integer, default=0) stripe_customer_id = db.Column(db.String(50)) @@ -934,13 +934,10 @@ class User(UserMixin, db.Model): total_upvotes = upvotes + comment_upvotes total_downvotes = downvotes + comment_downvotes - if total_downvotes == 0: # guard against division by zero - self.attitude = 1.0 + if total_upvotes + total_downvotes > 2: # Only calculate attitude if they've done 3 or more votes as anything less than this could be an outlier and not representative of their overall attitude (also guard against division by zero) + self.attitude = (total_upvotes - total_downvotes) / (total_upvotes + total_downvotes) else: - if total_upvotes + total_downvotes > 2: # Only calculate attitude if they've done 3 or more votes as anything less than this could be an outlier and not representative of their overall attitude - self.attitude = (total_upvotes - total_downvotes) / (total_upvotes + total_downvotes) - else: - self.attitude = 1.0 + self.attitude = None def recalculate_post_stats(self, posts=True, replies=True): if posts: diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index af7d5223..5f14afb4 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -50,9 +50,9 @@ - @@ -77,7 +77,7 @@ {{ 'Banned posts'|safe if user.ban_posts }} {{ 'Banned comments'|safe if user.ban_comments }} {{ user.reports if user.reports > 0 }} - {% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %} + {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %} {% if user.reputation %}R {{ user.reputation | round | int }}{% endif %} {{ arrow.get(user.last_seen).humanize(locale=locale) }} Edit, diff --git a/app/templates/user/show_profile.html b/app/templates/user/show_profile.html index a9743eba..276c0ea5 100644 --- a/app/templates/user/show_profile.html +++ b/app/templates/user/show_profile.html @@ -116,7 +116,7 @@ {% if user.bot %} {{ _('Bot Account') }}
{% endif %} - {{ _('Attitude') }}: {{ (user.attitude * 100) | round | int }}%
+ {{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: {{ user.reputation | round | int }}
{% endif %} {{ _('Posts') }}: {{ user.post_count }}
{{ _('Comments') }}: {{ user.post_reply_count }}
diff --git a/app/templates/user/user_preview.html b/app/templates/user/user_preview.html index fa98f797..cba88076 100644 --- a/app/templates/user/user_preview.html +++ b/app/templates/user/user_preview.html @@ -22,7 +22,7 @@ {% if user.bot %} {{ _('Bot Account') }}
{% endif %} - {{ _('Attitude') }}: {{ (user.attitude * 100) | round | int }}%
+ {{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: {{ user.reputation | round | int }}
{% endif %} {{ _('Posts') }}: {{ user.post_count }}
{{ _('Comments') }}: {{ user.post_reply_count }}
@@ -54,4 +54,4 @@ - \ No newline at end of file + diff --git a/app/utils.py b/app/utils.py index 46bbca9f..77ccbe7a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -706,7 +706,7 @@ def can_downvote(user, community: Community, site=None) -> bool: if community.local_only and not user.is_local(): return False - if user.attitude < -0.40 or user.reputation < -10: # this should exclude about 3.7% of users. + if (user.attitude and user.attitude < -0.40) or user.reputation < -10: # this should exclude about 3.7% of users. return False if community.id in communities_banned_from(user.id):