Skip to content

Instantly share code, notes, and snippets.

@jhodges10
Created August 8, 2018 00:02
Show Gist options
  • Save jhodges10/0b5b086bd95179af62bc240efa7e4342 to your computer and use it in GitHub Desktop.
Save jhodges10/0b5b086bd95179af62bc240efa7e4342 to your computer and use it in GitHub Desktop.
Checks for swapped votes using the Dash Intel vote Database
from bin.db_functions import IntelDatabase
from bin.DashInfo import DataPreparation
test_prop_hash = '7877338b947d7fe25d4dcc80979ee1f918736596677188ebadc79e5b9009d847'
def check_for_changed_votes():
node_dict = {}
votes_dict = IntelDatabase.get_votes_for_hash(test_prop_hash)
DataPreparation.write_json(votes_dict, 'votes_data')
print("Saved votes.")
for node in votes_dict:
cur_votes = []
if node[1] not in node_dict:
node_dict[node[1]] = node[0]
else:
votes_list = node_dict[node[1]]
# Re-append current votes to list without making a list of lists
if len(votes_list) >= 2 and votes_list == list:
for vote in node_dict[node[1]]:
cur_votes.append(vote)
else:
cur_votes = votes_list
# Append new vote
cur_votes.append(node[0])
# Reset votes for that node
node_dict[node[1]] = cur_votes
vote_switches = 0
yes_to_no = 0
no_to_yes = 0
abstain_to_yes = 0
abstain_to_no = 0
yes_to_abstain = 0
no_to_abstain = 0
yes_to_yes = 0
no_to_no = 0
for node, votes in node_dict.items():
if type(votes) == list and len(votes) >= 2:
vote_switches += 1
if votes[0] == 'YES' and votes[-1] == 'NO':
yes_to_no += 1
elif votes[0] == 'YES' and votes[-1] == 'YES':
yes_to_yes += 1
elif votes[0] == 'NO' and votes[-1] == 'YES':
no_to_yes += 1
elif votes[0] == 'NO' and votes[-1] == 'NO':
no_to_no += 1
elif votes[0] == 'ABSTAIN' and votes[-1] == 'YES':
abstain_to_yes += 1
elif votes[0] == 'ABSTAIN' and votes[-1] == 'NO':
abstain_to_no += 1
elif votes[0] == 'NO' and votes[-1] == 'ABSTAIN':
no_to_abstain += 1
elif votes[0] == 'YES' and votes[-1] == 'ABSTAIN':
yes_to_abstain += 1
else:
pass
print("Total votes evaluated: {}".format(len(list(votes_dict))))
print("Total of {} vote switches found.".format(vote_switches))
print("Yes to No: {}".format(yes_to_no))
print("Yes to Yes: {}".format(yes_to_yes))
print("No to Yes: {}".format(no_to_yes))
print("No to No: {}".format(no_to_no))
print("No to Abstain: {}".format(no_to_abstain))
print("Yes to Abstain: {}".format(yes_to_abstain))
print("Abstain to No: {}".format(abstain_to_no))
print("Abstain to Yes: {}".format(abstain_to_yes))
return True
check_for_changed_votes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment