forked from defilytica/aura_gauge_vote_scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.py
32 lines (25 loc) · 1.17 KB
/
processor.py
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
# processor.py
import pandas as pd
from decimal import Decimal, getcontext
# Set precision high enough to avoid rounding issues
getcontext().prec = 28
def process_votes(votes, choices, target_choices):
choice_indices = {choice: index + 1 for index, choice in enumerate(choices)}
target_indices = {index: choice for choice, index in choice_indices.items() if choice in target_choices}
filtered_votes = []
for vote in votes:
choice_weights = vote['choice']
total_votes = sum(choice_weights.values())
total_vp = Decimal(vote['vp'])
for choice_index, weight in choice_weights.items():
if int(choice_index) in target_indices:
relative_weight = Decimal(weight) / Decimal(total_votes)
voting_power = relative_weight * total_vp
filtered_votes.append({
'address': vote['voter'],
'choice': target_indices[int(choice_index)],
'total_voting_power': float(total_vp),
'vote_weight': float(relative_weight),
'total_votes': float(voting_power)
})
return pd.DataFrame(filtered_votes)