BasitAliii commited on
Commit
91eaf66
·
verified ·
1 Parent(s): 46e0d30

Update matching.py

Browse files
Files changed (1) hide show
  1. matching.py +12 -5
matching.py CHANGED
@@ -1,22 +1,29 @@
1
  from typing import List, Dict
2
  from models import Profile
3
 
 
4
  def calculate_local_matches(
5
  current: Profile,
6
  candidates: List[Profile],
7
  top_k: int = 3,
8
  ) -> List[Dict]:
 
 
 
 
9
  matches = []
10
 
11
  for c in candidates:
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,
@@ -24,9 +31,9 @@ def calculate_local_matches(
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]
 
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],
8
  top_k: int = 3,
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
  "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]