AI-Skill-Connector / matching.py
BasitAliii's picture
Update matching.py
db3ea53 verified
from typing import List, Dict
from models import Profile
def calculate_local_matches(
current: Profile,
candidates: List[Profile],
top_k: int = 3,
) -> List[Dict]:
"""
Calculate local matches based on skill overlap.
Returns scores normalized between 0.0 and 1.0
"""
matches: List[Dict] = []
for c in candidates:
if c.id == current.id:
continue
score_points = 0
# Candidate offers what current wants
score_points += len(set(c.offers) & set(current.wants)) * 30
# Current offers what candidate wants
score_points += len(set(current.offers) & set(c.wants)) * 30
# Normalize β†’ max 100 points β†’ 0.0–1.0
score = min(score_points / 100.0, 1.0)
matches.append({
"id": c.id,
"username": c.username,
"offers": c.offers,
"wants": c.wants,
"avatar": c.avatar,
"score": round(score, 3), # ALWAYS 0–1
"reason": "Local scoring"
})
return sorted(matches, key=lambda x: x["score"], reverse=True)[:top_k]