File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 1515REPORTS_MULTIPLIER = 10
1616VIEW_MULTIPLIER = 1
1717MESSAGES_DIVIDER = 5
18+ INACTIVITY_DIVIDER = 10
1819
1920
2021@celery .on_after_configure .connect
@@ -53,11 +54,19 @@ def update_heat_scores():
5354 score -= reports_received * REPORTS_MULTIPLIER
5455 score += views * VIEW_MULTIPLIER
5556 score += ceil (messages / MESSAGES_DIVIDER )
57+
58+ now = datetime .datetime .utcnow ()
59+ monday1 = now - datetime .timedelta (days = now .weekday ())
60+ monday2 = user .date_lastseen - datetime .timedelta (days = user .date_lastseen .weekday ())
61+ weeks_passed_since_last_activity = int ((monday1 - monday2 ).days / 7 )
62+
63+ score -= weeks_passed_since_last_activity * INACTIVITY_DIVIDER
64+
5665 if score < 0 :
5766 score = 0
5867 user .heat_score = score
5968 user .save ()
60- return f"Updated heat score for user { user . id } : { user . heat_score } ."
69+ return "Successfully updated heat scores ."
6170
6271
6372@celery .task
You can’t perform that action at this time.
0 commit comments