Skip to content

Commit

Permalink
enough playing with visualization for now
Browse files Browse the repository at this point in the history
  • Loading branch information
abie committed Nov 28, 2011
1 parent a4da022 commit b84280b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
33 changes: 24 additions & 9 deletions viz/force.js
@@ -1,5 +1,5 @@
var w = 960,
h = 500,
var w = 1024,
h = 1024,
fill = d3.scale.linear()
.domain([-1,0,5,10,Infinity])
.range(["white", "green", "yellow", "red", "red"]);
Expand All @@ -11,23 +11,38 @@ var vis = d3.select("#chart").append("svg:svg")
d3.json("t.json", function(json) {
// create nodes and node index
var ix = {null:0};
users = {};
for (var r in json.results) {
users[json.results[r].user] = [];
}

var nodes = [{"content": "(original article)", "ups": 25, "downs": -1, "published": json.results[0].published-1.0}];
var i = 1;
for (r in json.results) {
n = json.results[r];
for (var r in json.results) {
var n = json.results[r];
ix[n.id] = nodes.length;
nodes.push(n);
ix[n.id] = i;
i++;
users[n.user].push(n.id)
}

// create links
var links = [];
for (i in json.results) {
for (var i in json.results) {
var id = json.results[i].id;
var p_id = json.results[i].parent_id;
links.push({"source":ix[p_id], "target":ix[id], "weight":1});
}

// add squares for users
var user_list = [];
for (var u in users) {
user_list.push(u);
}
var user = vis.selectAll("circle")
.data(user_list)
.enter().append("svg:circle")
.attr("cx", 10)
.attr("cy", function(d, i) { return 10*i; });

var link_distance = function(link) {
d = (link.target.published - link.source.published);
return 1.0 + Math.log(1.0 + Math.abs(d/1000.0));
Expand All @@ -46,7 +61,7 @@ d3.json("t.json", function(json) {
.data(links)
.enter().append("svg:line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); })
.style("stroke-width", 1.0)
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
Expand Down
1 change: 1 addition & 0 deletions viz/t.json

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions viz/viz_comments.py
Expand Up @@ -2,11 +2,15 @@
import simplejson as json
import networkx as nx

r = requests.get('http://occupywallst.org/api/safe/article_get/?article_slug=occupy-seattle-occupies-wal-mart')
article_slug = 'occupy-seattle-occupies-wal-mart'
article_slug = 'answering-egypts-call-solidarity'
article_slug = 'solidarity-striking-chinese-workers'

r = requests.get('http://occupywallst.org/api/safe/article_get/?article_slug=%s'%article_slug)
j = json.loads(r.content)
article = j['results'][0]

r = requests.get('http://occupywallst.org/api/safe/article_get_comments/?article_slug=occupy-seattle-occupies-wal-mart')
r = requests.get('http://occupywallst.org/api/safe/article_get_comments/?article_slug=%s'%article_slug)
j = json.loads(r.content)

G = nx.DiGraph()
Expand Down Expand Up @@ -36,10 +40,19 @@
G.node[u]['karma'] = (G.node[u]['ups'] - G.node[u]['downs']) / len(G[u])

# list the posts from the highest karma users
high_karma = [u for u in G.users if G.node[u]['karma'] >= 3.0]
for u in high_karma:
print u
for c in G[u]:
#high_karma = [u for u in G.users if G.node[u]['karma'] >= 3.0]
#for u in high_karma:
# print u
# for c in G[u]:
# print '#%d:'%c,
# print '(%d hr)' % ((G.node[c]['published'] - G.node['original article']['published'])/(1000*3600)),
# print G.node[c]['content']
# print

for c in G:
if c in G.users:
continue
if G.node[c]['karma'] >= 3.0:
print '#%d:'%c,
print '(%d hr)' % ((G.node[c]['published'] - G.node['original article']['published'])/(1000*3600)),
print G.node[c]['content']
Expand Down

0 comments on commit b84280b

Please sign in to comment.