-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scoring_algorithm.py
More file actions
289 lines (230 loc) · 8.75 KB
/
Copy pathtest_scoring_algorithm.py
File metadata and controls
289 lines (230 loc) · 8.75 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
"""
Test script for V1 scoring algorithm functions.
This validates the core scoring logic before notebook execution.
"""
from src.contracts.common import Position
from src.contracts.timeline import (
ChampionStats,
DamageStats,
Frame,
MatchTimeline,
ParticipantFrame,
)
def create_mock_timeline() -> MatchTimeline:
"""Create a minimal mock timeline for testing."""
# Create mock participant frame
champion_stats = ChampionStats(
health=580, health_max=580, attack_damage=60, armor=35, magic_resist=32
)
damage_stats = DamageStats(total_damage_done_to_champions=15000, total_damage_taken=8000)
participant_frame = ParticipantFrame(
participant_id=1,
champion_stats=champion_stats,
damage_stats=damage_stats,
current_gold=12000,
total_gold=15000,
level=15,
minions_killed=180,
jungle_minions_killed=20,
position=Position(x=1000, y=1000),
xp=15000,
)
# Create frame with events
frame = Frame(
timestamp=1800000, # 30 minutes
participant_frames={"1": participant_frame},
events=[
# Kill event
{
"type": "CHAMPION_KILL",
"timestamp": 600000,
"killerId": 1,
"victimId": 6,
"assistingParticipantIds": [2, 3],
},
# Dragon kill
{
"type": "ELITE_MONSTER_KILL",
"timestamp": 900000,
"killerId": 1,
"monsterType": "DRAGON",
},
# Ward placed
{
"type": "WARD_PLACED",
"timestamp": 300000,
"creatorId": 1,
"wardType": "YELLOW_TRINKET",
},
# Item purchased
{
"type": "ITEM_PURCHASED",
"timestamp": 1200000,
"participantId": 1,
"itemId": 3031, # Infinity Edge
},
],
)
# Create timeline
timeline = MatchTimeline(
metadata={
"data_version": "2",
"match_id": "TEST_MATCH_001",
"participants": ["test-puuid-1", "test-puuid-2"],
},
info={
"frame_interval": 60000,
"frames": [frame],
"game_id": 123456,
"participants": [
{"participant_id": 1, "puuid": "test-puuid-1"},
{"participant_id": 2, "puuid": "test-puuid-2"},
],
},
)
return timeline
def test_combat_efficiency():
"""Test combat efficiency calculation."""
timeline = create_mock_timeline()
# Extract combat metrics
kills = 0
deaths = 0
assists = 0
for frame in timeline.info.frames:
for event in frame.events:
if event.get("type") == "CHAMPION_KILL":
if event.get("killerId") == 1:
kills += 1
if event.get("victimId") == 1:
deaths += 1
if 1 in event.get("assistingParticipantIds", []):
assists += 1
kda = (kills + assists) / max(deaths, 1)
kda_score = min(kda / 10, 1.0)
print("🎯 Combat Efficiency Test:")
print(f" Kills: {kills}, Deaths: {deaths}, Assists: {assists}")
print(f" KDA: {kda:.2f}")
print(f" KDA Score (normalized): {kda_score:.3f}")
# Get damage stats
last_frame = timeline.info.frames[-1]
participant_frame = last_frame.participant_frames.get("1")
if participant_frame:
damage = participant_frame.damage_stats.total_damage_done_to_champions
gold = participant_frame.total_gold
damage_efficiency = damage / max(gold / 1000, 1)
print(f" Damage to Champions: {damage}")
print(f" Total Gold: {gold}")
print(f" Damage Efficiency: {damage_efficiency:.2f} damage per 1k gold")
assert kills > 0, "Should have at least one kill"
assert kda > 0, "KDA should be positive"
print(" ✅ Combat efficiency calculation works!")
return True
def test_economic_management():
"""Test economic management calculation."""
timeline = create_mock_timeline()
last_frame = timeline.info.frames[-1]
participant_frame = last_frame.participant_frames.get("1")
print("\n💰 Economic Management Test:")
if participant_frame:
game_duration_min = last_frame.timestamp / 60000
total_cs = participant_frame.minions_killed + participant_frame.jungle_minions_killed
cs_per_min = total_cs / game_duration_min
print(f" Game Duration: {game_duration_min:.1f} min")
print(f" Total CS: {total_cs}")
print(f" CS/min: {cs_per_min:.2f}")
print(f" Total Gold: {participant_frame.total_gold}")
# Normalize CS efficiency
cs_efficiency = min(cs_per_min / 10, 1.0)
print(f" CS Efficiency (normalized): {cs_efficiency:.3f}")
assert cs_per_min > 0, "CS/min should be positive"
print(" ✅ Economic management calculation works!")
return True
return False
def test_objective_control():
"""Test objective control calculation."""
timeline = create_mock_timeline()
epic_monsters = 0
total_epic_monsters = 0
print("\n🐉 Objective Control Test:")
for frame in timeline.info.frames:
for event in frame.events:
if event.get("type") == "ELITE_MONSTER_KILL":
total_epic_monsters += 1
if event.get("killerId") == 1:
epic_monsters += 1
participation = epic_monsters / max(total_epic_monsters, 1)
print(f" Epic Monsters Secured: {epic_monsters}")
print(f" Total Epic Monsters: {total_epic_monsters}")
print(f" Participation Rate: {participation:.1%}")
assert epic_monsters > 0, "Should have secured at least one epic monster"
print(" ✅ Objective control calculation works!")
return True
def test_vision_control():
"""Test vision control calculation."""
timeline = create_mock_timeline()
wards_placed = 0
print("\n👁️ Vision Control Test:")
for frame in timeline.info.frames:
for event in frame.events:
if event.get("type") == "WARD_PLACED" and event.get("creatorId") == 1:
wards_placed += 1
game_duration_min = timeline.info.frames[-1].timestamp / 60000
wards_per_min = wards_placed / game_duration_min
print(f" Wards Placed: {wards_placed}")
print(f" Wards per Min: {wards_per_min:.2f}")
ward_placement_rate = min(wards_per_min / 2, 1.0)
print(f" Ward Placement Rate (normalized): {ward_placement_rate:.3f}")
assert wards_placed > 0, "Should have placed at least one ward"
print(" ✅ Vision control calculation works!")
return True
def test_timeline_helper_methods():
"""Test MatchTimeline helper methods."""
timeline = create_mock_timeline()
print("\n🔧 Timeline Helper Methods Test:")
# Test get_participant_by_puuid
participant_id = timeline.get_participant_by_puuid("test-puuid-1")
print(f" get_participant_by_puuid: {participant_id}")
assert participant_id == 1, "Should find participant 1"
# Test get_events_by_type
kill_events = timeline.get_events_by_type("CHAMPION_KILL")
print(f" get_events_by_type('CHAMPION_KILL'): {len(kill_events)} events")
assert len(kill_events) > 0, "Should find kill events"
# Test get_participant_frame_at_time
frame = timeline.get_participant_frame_at_time(1, 1800000)
print(f" get_participant_frame_at_time: {frame is not None}")
assert frame is not None, "Should find participant frame"
# Test get_kill_participation
kp = timeline.get_kill_participation(1)
print(f" get_kill_participation: {kp:.1f}%")
assert kp >= 0, "Kill participation should be non-negative"
print(" ✅ All helper methods work!")
return True
def main():
"""Run all tests."""
print("=" * 60)
print("V1 Scoring Algorithm Core Function Tests")
print("=" * 60)
try:
test_combat_efficiency()
test_economic_management()
test_objective_control()
test_vision_control()
test_timeline_helper_methods()
print("\n" + "=" * 60)
print("🎉 ALL TESTS PASSED!")
print("=" * 60)
print("\n✅ Core scoring algorithm functions validated")
print("✅ Ready for notebook execution with real data")
print("✅ P2 Phase deliverables confirmed working")
except AssertionError as e:
print(f"\n❌ TEST FAILED: {e}")
return False
except Exception as e:
print(f"\n❌ UNEXPECTED ERROR: {e}")
import traceback
traceback.print_exc()
return False
return True
if __name__ == "__main__":
success = main()
exit(0 if success else 1)