Jimin Park
commited on
Commit
·
291e330
1
Parent(s):
1c99c03
added model
Browse files- util/app.py +17 -2
- util/app_training_df_getter.py +78 -0
util/app.py
CHANGED
@@ -62,10 +62,25 @@ except Exception as e:
|
|
62 |
|
63 |
def get_user_training_df(player_opgg_url):
|
64 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
training_df = create_app_user_training_df(player_opgg_url)
|
66 |
return training_df
|
67 |
except Exception as e:
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
def show_stats(player_opgg_url):
|
71 |
"""Display player statistics and recent matches"""
|
@@ -126,7 +141,7 @@ with gr.Blocks() as demo:
|
|
126 |
|
127 |
with gr.Row():
|
128 |
player_opgg_url = gr.Textbox(label="OPGG Player URL")
|
129 |
-
show_button = gr.Button("Show Stats")
|
130 |
|
131 |
with gr.Row():
|
132 |
stats_output = gr.HTML(label="Player Statistics")
|
|
|
62 |
|
63 |
def get_user_training_df(player_opgg_url):
|
64 |
try:
|
65 |
+
|
66 |
+
# Add input validation
|
67 |
+
if not player_opgg_url or not isinstance(player_opgg_url, str):
|
68 |
+
return "Invalid URL provided"
|
69 |
+
|
70 |
+
# Add debugging print
|
71 |
+
print(f"Processing URL: {player_opgg_url}")
|
72 |
+
|
73 |
training_df = create_app_user_training_df(player_opgg_url)
|
74 |
return training_df
|
75 |
except Exception as e:
|
76 |
+
|
77 |
+
# Add more detailed error information
|
78 |
+
import traceback
|
79 |
+
error_trace = traceback.format_exc()
|
80 |
+
print(f"Full error trace:\n{error_trace}")
|
81 |
+
return f"Error getting training data: {str(e)}"
|
82 |
+
|
83 |
+
#return f"Error getting training data: {e}"
|
84 |
|
85 |
def show_stats(player_opgg_url):
|
86 |
"""Display player statistics and recent matches"""
|
|
|
141 |
|
142 |
with gr.Row():
|
143 |
player_opgg_url = gr.Textbox(label="OPGG Player URL")
|
144 |
+
show_button = gr.Button("Show Player Stats")
|
145 |
|
146 |
with gr.Row():
|
147 |
stats_output = gr.HTML(label="Player Statistics")
|
util/app_training_df_getter.py
CHANGED
@@ -355,6 +355,7 @@ def create_champion_features_and_return_df(merged_player_stats=None, meta_stats=
|
|
355 |
print(f"\nError occurred: {str(e)}")
|
356 |
return None
|
357 |
|
|
|
358 |
def create_app_user_training_df(url):
|
359 |
|
360 |
# EXAMPLE OF INPUT: url = "https://www.op.gg/summoners/euw/Agurin-EUW?queue_type=SOLORANKED"
|
@@ -369,6 +370,7 @@ def create_app_user_training_df(url):
|
|
369 |
recent_stats = get_matches_stats(region, username)
|
370 |
# Replace " #" with "-" in the player_id column
|
371 |
recent_stats['player_id'] = recent_stats['player_id'].str.replace(" #", "-", regex=False)
|
|
|
372 |
|
373 |
player_stats = get_player_stats(region, username)
|
374 |
|
@@ -379,6 +381,82 @@ def create_app_user_training_df(url):
|
|
379 |
#save to feature_eng_stats.csv
|
380 |
training_features = create_champion_features_and_return_df(merged_player_stats=merged_stats, debug=None, consider_team_comp=True, test_mode=False)
|
381 |
return training_features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
# ========================================= end of my functions =====================================================
|
384 |
|
|
|
355 |
print(f"\nError occurred: {str(e)}")
|
356 |
return None
|
357 |
|
358 |
+
'''OG
|
359 |
def create_app_user_training_df(url):
|
360 |
|
361 |
# EXAMPLE OF INPUT: url = "https://www.op.gg/summoners/euw/Agurin-EUW?queue_type=SOLORANKED"
|
|
|
370 |
recent_stats = get_matches_stats(region, username)
|
371 |
# Replace " #" with "-" in the player_id column
|
372 |
recent_stats['player_id'] = recent_stats['player_id'].str.replace(" #", "-", regex=False)
|
373 |
+
print("recent_stats recieved, player_id parsed.\n")
|
374 |
|
375 |
player_stats = get_player_stats(region, username)
|
376 |
|
|
|
381 |
#save to feature_eng_stats.csv
|
382 |
training_features = create_champion_features_and_return_df(merged_player_stats=merged_stats, debug=None, consider_team_comp=True, test_mode=False)
|
383 |
return training_features
|
384 |
+
'''
|
385 |
+
|
386 |
+
def create_app_user_training_df(url):
|
387 |
+
try:
|
388 |
+
# Input validation
|
389 |
+
if not url or not isinstance(url, str):
|
390 |
+
raise ValueError("Invalid URL provided")
|
391 |
+
|
392 |
+
# Extract region and username
|
393 |
+
match = re.search(r"/summoners/(\w+)/([\w\-]+)\?", url)
|
394 |
+
if not match:
|
395 |
+
raise ValueError(f"Could not parse region and username from URL: {url}")
|
396 |
+
|
397 |
+
region = match.group(1)
|
398 |
+
username = match.group(2)
|
399 |
+
print(f"Extracted - Region: {region}, Username: {username}")
|
400 |
+
|
401 |
+
# Get recent stats
|
402 |
+
print("Fetching recent matches...")
|
403 |
+
recent_stats = get_matches_stats(region, username)
|
404 |
+
|
405 |
+
# Validate recent_stats
|
406 |
+
if recent_stats is None or recent_stats.empty:
|
407 |
+
raise ValueError("No recent matches found")
|
408 |
+
|
409 |
+
print("Recent matches columns:", recent_stats.columns.tolist())
|
410 |
+
|
411 |
+
# Check if player_id exists before trying to process it
|
412 |
+
if 'player_id' not in recent_stats.columns:
|
413 |
+
raise KeyError("player_id column not found in recent_stats")
|
414 |
+
|
415 |
+
# Process player_id
|
416 |
+
recent_stats['player_id'] = recent_stats['player_id'].str.replace(" #", "-", regex=False)
|
417 |
+
print("Processed player_ids:", recent_stats['player_id'].head())
|
418 |
+
|
419 |
+
# Get player stats
|
420 |
+
print("Fetching player stats...")
|
421 |
+
player_stats = get_player_stats(region, username)
|
422 |
+
|
423 |
+
# Validate player_stats
|
424 |
+
if player_stats is None or player_stats.empty:
|
425 |
+
raise ValueError("No player stats found")
|
426 |
+
|
427 |
+
print("Player stats columns:", player_stats.columns.tolist())
|
428 |
+
|
429 |
+
# Merge stats
|
430 |
+
print("Merging stats...")
|
431 |
+
merged_stats = merge_stats(recent_stats, player_stats)
|
432 |
+
|
433 |
+
# Validate merged stats
|
434 |
+
if merged_stats is None or merged_stats.empty:
|
435 |
+
raise ValueError("Failed to merge stats")
|
436 |
+
|
437 |
+
print("Merged stats columns:", merged_stats.columns.tolist())
|
438 |
+
|
439 |
+
# Create features
|
440 |
+
print("Creating champion features...")
|
441 |
+
training_features = create_champion_features_and_return_df(
|
442 |
+
merged_player_stats=merged_stats,
|
443 |
+
debug=None,
|
444 |
+
consider_team_comp=True,
|
445 |
+
test_mode=False
|
446 |
+
)
|
447 |
+
|
448 |
+
# Final validation
|
449 |
+
if training_features is None or training_features.empty:
|
450 |
+
raise ValueError("Failed to create training features")
|
451 |
+
|
452 |
+
print("Training features created successfully")
|
453 |
+
return training_features
|
454 |
+
|
455 |
+
except Exception as e:
|
456 |
+
import traceback
|
457 |
+
error_trace = traceback.format_exc()
|
458 |
+
print(f"Error in create_app_user_training_df:\n{error_trace}")
|
459 |
+
raise Exception(f"Failed to create training dataframe: {str(e)}")
|
460 |
|
461 |
# ========================================= end of my functions =====================================================
|
462 |
|