-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_compatibility_engine.py
More file actions
269 lines (230 loc) · 11.1 KB
/
Copy pathuniversal_compatibility_engine.py
File metadata and controls
269 lines (230 loc) · 11.1 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
#!/usr/bin/env python3
"""
Universal Compatibility Engine
Designed to work fairly across all system configurations
"""
import sqlite3
from typing import Dict, List, Any, Tuple
class UniversalCompatibilityEngine:
"""
Universal compatibility engine that provides fair assessments across all hardware tiers
"""
def __init__(self, db_path: str):
self.db_path = db_path
self.compatibility_thresholds = {
'ultra_high': 0.9, # 90% compatibility for ultra-high systems
'high': 0.75, # 75% compatibility for high-end systems
'medium': 0.6, # 60% compatibility for medium systems
'low': 0.5, # 50% compatibility for low-end systems
'minimum': 0.4 # 40% compatibility for minimum systems
}
def get_compatible_games_universal(self, system_specs: Dict[str, Any]) -> List[Dict[str, Any]]:
"""Get games compatible with any system using adaptive thresholds"""
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
# Get performance tier
performance_tier = system_specs.get('performance_tier', 'minimum')
compatibility_threshold = self.compatibility_thresholds.get(performance_tier, 0.4)
cursor.execute('''
SELECT name, min_requirements, recommended_requirements,
min_cpu_score, min_gpu_score, min_ram, min_storage, source,
steam_url, gog_url, epic_url, youtube_trailer
FROM games
ORDER BY name
''')
rows = cursor.fetchall()
conn.close()
compatible_games = []
for row in rows:
game = {
'name': row[0],
'min_requirements': row[1],
'recommended_requirements': row[2],
'min_cpu_score': row[3] or 0,
'min_gpu_score': row[4] or 0,
'min_ram': row[5] or 0,
'min_storage': row[6] or 0,
'source': row[7],
'steam_url': row[8],
'gog_url': row[9],
'epic_url': row[10],
'youtube_trailer': row[11]
}
# Calculate compatibility using universal algorithm
compatibility_score = self.calculate_universal_compatibility(game, system_specs)
if compatibility_score >= compatibility_threshold:
game['compatibility_score'] = compatibility_score
compatible_games.append(game)
# Sort by compatibility score (best matches first)
compatible_games.sort(key=lambda x: x['compatibility_score'], reverse=True)
return compatible_games
except Exception as e:
print(f"Error getting compatible games: {e}")
return []
def calculate_universal_compatibility(self, game: Dict[str, Any], system_specs: Dict[str, Any]) -> float:
"""Calculate compatibility score using universal algorithm (0.0 to 1.0)"""
try:
# Get system specs
system_cpu = system_specs.get('cpu_score', 0)
system_gpu = system_specs.get('gpu_score', 0)
system_ram = system_specs.get('ram', 0)
system_storage = system_specs.get('storage', 0)
# Get game requirements
game_cpu = game.get('min_cpu_score', 0)
game_gpu = game.get('min_gpu_score', 0)
game_ram = game.get('min_ram', 0)
game_storage = game.get('min_storage', 0)
# Calculate individual component scores
cpu_score = self.calculate_component_score(system_cpu, game_cpu)
gpu_score = self.calculate_component_score(system_gpu, game_gpu)
ram_score = self.calculate_component_score(system_ram, game_ram)
storage_score = self.calculate_component_score(system_storage, game_storage)
# Weighted average (GPU and CPU are most important)
weights = {
'cpu': 0.3,
'gpu': 0.4,
'ram': 0.2,
'storage': 0.1
}
total_score = (
cpu_score * weights['cpu'] +
gpu_score * weights['gpu'] +
ram_score * weights['ram'] +
storage_score * weights['storage']
)
return min(total_score, 1.0) # Cap at 1.0
except Exception as e:
print(f"Error calculating compatibility: {e}")
return 0.0
def calculate_component_score(self, system_value: float, required_value: float) -> float:
"""Calculate compatibility score for individual component (0.0 to 1.0+)"""
if required_value <= 0:
return 1.0 # No requirement means automatic pass
if system_value <= 0:
return 0.0 # No system capability means fail
ratio = system_value / required_value
if ratio >= 2.0:
return 1.0 # System exceeds requirements by 2x or more
elif ratio >= 1.5:
return 0.95 # System exceeds requirements by 50%+
elif ratio >= 1.2:
return 0.9 # System exceeds requirements by 20%+
elif ratio >= 1.0:
return 0.8 # System meets requirements exactly
elif ratio >= 0.9:
return 0.7 # System is slightly below requirements
elif ratio >= 0.8:
return 0.6 # System is notably below requirements
elif ratio >= 0.7:
return 0.5 # System is significantly below requirements
elif ratio >= 0.5:
return 0.3 # System is well below requirements
else:
return 0.1 # System is far below requirements
def get_compatibility_explanation(self, game: Dict[str, Any], system_specs: Dict[str, Any]) -> str:
"""Get human-readable explanation of compatibility"""
score = self.calculate_universal_compatibility(game, system_specs)
performance_tier = system_specs.get('performance_tier', 'minimum')
if score >= 0.9:
return "Excellent - Should run smoothly at high settings"
elif score >= 0.8:
return "Very Good - Should run well at medium-high settings"
elif score >= 0.7:
return "Good - Should run well at medium settings"
elif score >= 0.6:
return "Fair - Should run at medium-low settings"
elif score >= 0.5:
return "Playable - May need low settings"
elif score >= 0.4:
return "Limited - Low settings, possible stuttering"
else:
return "Not Recommended - Likely to have performance issues"
def get_performance_recommendations(self, system_specs: Dict[str, Any]) -> Dict[str, Any]:
"""Get performance and game recommendations based on system"""
performance_tier = system_specs.get('performance_tier', 'minimum')
cpu_score = system_specs.get('cpu_score', 0)
gpu_score = system_specs.get('gpu_score', 0)
ram_gb = system_specs.get('ram', 0)
recommendations = {
'tier': performance_tier,
'suitable_genres': [],
'recommended_settings': {},
'upgrade_suggestions': []
}
if performance_tier in ['ultra_high', 'high']:
recommendations['suitable_genres'] = [
'All AAA games', 'VR games', 'Simulation games', 'Open world games'
]
recommendations['recommended_settings'] = {
'resolution': '1440p-4K',
'quality': 'High-Ultra',
'raytracing': 'Possible',
'fps_target': '60+'
}
elif performance_tier == 'medium':
recommendations['suitable_genres'] = [
'Most modern games', 'Competitive games', 'RPGs', 'Strategy games'
]
recommendations['recommended_settings'] = {
'resolution': '1080p',
'quality': 'Medium-High',
'raytracing': 'Limited',
'fps_target': '60'
}
elif performance_tier == 'low':
recommendations['suitable_genres'] = [
'Indie games', 'Esports titles', 'Older AAA games', 'Strategy games'
]
recommendations['recommended_settings'] = {
'resolution': '1080p',
'quality': 'Medium-Low',
'raytracing': 'Off',
'fps_target': '30-60'
}
else: # minimum
recommendations['suitable_genres'] = [
'2D games', 'Pixel art games', 'Retro games', 'Browser games'
]
recommendations['recommended_settings'] = {
'resolution': '720p-1080p',
'quality': 'Low',
'raytracing': 'Off',
'fps_target': '30+'
}
# Upgrade suggestions
if cpu_score < 50:
recommendations['upgrade_suggestions'].append('CPU upgrade would improve performance')
if gpu_score < 40:
recommendations['upgrade_suggestions'].append('GPU upgrade would significantly improve gaming')
if ram_gb < 8:
recommendations['upgrade_suggestions'].append('More RAM (8GB+) recommended for modern games')
return recommendations
# Test the universal system
def test_universal_compatibility():
"""Test the universal compatibility system"""
from universal_system_analyzer import UniversalSystemAnalyzer
analyzer = UniversalSystemAnalyzer()
engine = UniversalCompatibilityEngine("games.db")
# Get system specs
system_specs = analyzer.get_system_specs()
print("=== UNIVERSAL COMPATIBILITY TEST ===")
print(f"System Performance Tier: {system_specs.get('performance_tier', 'unknown')}")
print(f"CPU Score: {system_specs.get('cpu_score', 0)}")
print(f"GPU Score: {system_specs.get('gpu_score', 0)}")
print(f"RAM: {system_specs.get('ram', 0)} GB")
# Get compatible games
compatible_games = engine.get_compatible_games_universal(system_specs)
print(f"\nFound {len(compatible_games)} compatible games:")
for i, game in enumerate(compatible_games[:10], 1): # Show top 10
explanation = engine.get_compatibility_explanation(game, system_specs)
print(f"{i}. {game['name']} - {explanation}")
# Get recommendations
recommendations = engine.get_performance_recommendations(system_specs)
print(f"\nRecommendations for {recommendations['tier']} tier system:")
print(f"Suitable genres: {', '.join(recommendations['suitable_genres'])}")
print(f"Recommended settings: {recommendations['recommended_settings']}")
if recommendations['upgrade_suggestions']:
print(f"Upgrade suggestions: {', '.join(recommendations['upgrade_suggestions'])}")
if __name__ == "__main__":
test_universal_compatibility()