Permalink
Browse files

enough playing with visualization for now

  • Loading branch information...
abie
abie committed Nov 28, 2011
1 parent a4da022 commit b84280b7eb70b1170a452aa8762268e4b6872093
Showing with 44 additions and 15 deletions.
  1. +24 −9 viz/force.js
  2. +1 −0 viz/t.json
  3. +19 −6 viz/viz_comments.py
View
@@ -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"]);
@@ -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));
@@ -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; })
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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()
@@ -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']

0 comments on commit b84280b

Please sign in to comment.