Spaces:
Sleeping
Sleeping
Update matching.py
Browse files- matching.py +7 -3
matching.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
from typing import List, Dict
|
| 2 |
from models import Profile
|
| 3 |
|
| 4 |
-
|
| 5 |
def calculate_local_matches(
|
| 6 |
current: Profile,
|
| 7 |
candidates: List[Profile],
|
|
@@ -13,16 +12,21 @@ def calculate_local_matches(
|
|
| 13 |
if c.id == current.id:
|
| 14 |
continue
|
| 15 |
|
|
|
|
| 16 |
score = 0
|
| 17 |
score += len(set(c.offers) & set(current.wants)) * 30
|
| 18 |
score += len(set(current.offers) & set(c.wants)) * 30
|
|
|
|
| 19 |
|
| 20 |
matches.append({
|
| 21 |
"id": c.id,
|
| 22 |
"username": c.username,
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
"avatar": c.avatar,
|
|
|
|
|
|
|
| 26 |
})
|
| 27 |
|
|
|
|
| 28 |
return sorted(matches, key=lambda x: x["score"], reverse=True)[:top_k]
|
|
|
|
| 1 |
from typing import List, Dict
|
| 2 |
from models import Profile
|
| 3 |
|
|
|
|
| 4 |
def calculate_local_matches(
|
| 5 |
current: Profile,
|
| 6 |
candidates: List[Profile],
|
|
|
|
| 12 |
if c.id == current.id:
|
| 13 |
continue
|
| 14 |
|
| 15 |
+
# Calculate score based on skill overlap
|
| 16 |
score = 0
|
| 17 |
score += len(set(c.offers) & set(current.wants)) * 30
|
| 18 |
score += len(set(current.offers) & set(c.wants)) * 30
|
| 19 |
+
score = min(1.0, score / 100) # Normalize to 0-1
|
| 20 |
|
| 21 |
matches.append({
|
| 22 |
"id": c.id,
|
| 23 |
"username": c.username,
|
| 24 |
+
"offers": c.offers,
|
| 25 |
+
"wants": c.wants,
|
| 26 |
"avatar": c.avatar,
|
| 27 |
+
"score": score, # 0-1 float
|
| 28 |
+
"reason": "Local scoring",
|
| 29 |
})
|
| 30 |
|
| 31 |
+
# Sort descending and take top_k
|
| 32 |
return sorted(matches, key=lambda x: x["score"], reverse=True)[:top_k]
|