Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpmckenna8/d3f6fa5868a03f3ffccd to your computer and use it in GitHub Desktop.
Save mpmckenna8/d3f6fa5868a03f3ffccd to your computer and use it in GitHub Desktop.
Top twitterers from a json dataset d3.js

Right after the first MaptimeDC I did a query to the twitter API and saved the results to a file. The search with the API doesn't get everything and there are definitely problems with using this for analysis. For example I end up on this list and I think I may have retweeted something including maptimeDC but don't think I created anything original w/ that string in it. So my query returned 44 unique ids with tweets. I decided to use the maptimeDC query because it didn't quite make it to the 100 tweet limit the maptime or maptimeSF get up to yet still returned 70 some to work with. Great job maptimDCers for giving me a good practice dataset! For other maptime twitter datasets see my mapTwit repo where I'll post script examples so you can create your own datasets and put em' in files or databases or what have you. Plus I'm sure I/you can do better than just a text visualization w/ d3, but for now let's make more data by tweeting w/ #maptime.

Because I don't make top whatever lists often I'll take this chance to make a top 3 twitterers using maptimeDC:

Bonnie Bogle:7

Rosemary Wardley:7

Maptime HQ:5

So follow them if you want to get to know more about when a MaptimeDC is coming up and as always let me know what can be better with this code and feel free to make it better and share w/ me!

<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script src="twinfo.js"> </script>
</body>
var ugger = d3.json('/mpmckenna8/raw/7ea8d78ddee6fe930d67/maptimeDC.json', shower);
d3.select('body').append('div').attr('class', 'twitters')
function shower(err,data){
if (err) {console.log(err)};
//console.log(data);
var tweeters = []
for (var o in data){
// tweTab.append('tr').append('td').
// console.log(data[o].user.name)
tweeters.push(data[o].user.name)
};
console.log(tweeters.length)
// this and a bunch of other similar functions at: http://www.htmlforums.com/client-side-scripting/t-javascript-get-a-count-of-array-values-that-are-the-same-92328.html
function countAppearance( myArray ) {
var myBlocks = new Object ;
for( var i=0; i<myArray.length; i++ ) {
var aBlock = myArray[i] ;
if( myBlocks.hasOwnProperty( aBlock ) ) {
myBlocks[aBlock]++ ;
} else {
myBlocks[aBlock] = 1 ;
}
}
var str = "" ;
for( var j in myBlocks ) {
d3.select('.twitters').append('html:p')
.html( j +':<span class=\'nmmy\'>'+myBlocks[j] + '</span>').attr('class','eacher')
.attr('data-rank',function(){
return myBlocks[j]
});
str += "\t"+j+":"+myBlocks[j]+"\n" ;
}
console.log( str ) ;
}
countAppearance(tweeters);
d3.selectAll('.eacher')
.style('color',function(d){
//console.log(this)
d3.select('span')
.attr('class',function(d){
// console.log(this);
// console.log(d)
return 'eacher'
})
return 'purple';
})
var tweepers = 0
d3.selectAll('p')
.datum(function(){
console.log(this.dataset);
return this.dataset;
})
.sort(function(a,b){
return d3.descending(a.rank,b.rank);
})
.style('color',function(d,i){
//console.log(this.dataset)
console.log(d)
if(this.dataset.rank>4){
tweepers ++;
return 'red'}
else{
tweepers ++;
return 'blue'}
})
console.log(tweepers)
}
//console.log(ugger);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment