Skip to content

Commit 4a9c7a5

Browse files
committed
Fixed error in distance function and in extend queery for gender queries
1 parent f0e6950 commit 4a9c7a5

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

backend/PyMatcha/utils/match_score.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import itertools
22
from typing import List
3+
from typing import Optional
34

45
from fuzzywuzzy import fuzz
56
from Geohash import decode
67
from geopy.distance import distance
78
from PyMatcha.models.user import User
89

910

10-
def _get_distance(geohash_1: str, geohash_2: str) -> float:
11-
coords_1 = decode(geohash_1)
12-
coords_2 = decode(geohash_2)
13-
return distance(coords_1, coords_2).kilometers
11+
def _get_distance(geohash_1: str, geohash_2: str) -> Optional[float]:
12+
try:
13+
coords_1 = decode(geohash_1)
14+
coords_2 = decode(geohash_2)
15+
except TypeError:
16+
return None
17+
else:
18+
return distance(coords_1, coords_2).kilometers
1419

1520

1621
def _get_common_tags(tag_list_1: list, tag_list_2: list) -> List[str]:
@@ -33,28 +38,34 @@ def _get_gender_query(orientation, gender):
3338
if gender == "female":
3439
q1 = User.get_multis(orientation=orientation, gender="male")
3540
q2 = User.get_multis(orientation="other", gender="male")
36-
return q1.extend(q2)
41+
q1.extend(q2)
42+
return q1
3743
elif gender == "male":
3844
q1 = User.get_multis(orientation=orientation, gender="female")
3945
q2 = User.get_multis(orientation="other", gender="female")
40-
return q1.extend(q2)
46+
q1.extend(q2)
47+
return q1
4148
else:
4249
q1 = User.get_multis(orientation=orientation, gender="female")
4350
q2 = User.get_multis(orientation=orientation, gender="male")
44-
return q1.extend(q2)
51+
q1.extend(q2)
52+
return q1
4553
elif orientation == "homosexual":
4654
if gender == "female":
4755
q1 = User.get_multis(orientation=orientation, gender="female")
4856
q2 = User.get_multis(orientation="other", gender="female")
49-
return q1.extend(q2)
57+
q1.extend(q2)
58+
return q1
5059
elif gender == "male":
5160
q1 = User.get_multis(orientation=orientation, gender="male")
5261
q2 = User.get_multis(orientation="other", gender="male")
53-
return q1.extend(q2)
62+
q1.extend(q2)
63+
return q1
5464
else:
5565
q1 = User.get_multis(orientation=orientation, gender="female")
5666
q2 = User.get_multis(orientation=orientation, gender="male")
57-
return q1.extend(q2)
67+
q1.extend(q2)
68+
return q1
5869
elif orientation == "bisexual":
5970
q1 = User.get_multis(orientation=orientation, gender="female")
6071
q3 = User.get_multis(orientation=orientation, gender="male")

0 commit comments

Comments
 (0)