File size: 6,157 Bytes
ce673e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"""
Trophy/Badge Models for OpenTriage.
"""
from pydantic import BaseModel, Field
from typing import Optional, List, Dict, Any
from datetime import datetime, timezone
from enum import Enum
import uuid


class TrophyType(str, Enum):
    # Contribution milestones
    FIRST_PR = "first_pr"
    PR_MASTER = "pr_master"           # 10 PRs merged
    PR_LEGEND = "pr_legend"           # 50 PRs merged
    
    # Bug hunting
    BUG_HUNTER = "bug_hunter"         # Found 5 bugs
    BUG_SLAYER = "bug_slayer"         # Found 25 bugs
    
    # Mentorship
    FIRST_MENTOR = "first_mentor"     # First mentee helped
    MASTER_MENTOR = "master_mentor"   # Mentored 10 contributors
    
    # Streaks
    STREAK_STARTER = "streak_starter" # 7-day streak
    STREAK_WARRIOR = "streak_warrior" # 30-day streak
    STREAK_LEGEND = "streak_legend"   # 100-day streak
    
    # Triage
    TRIAGE_HELPER = "triage_helper"   # Triaged 10 issues
    TRIAGE_HERO = "triage_hero"       # Triaged 50 issues
    
    # Reviews
    FIRST_REVIEW = "first_review"     # First review given
    REVIEW_GURU = "review_guru"       # 25 reviews given
    
    # Community
    WELCOME_COMMITTEE = "welcome_committee"  # Welcomed 5 newcomers
    DOCUMENTATION_HERO = "documentation_hero"  # Improved docs
    
    # Special
    EARLY_ADOPTER = "early_adopter"   # Early platform user
    TOP_CONTRIBUTOR = "top_contributor"  # Monthly top contributor


TROPHY_METADATA: Dict[str, Dict[str, Any]] = {
    TrophyType.FIRST_PR: {
        "name": "First PR",
        "description": "Merged your first pull request!",
        "icon": "πŸŽ‰",
        "color": "#4CAF50",
        "rarity": "common"
    },
    TrophyType.PR_MASTER: {
        "name": "PR Master",
        "description": "Merged 10 pull requests",
        "icon": "⭐",
        "color": "#2196F3",
        "rarity": "uncommon"
    },
    TrophyType.PR_LEGEND: {
        "name": "PR Legend",
        "description": "Merged 50 pull requests",
        "icon": "πŸ†",
        "color": "#9C27B0",
        "rarity": "legendary"
    },
    TrophyType.BUG_HUNTER: {
        "name": "Bug Hunter",
        "description": "Found and reported 5 bugs",
        "icon": "πŸ›",
        "color": "#FF5722",
        "rarity": "common"
    },
    TrophyType.BUG_SLAYER: {
        "name": "Bug Slayer",
        "description": "Squashed 25 bugs",
        "icon": "βš”οΈ",
        "color": "#E91E63",
        "rarity": "rare"
    },
    TrophyType.FIRST_MENTOR: {
        "name": "First Mentor",
        "description": "Helped your first mentee",
        "icon": "🀝",
        "color": "#00BCD4",
        "rarity": "uncommon"
    },
    TrophyType.MASTER_MENTOR: {
        "name": "Master Mentor",
        "description": "Mentored 10 contributors",
        "icon": "πŸŽ“",
        "color": "#673AB7",
        "rarity": "rare"
    },
    TrophyType.STREAK_STARTER: {
        "name": "Streak Starter",
        "description": "7-day contribution streak",
        "icon": "πŸ”₯",
        "color": "#FF9800",
        "rarity": "common"
    },
    TrophyType.STREAK_WARRIOR: {
        "name": "Streak Warrior",
        "description": "30-day contribution streak",
        "icon": "πŸ’ͺ",
        "color": "#F44336",
        "rarity": "rare"
    },
    TrophyType.STREAK_LEGEND: {
        "name": "Streak Legend",
        "description": "100-day contribution streak",
        "icon": "🌟",
        "color": "#FFD700",
        "rarity": "legendary"
    },
    TrophyType.TRIAGE_HELPER: {
        "name": "Triage Helper",
        "description": "Triaged 10 issues",
        "icon": "πŸ“‹",
        "color": "#607D8B",
        "rarity": "common"
    },
    TrophyType.TRIAGE_HERO: {
        "name": "Triage Hero",
        "description": "Triaged 50 issues",
        "icon": "🦸",
        "color": "#3F51B5",
        "rarity": "rare"
    },
    TrophyType.FIRST_REVIEW: {
        "name": "First Review",
        "description": "Gave your first code review",
        "icon": "πŸ‘€",
        "color": "#8BC34A",
        "rarity": "common"
    },
    TrophyType.REVIEW_GURU: {
        "name": "Review Guru",
        "description": "Provided 25 code reviews",
        "icon": "πŸ§™",
        "color": "#795548",
        "rarity": "rare"
    },
    TrophyType.WELCOME_COMMITTEE: {
        "name": "Welcome Committee",
        "description": "Welcomed 5 newcomers to the project",
        "icon": "πŸ‘‹",
        "color": "#FFEB3B",
        "rarity": "uncommon"
    },
    TrophyType.DOCUMENTATION_HERO: {
        "name": "Documentation Hero",
        "description": "Improved project documentation",
        "icon": "πŸ“š",
        "color": "#009688",
        "rarity": "uncommon"
    },
    TrophyType.EARLY_ADOPTER: {
        "name": "Early Adopter",
        "description": "One of the first OpenTriage users",
        "icon": "πŸš€",
        "color": "#00BCD4",
        "rarity": "rare"
    },
    TrophyType.TOP_CONTRIBUTOR: {
        "name": "Top Contributor",
        "description": "Monthly top contributor",
        "icon": "πŸ‘‘",
        "color": "#FFD700",
        "rarity": "legendary"
    }
}


class Trophy(BaseModel):
    """A trophy/badge earned by a user."""
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    user_id: str
    username: str
    trophy_type: TrophyType
    
    # Display info
    name: str
    description: str
    icon: str
    color: str
    rarity: str  # common, uncommon, rare, legendary
    
    # SVG data for sharing
    svg_data: Optional[str] = None
    
    # Sharing
    is_public: bool = True
    share_url: Optional[str] = None
    
    # Context
    earned_for: Optional[str] = None  # e.g., "owner/repo"
    milestone_value: Optional[int] = None  # e.g., 10 for "10 PRs"
    
    awarded_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))


class UserTrophyStats(BaseModel):
    """Summary of a user's trophy collection."""
    user_id: str
    username: str
    total_trophies: int = 0
    common_count: int = 0
    uncommon_count: int = 0
    rare_count: int = 0
    legendary_count: int = 0
    recent_trophy: Optional[Trophy] = None
    trophy_ids: List[str] = []