File size: 1,123 Bytes
883d057
 
 
91eaf66
883d057
 
 
 
 
91eaf66
 
db3ea53
91eaf66
db3ea53
 
883d057
 
 
 
 
db3ea53
 
 
 
 
 
 
91eaf66
db3ea53
 
883d057
 
 
 
46e0d30
 
883d057
db3ea53
91eaf66
883d057
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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]