Skip to content

Commit 369825e

Browse files
authored
Merge pull request #358 from Seluj78/10pts-innactivity
2 parents 9031e8b + edb831f commit 369825e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

backend/PyMatcha/utils/tasks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
REPORTS_MULTIPLIER = 10
1616
VIEW_MULTIPLIER = 1
1717
MESSAGES_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

0 commit comments

Comments
 (0)