James McCool
commited on
Commit
·
8c72f5c
1
Parent(s):
f978f29
Refactor calculate_weighted_ownership function in predict_dupes.py: remove debug print statements, adjust ownership value calculations to handle percentages, and ensure the return value is in percentage form, improving clarity and accuracy of ownership metrics.
Browse files- global_func/predict_dupes.py +6 -10
global_func/predict_dupes.py
CHANGED
@@ -11,35 +11,31 @@ def calculate_weighted_ownership(row_ownerships):
|
|
11 |
(AVERAGE of (each value's average with overall average)) * count - (max - min)
|
12 |
|
13 |
Args:
|
14 |
-
row_ownerships: Series containing ownership values for
|
15 |
|
16 |
Returns:
|
17 |
float: Calculated weighted ownership value
|
18 |
"""
|
19 |
-
|
20 |
-
|
21 |
|
22 |
# Get the mean of all ownership values
|
23 |
row_mean = row_ownerships.mean()
|
24 |
-
print("Row mean:", row_mean) # Debug print
|
25 |
|
26 |
# Calculate average of each value with the overall mean
|
27 |
value_means = [(val + row_mean) / 2 for val in row_ownerships]
|
28 |
-
print("Value means:", value_means) # Debug print
|
29 |
|
30 |
# Take average of all those means
|
31 |
-
avg_of_means = sum(value_means) / len(
|
32 |
-
print("Average of means:", avg_of_means) # Debug print
|
33 |
|
34 |
# Multiply by count of values
|
35 |
weighted = avg_of_means * len(row_ownerships)
|
36 |
-
print("After multiplication:", weighted) # Debug print
|
37 |
|
38 |
# Subtract (max - min)
|
39 |
weighted = weighted - (row_ownerships.max() - row_ownerships.min())
|
40 |
-
print("Final weighted:", weighted) # Debug print
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var, sport_var):
|
45 |
if strength_var == 'Weak':
|
|
|
11 |
(AVERAGE of (each value's average with overall average)) * count - (max - min)
|
12 |
|
13 |
Args:
|
14 |
+
row_ownerships: Series containing ownership values in percentage form (e.g., 24.2213 for 24.2213%)
|
15 |
|
16 |
Returns:
|
17 |
float: Calculated weighted ownership value
|
18 |
"""
|
19 |
+
# Drop NaN values and convert percentages to decimals
|
20 |
+
row_ownerships = row_ownerships.dropna() / 100
|
21 |
|
22 |
# Get the mean of all ownership values
|
23 |
row_mean = row_ownerships.mean()
|
|
|
24 |
|
25 |
# Calculate average of each value with the overall mean
|
26 |
value_means = [(val + row_mean) / 2 for val in row_ownerships]
|
|
|
27 |
|
28 |
# Take average of all those means
|
29 |
+
avg_of_means = sum(value_means) / len(row_ownerships)
|
|
|
30 |
|
31 |
# Multiply by count of values
|
32 |
weighted = avg_of_means * len(row_ownerships)
|
|
|
33 |
|
34 |
# Subtract (max - min)
|
35 |
weighted = weighted - (row_ownerships.max() - row_ownerships.min())
|
|
|
36 |
|
37 |
+
# Convert back to percentage form to match input format
|
38 |
+
return weighted * 100
|
39 |
|
40 |
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var, sport_var):
|
41 |
if strength_var == 'Weak':
|