BasitAliii commited on
Commit
db3ea53
·
verified ·
1 Parent(s): 2063026

Update matching.py

Browse files
Files changed (1) hide show
  1. matching.py +13 -10
matching.py CHANGED
@@ -9,21 +9,25 @@ def calculate_local_matches(
9
  ) -> List[Dict]:
10
  """
11
  Calculate local matches based on skill overlap.
12
- Returns a list of dicts containing full profile info + score (0-1).
13
  """
14
- matches = []
 
15
 
16
  for c in candidates:
17
  if c.id == current.id:
18
  continue
19
 
20
- # Skill overlap score
21
- score = 0
22
- score += len(set(c.offers) & set(current.wants)) * 30
23
- score += len(set(current.offers) & set(c.wants)) * 30
 
 
 
24
 
25
- # Normalize score to 0-1
26
- score = min(1.0, score / 100)
27
 
28
  matches.append({
29
  "id": c.id,
@@ -31,9 +35,8 @@ def calculate_local_matches(
31
  "offers": c.offers,
32
  "wants": c.wants,
33
  "avatar": c.avatar,
34
- "score": score,
35
  "reason": "Local scoring"
36
  })
37
 
38
- # Sort descending by score and return top_k
39
  return sorted(matches, key=lambda x: x["score"], reverse=True)[:top_k]
 
9
  ) -> List[Dict]:
10
  """
11
  Calculate local matches based on skill overlap.
12
+ Returns scores normalized between 0.0 and 1.0
13
  """
14
+
15
+ matches: List[Dict] = []
16
 
17
  for c in candidates:
18
  if c.id == current.id:
19
  continue
20
 
21
+ score_points = 0
22
+
23
+ # Candidate offers what current wants
24
+ score_points += len(set(c.offers) & set(current.wants)) * 30
25
+
26
+ # Current offers what candidate wants
27
+ score_points += len(set(current.offers) & set(c.wants)) * 30
28
 
29
+ # Normalize max 100 points → 0.0–1.0
30
+ score = min(score_points / 100.0, 1.0)
31
 
32
  matches.append({
33
  "id": c.id,
 
35
  "offers": c.offers,
36
  "wants": c.wants,
37
  "avatar": c.avatar,
38
+ "score": round(score, 3), # ALWAYS 0–1
39
  "reason": "Local scoring"
40
  })
41
 
 
42
  return sorted(matches, key=lambda x: x["score"], reverse=True)[:top_k]