Skip to content

Commit b91f08e

Browse files
committed
Updated gender query to use all genders and orientations
1 parent ac8cfb5 commit b91f08e

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

backend/PyMatcha/utils/match_score.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import itertools
12
from typing import List
23

34
from fuzzywuzzy import fuzz
45
from Geohash import decode
56
from geopy.distance import distance
7+
from PyMatcha.models.user import User
68

79

810
def _get_distance(geohash_1: str, geohash_2: str) -> float:
@@ -26,11 +28,58 @@ def _get_age_diff(age_1: int, age_2: int) -> int:
2628
return -1 * (age_1 - age_2)
2729

2830

29-
def _get_inverted_gender(gender, orientation):
30-
# TODO: Handle other gender and bisexual and other orientations
31+
def _get_gender_query(orientation, gender):
3132
if orientation == "heterosexual":
32-
return "male" if gender == "female" else "female"
33+
if gender == "female":
34+
q1 = User.get_multis(orientation=orientation, gender="male")
35+
q2 = User.get_multis(orientation="other", gender="male")
36+
return q1.extend(q2)
37+
elif gender == "male":
38+
q1 = User.get_multis(orientation=orientation, gender="female")
39+
q2 = User.get_multis(orientation="other", gender="female")
40+
return q1.extend(q2)
41+
else:
42+
q1 = User.get_multis(orientation=orientation, gender="female")
43+
q2 = User.get_multis(orientation=orientation, gender="male")
44+
return q1.extend(q2)
3345
elif orientation == "homosexual":
34-
return "male" if gender == "male" else "female"
46+
if gender == "female":
47+
q1 = User.get_multis(orientation=orientation, gender="female")
48+
q2 = User.get_multis(orientation="other", gender="female")
49+
return q1.extend(q2)
50+
elif gender == "male":
51+
q1 = User.get_multis(orientation=orientation, gender="male")
52+
q2 = User.get_multis(orientation="other", gender="male")
53+
return q1.extend(q2)
54+
else:
55+
q1 = User.get_multis(orientation=orientation, gender="female")
56+
q2 = User.get_multis(orientation=orientation, gender="male")
57+
return q1.extend(q2)
58+
elif orientation == "bisexual":
59+
q1 = User.get_multis(orientation=orientation, gender="female")
60+
q3 = User.get_multis(orientation=orientation, gender="male")
61+
q2 = []
62+
q4 = []
63+
if gender == "female":
64+
q2 = User.get_multis(orientation="homosexual", gender="female")
65+
if gender == "male":
66+
q4 = User.get_multis(orientation="homosexual", gender="male")
67+
q5 = User.get_multis(orientation="other", gender="male")
68+
q6 = User.get_multis(orientation="other", gender="female")
69+
return list(set(list(itertools.chain(q1, q2, q3, q4, q5, q6))))
70+
elif orientation == "other":
71+
q1 = User.get_multis(orientation=orientation, gender="female")
72+
q3 = User.get_multis(orientation=orientation, gender="male")
73+
q2 = []
74+
q4 = []
75+
q5 = []
76+
q6 = []
77+
if gender == "female":
78+
q2 = User.get_multis(orientation="homosexual", gender="female")
79+
q5 = User.get_multis(orientation="heterosexual", gender="male")
80+
if gender == "male":
81+
q4 = User.get_multis(orientation="homosexual", gender="male")
82+
q6 = User.get_multis(orientation="heterosexual", gender="female")
83+
return list(set(list(itertools.chain(q1, q2, q3, q4, q5, q6))))
3584
else:
36-
return "other"
85+
raise ValueError("No match found for genre. This should not happen")

backend/PyMatcha/utils/tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from PyMatcha.utils.match_score import _get_age_diff
1111
from PyMatcha.utils.match_score import _get_common_tags
1212
from PyMatcha.utils.match_score import _get_distance
13-
from PyMatcha.utils.match_score import _get_inverted_gender
13+
from PyMatcha.utils.match_score import _get_gender_query
1414

1515

1616
@celery.on_after_configure.connect
@@ -115,9 +115,9 @@ def update_user_recommendations():
115115
)
116116
user_to_update_tags = [t.name for t in user_to_update.get_tags()]
117117

118-
inverted_gender = _get_inverted_gender(user_to_update.gender, user_to_update.orientation)
118+
query = _get_gender_query(user_to_update.orientation, user_to_update.gender)
119119

120-
for user in User.get_multis(orientation=user_to_update.orientation, gender=inverted_gender):
120+
for user in query:
121121
if user.id == user_to_update.id:
122122
continue
123123
score = 0

0 commit comments

Comments
 (0)