Skip to content

Instantly share code, notes, and snippets.

@random-person-001
Created February 12, 2017 23:49
Show Gist options
  • Save random-person-001/ad94b712100ed707b4f03f5690169947 to your computer and use it in GitHub Desktop.
Save random-person-001/ad94b712100ed707b4f03f5690169947 to your computer and use it in GitHub Desktop.
Plot money movements for the game POWER. Just paste the part of the webpage where you can see other's donations to you, for each person you wish to graph. Uses the other file 'chordplot1.py' plot the data prettily.
#
# Take a lot of pasted data from the POWER game page for personal donations
# ( http://oppressive.games/power/pnews.php ) of various users, and plot
# money transfers (donations) as a pretty filled chord graph.
#
# Running This:
# You should also have the file 'chordplot1.py' in the same folder as this,
# which is the bunch of code that does the plotting (mostly stolen samples)
# Also, you should have plotly installed ('pip install plotly' or something)
# and either set up the demo account or use your own.
#
# By Riley, Feb 2017
# Python 2.7, but should easily be converted to 3
#
import chordplot1
import numpy as np
numPeople = 3
matrix = np.zeros((numPeople, numPeople), dtype=int)
labels = []
labels.append(raw_input("Type who is first: "))
for receiverIndex in range(numPeople):
receiver = labels[receiverIndex]
# Get input from the user
print("For politican " + receiver)
print("Paste data from page, and enter 'end' when you're done:")
s = ["floof"]
while s[-1].find("end") is -1:
s.append(raw_input())
# parse pasted (inputted) text, putting the good bits into our data array
for text in s:
if text.find("has provided us with") is not -1:
donor = text[:text.find(" has provided")].strip()
qty = text[text.find("$")+1 : text.find(" in campaign")]
print donor
print qty
if donor not in labels:
labels.append(donor)
labelIndex = labels.index(donor)
if labelIndex is -1 or labelIndex > numPeople-1:
print("\n!!!Trying to put in too many people!\n!!!You should increase numPeople, cuz " + donor + " will be ignored!\n\n")
else:
matrix[receiverIndex][labelIndex] += int(qty)
else:
print("Floofy input")
print labels
print matrix
if __name__ == "__main__":
#labels=['Emma', 'Isabella', 'Ava', 'Olivia', 'Sophia']
#matrix=np.array([[16, 3, 28, 0, 18],
# [18, 0, 12, 5, 29],
# [ 9, 11, 17, 27, 0],
# [19, 0, 31, 11, 12],
# [23, 17, 10, 0, 34]], dtype=int)
chordplot1.doCircleRibbonGraph(labels, matrix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment