Skip to content

Commit

Permalink
wordcloud sorta works
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Sep 2, 2010
1 parent e53b2d1 commit a01e47f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _attachments/index.html
Expand Up @@ -13,8 +13,7 @@ <h1><a href="#/">Twebz</a> - Decentralizing Twitter, One Tweet at a Time</h1>
<div id="items"></div>

<div id="sidebar">
<p>Edit welcome message.</p>
<p>Ideas: You could easily turn this into a photo sharing app, or a grocery list, or a chat room.</p>
<div id="wordcloud"></div>
</div>
</body>
<script src="vendor/couchapp/loader.js"></script>
Expand All @@ -27,6 +26,7 @@ <h1><a href="#/">Twebz</a> - Decentralizing Twitter, One Tweet at a Time</h1>
$("#profile").evently("profile", app);
$.evently.connect("#account","#profile", ["loggedIn","loggedOut"]);
$("#items").evently("items", app);
$("#wordcloud").evently("wordcloud", app);
$.pathbinder.begin("/");
});
</script>
Expand Down
21 changes: 21 additions & 0 deletions evently/wordcloud/recent/data.js
@@ -0,0 +1,21 @@
function(view) {
var row, i, gWC = [], max =0, count, total = 0,
maxPerc, multpl;

for (i=0; i < view.rows.length; i++) {
count = view.rows[i].value;
total += count;
if (count > max) max = count;
}
maxPerc = max / total;
multpl = 100 / maxPerc;
for (i=0; i < view.rows.length; i++) {
row = view.rows[i];
if (row.value > 4) {
gWC.push({word: row.key, size:5+10*Math.log(1+(row.value / total) * multpl)});
}
};
return {
cloud : gWC
};
};
4 changes: 4 additions & 0 deletions evently/wordcloud/recent/mustache.html
@@ -0,0 +1,4 @@
<p>Word count</p>
{{#cloud}}
<a href="#/search/{{word}}" style="font-size:{{size}}px">{{word}}</a>
{{/cloud}}
1 change: 1 addition & 0 deletions evently/wordcloud/recent/path.txt
@@ -0,0 +1 @@
/
4 changes: 4 additions & 0 deletions evently/wordcloud/recent/query.json
@@ -0,0 +1,4 @@
{
"view" : "globalWordCount",
"group" : true
}
21 changes: 21 additions & 0 deletions evently/wordcloud/user/data.js
@@ -0,0 +1,21 @@
function(view) {
var row, i, gWC = [], max =0, count, total = 0,
maxPerc, multpl;

for (i=0; i < view.rows.length; i++) {
count = view.rows[i].value;
total += count;
if (count > max) max = count;
}
maxPerc = max / total;
multpl = 100 / maxPerc;
for (i=0; i < view.rows.length; i++) {
row = view.rows[i];
if (row.value > 2) {
gWC.push({word: row.key[1], size:5+10*Math.log(1+(row.value / total) * multpl)});
}
};
return {
cloud : gWC
};
};
4 changes: 4 additions & 0 deletions evently/wordcloud/user/mustache.html
@@ -0,0 +1,4 @@
<p>Word count</p>
{{#cloud}}
<a href="#/search/{{word}}" style="font-size:{{size}}px">{{word}}</a>
{{/cloud}}
1 change: 1 addition & 0 deletions evently/wordcloud/user/path.txt
@@ -0,0 +1 @@
/user/:screen_name
9 changes: 9 additions & 0 deletions evently/wordcloud/user/query.js
@@ -0,0 +1,9 @@
function(e, params) {
var name = params.screen_name;
return {
"view" : "userWordCloud",
startkey : [name],
endkey : [name, {}],
"group" : true
}
};
4 changes: 2 additions & 2 deletions views/userWordCloud/map.js
@@ -1,5 +1,5 @@
function(tweet) {
if (tweet.id && tweet.text && tweet.user && tweet.user.id) {
if (tweet.id && tweet.text && tweet.user && tweet.user.screen_name) {
var wordCounts = {};
var words = tweet.text.toLowerCase().split(/\s/);
words.forEach(function(word) {
Expand All @@ -12,7 +12,7 @@ function(tweet) {
});
for (var w in wordCounts) {
if (wordCounts.hasOwnProperty(w))
emit([tweet.user.id, w], (parseInt(wordCounts[w]) || 0));
emit([tweet.user.screen_name, w], (parseInt(wordCounts[w]) || 0));
}
}
};

0 comments on commit a01e47f

Please sign in to comment.