Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Nov 23, 2024
1 parent c971ba5 commit 83a8be5
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,24 @@ def calculate_deviation(scores, normalization_factors=None):
if not scores or len(scores) < 2:
print("Not enough scores to calculate deviation")
return 0

if normalization_factors:
scores = [score / factor for score,
factor in zip(scores, normalization_factors)]

# Calculate relative changes
relative_changes = [(scores[i] - scores[i - 1]) / scores[i - 1]
for i in range(1, len(scores))]
scores = [score / factor for score, factor in zip(scores, normalization_factors)]

# Calculate relative changes, skipping pairs where the previous score is 0
relative_changes = []
for i in range(1, len(scores)):
if scores[i-1] != 0: # Only calculate if previous score is non-zero
relative_change = (scores[i] - scores[i-1]) / scores[i-1]
relative_changes.append(relative_change)

# If no valid relative changes could be calculated, return 0
if not relative_changes:
return 0

avg_change = sum(relative_changes) / len(relative_changes)
deviation_percent = (sum((change - avg_change) ** 2 for change in relative_changes)
** 0.5 / len(relative_changes) ** 0.5) * 100
** 0.5 / len(relative_changes) ** 0.5) * 100
return deviation_percent


Expand Down

0 comments on commit 83a8be5

Please sign in to comment.