Skip to content

Commit 641564e

Browse files
authored
Merge pull request #154 from Seluj78/heat_score
2 parents a3b679c + 6db38a0 commit 641564e

File tree

4 files changed

+202
-2
lines changed

4 files changed

+202
-2
lines changed

PyMatcha.postman_collection.json

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,6 +3659,182 @@
36593659
}
36603660
},
36613661
"response": []
3662+
},
3663+
{
3664+
"name": "Edit geolocation with ip",
3665+
"event": [
3666+
{
3667+
"listen": "test",
3668+
"script": {
3669+
"id": "39231db4-62ff-4230-8a9f-d6bcda2e91ad",
3670+
"exec": [
3671+
"var response = JSON.parse(responseBody);",
3672+
"",
3673+
"",
3674+
"pm.test(\"Status code is 200\", function () {",
3675+
" pm.response.to.have.status(200);",
3676+
"});",
3677+
"",
3678+
"",
3679+
"tests[\"success is true\"] = response.success == true",
3680+
"tests[\"Message is correct\"] = response.message == \"New location sucessfully saved.\""
3681+
],
3682+
"type": "text/javascript"
3683+
}
3684+
}
3685+
],
3686+
"request": {
3687+
"method": "PUT",
3688+
"header": [],
3689+
"body": {
3690+
"mode": "raw",
3691+
"raw": "{\n\t\"ip\": \"{{user_ip}}\"\n}",
3692+
"options": {
3693+
"raw": {
3694+
"language": "json"
3695+
}
3696+
}
3697+
},
3698+
"url": {
3699+
"raw": "{{host}}/profile/edit/geolocation",
3700+
"host": [
3701+
"{{host}}"
3702+
],
3703+
"path": [
3704+
"profile",
3705+
"edit",
3706+
"geolocation"
3707+
]
3708+
}
3709+
},
3710+
"response": []
3711+
},
3712+
{
3713+
"name": "Get one user after ip geoloc edit",
3714+
"event": [
3715+
{
3716+
"listen": "test",
3717+
"script": {
3718+
"id": "499a0ac6-2355-490c-8f0f-010c397591be",
3719+
"exec": [
3720+
"var response = JSON.parse(responseBody);",
3721+
"",
3722+
"",
3723+
"pm.test(\"Status code is 200\", function () {",
3724+
" pm.response.to.have.status(200);",
3725+
"});",
3726+
"",
3727+
"user_email = pm.collectionVariables.get(\"user_email\");",
3728+
"",
3729+
"tests[\"Is geohash correct\"] = response.geohash == \"ezzweqbd4wuk\""
3730+
],
3731+
"type": "text/javascript"
3732+
}
3733+
}
3734+
],
3735+
"request": {
3736+
"method": "GET",
3737+
"header": [],
3738+
"url": {
3739+
"raw": "{{host}}/users/{{user_email}}",
3740+
"host": [
3741+
"{{host}}"
3742+
],
3743+
"path": [
3744+
"users",
3745+
"{{user_email}}"
3746+
]
3747+
}
3748+
},
3749+
"response": []
3750+
},
3751+
{
3752+
"name": "Edit geolocation with lat lng",
3753+
"event": [
3754+
{
3755+
"listen": "test",
3756+
"script": {
3757+
"id": "6f2ec5c9-96dc-4e1b-af46-96352d0d2135",
3758+
"exec": [
3759+
"var response = JSON.parse(responseBody);",
3760+
"",
3761+
"",
3762+
"pm.test(\"Status code is 200\", function () {",
3763+
" pm.response.to.have.status(200);",
3764+
"});",
3765+
"",
3766+
"",
3767+
"tests[\"success is true\"] = response.success == true",
3768+
"tests[\"Message is correct\"] = response.message == \"New location sucessfully saved.\""
3769+
],
3770+
"type": "text/javascript"
3771+
}
3772+
}
3773+
],
3774+
"request": {
3775+
"method": "PUT",
3776+
"header": [],
3777+
"body": {
3778+
"mode": "raw",
3779+
"raw": "{\n\t\"ip\": \"{{user_ip}}\",\n\t\"lat\": {{user_lat}},\n\t\"lng\": {{user_lng}}\n}",
3780+
"options": {
3781+
"raw": {
3782+
"language": "json"
3783+
}
3784+
}
3785+
},
3786+
"url": {
3787+
"raw": "{{host}}/profile/edit/geolocation",
3788+
"host": [
3789+
"{{host}}"
3790+
],
3791+
"path": [
3792+
"profile",
3793+
"edit",
3794+
"geolocation"
3795+
]
3796+
}
3797+
},
3798+
"response": []
3799+
},
3800+
{
3801+
"name": "Get one user after lat lng edit",
3802+
"event": [
3803+
{
3804+
"listen": "test",
3805+
"script": {
3806+
"id": "14daee88-fcc1-4a60-8100-45eded9ecbd8",
3807+
"exec": [
3808+
"var response = JSON.parse(responseBody);",
3809+
"",
3810+
"",
3811+
"pm.test(\"Status code is 200\", function () {",
3812+
" pm.response.to.have.status(200);",
3813+
"});",
3814+
"",
3815+
"user_email = pm.collectionVariables.get(\"user_email\");",
3816+
"",
3817+
"tests[\"Is geohash correct\"] = response.geohash == \"ezzx4fcq327u\""
3818+
],
3819+
"type": "text/javascript"
3820+
}
3821+
}
3822+
],
3823+
"request": {
3824+
"method": "GET",
3825+
"header": [],
3826+
"url": {
3827+
"raw": "{{host}}/users/{{user_email}}",
3828+
"host": [
3829+
"{{host}}"
3830+
],
3831+
"path": [
3832+
"users",
3833+
"{{user_email}}"
3834+
]
3835+
}
3836+
},
3837+
"response": []
36623838
}
36633839
],
36643840
"protocolProfileBehavior": {}

backend/PyMatcha/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,4 @@ def no_jwt_callback(error_message):
240240

241241
# import tasks here to be registered by celery
242242

243-
import PyMatcha.utils.user_online_management # noqa
243+
import PyMatcha.utils.tasks # noqa

backend/PyMatcha/utils/tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _create_user_table(db):
4141
orientation ENUM('heterosexual', 'homosexual', 'bisexual', 'other'),
4242
birthdate DATE DEFAULT NULL,
4343
geohash VARCHAR(256) DEFAULT NULL,
44-
heat_score INT DEFAULT (0),
44+
heat_score INT DEFAULT NULL,
4545
date_joined DATETIME DEFAULT NOW(),
4646
date_lastseen DATETIME DEFAULT NOW(),
4747
previous_reset_token VARCHAR(256),

backend/PyMatcha/utils/user_online_management.py renamed to backend/PyMatcha/utils/tasks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
@celery.on_after_configure.connect
1010
def setup_periodic_tasks(sender, **kwargs):
1111
sender.add_periodic_task(60, update_offline_users.s(), name="Update online users every minute")
12+
sender.add_periodic_task(10, update_popularity_scores.s(), name="Update popularity scores every minute")
13+
14+
15+
@celery.task
16+
def update_popularity_scores():
17+
# TODO: If user is Jules or Guilhem: +100 score
18+
19+
for user in User.select_all():
20+
likes_received = len(user.get_likes_received())
21+
reports_received = len(user.get_reports_received())
22+
views = len(user.get_views())
23+
24+
# TODO: Add matches
25+
# TODO: Add messages
26+
27+
points = 30
28+
points += likes_received * 2
29+
# TODO: Superlike received = 5 pts
30+
points -= reports_received * 10
31+
points += views
32+
# TODO: remove 5 pts per week of inactivity
33+
user.heat_score = points
34+
user.save()
35+
return f"Updated heat score for user {user.id}: {user.heat_score}."
1236

1337

1438
@celery.task

0 commit comments

Comments
 (0)