Spaces:
Sleeping
Sleeping
Commit
·
5c5f11f
1
Parent(s):
743b8c4
Debugging
Browse files
app.py
CHANGED
@@ -56,10 +56,14 @@ def process_player_data(player_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
56 |
# Read the example row from prediction_data_prepped.csv to get the expected structure
|
57 |
try:
|
58 |
pred_data = pd.read_csv("prediction_data_prepped.csv")
|
|
|
|
|
|
|
|
|
59 |
if not pred_data.empty:
|
60 |
# Get column structure from the first row
|
61 |
for col in pred_data.columns:
|
62 |
-
if col not in player_data:
|
63 |
player_data[col] = 0
|
64 |
except Exception as e:
|
65 |
print(f"Warning - Error reading prediction data template: {str(e)}")
|
@@ -86,30 +90,32 @@ def process_player_data(player_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
86 |
# Convert to DataFrame for consistency with training
|
87 |
df = pd.DataFrame([player_data])
|
88 |
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
# Get all columns from reference data
|
94 |
-
for col in ref_data.columns:
|
95 |
-
if col not in df.columns:
|
96 |
-
df[col] = 0
|
97 |
-
# Reorder columns to match reference data
|
98 |
-
df = df[ref_data.columns]
|
99 |
-
except Exception as e:
|
100 |
-
print(f"Warning - Error matching reference data structure: {str(e)}")
|
101 |
-
|
102 |
-
# Final check for required columns
|
103 |
-
if FEATURE_COLUMNS:
|
104 |
-
for col in FEATURE_COLUMNS:
|
105 |
-
if col not in df.columns:
|
106 |
-
df[col] = 0
|
107 |
-
# Reorder columns to match model input
|
108 |
-
df = df[FEATURE_COLUMNS]
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
|
|
113 |
return df
|
114 |
except Exception as e:
|
115 |
return f"Error processing player data: {str(e)}"
|
|
|
56 |
# Read the example row from prediction_data_prepped.csv to get the expected structure
|
57 |
try:
|
58 |
pred_data = pd.read_csv("prediction_data_prepped.csv")
|
59 |
+
print("\nReference columns from prediction_data_prepped.csv:")
|
60 |
+
print(sorted(pred_data.columns.tolist()))
|
61 |
+
print(f"Number of reference columns: {len(pred_data.columns)}")
|
62 |
+
|
63 |
if not pred_data.empty:
|
64 |
# Get column structure from the first row
|
65 |
for col in pred_data.columns:
|
66 |
+
if col not in player_data and col != 'Predicted_Cost': # Skip the target variable
|
67 |
player_data[col] = 0
|
68 |
except Exception as e:
|
69 |
print(f"Warning - Error reading prediction data template: {str(e)}")
|
|
|
90 |
# Convert to DataFrame for consistency with training
|
91 |
df = pd.DataFrame([player_data])
|
92 |
|
93 |
+
# Print out the columns we have in our processed data
|
94 |
+
print("\nProcessed data columns:")
|
95 |
+
print(sorted(df.columns.tolist()))
|
96 |
+
print(f"Number of processed columns: {len(df.columns)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
# Find missing columns
|
99 |
+
expected_cols = set(pred_data.columns) - {'Predicted_Cost'} # Remove target variable
|
100 |
+
actual_cols = set(df.columns)
|
101 |
+
|
102 |
+
missing_cols = expected_cols - actual_cols
|
103 |
+
extra_cols = actual_cols - expected_cols
|
104 |
+
|
105 |
+
if missing_cols:
|
106 |
+
print("\nMissing columns:")
|
107 |
+
print(sorted(list(missing_cols)))
|
108 |
+
|
109 |
+
if extra_cols:
|
110 |
+
print("\nExtra columns:")
|
111 |
+
print(sorted(list(extra_cols)))
|
112 |
+
|
113 |
+
# Ensure we have all needed columns and remove any extras
|
114 |
+
for col in missing_cols:
|
115 |
+
df[col] = 0
|
116 |
+
df = df[list(expected_cols)]
|
117 |
|
118 |
+
print(f"\nFinal number of columns: {len(df.columns)}")
|
119 |
return df
|
120 |
except Exception as e:
|
121 |
return f"Error processing player data: {str(e)}"
|