Exploration of micro-blogging visualization

Objectives

  1. Display a list of tweets
  2. Visualize a list of tweets
  3. Visualize a network of Twitter accounts
  4. Visualize tweets within a network of Twitter accounts
  5. Visualize a word cloud of hashtags
  6. Explore a twitter network centered on self


Tools used


To do

  1. fusion it with my social network visualization
    1. display links to wiki pages (thanks to PageList) holding hashtags the person has recently tweeted about
    2. look for matching hashtags for non mutual-followers
  2. Twitter social network flow
    1. propose the result to TopixTream.com
  3. Use serialize_json() to separate data extraction and visualization

Results

Source code of this page : Twitter-PHP/index.php.txt.

Display of a list of tweets

load(Twitter::ME_AND_FRIENDS); ?> deactivated for conciseness.

Visualize of a list of tweets

load(Twitter::ME_AND_FRIENDS); $tweets_count = count($channel->status); $processingpreloadcode = " float[][] e = new float[$tweets_count][3]; "; $processingsetupcode = " void setup(){ frameRate(15); size(800,200); strokeWeight(1); "; $processingdrawcode = " } void draw(){ background(255); fill(0, 102, 153); for (int j=0;j<$tweets_count;j++){ text(e[j][2],e[j][0]-10,e[j][1]); } "; $i=0; foreach ($channel->status as $status){ $name = $status->user->name; $text = addslashes(trim($status->text)); $text = preg_replace("/\n/", "", $text); $processingsetupcode .= "e[$i][0]=10+20*$i;"; $processingsetupcode .= "e[$i][1]=10+13*$i;"; $processingsetupcode .= "e[$i][2]=\"$name : $text\";\n"; $i++; } file_put_contents("twitter-viz.pjs",$processingpreloadcode.$processingsetupcode.$processingdrawcode."}"); ?>

twitter-viz.pjs file

Visualize a network of Twitter accounts

load(Twitter::ME_AND_FRIENDS); foreach ($channel->status as $status){ $name = $status->user->name; $network["$name"]["name"] = $name; if (!isset($network["$name"]["tweets"])) $network["$name"]["tweets"]=1; else $network["$name"]["tweets"]++; } $friends_count = count($network); $processingpreloadcode = " float[][] e = new float[$friends_count][3]; "; $processingsetupcode = " void setup(){ frameRate(15); size(800,200); strokeWeight(1); "; $processingdrawcode = " } void draw(){ background(255); fill(0, 102, 153); stroke(0, 102, 153); for (int j=0;j<$friends_count;j++){ text(e[j][2],e[j][0]-10,e[j][1]); } "; $i=0; foreach ($network as $friend){ $friend_name = $friend["name"]; $friend_tweets = $friend["tweets"]; $processingsetupcode .= "e[$i][0]=50*$friend_tweets;"; $processingsetupcode .= "e[$i][1]=10+13*$i;"; $processingsetupcode .= "e[$i][2]=\"$friend_name ($friend_tweets)\";\n"; $processingdrawcode .= "line(10,13*$i+5,50*$friend_tweets-20,13*$i+5);"; $i++; } file_put_contents("twitter-viz-network.pjs",$processingpreloadcode.$processingsetupcode.$processingdrawcode."}"); ?>
Followed accounts that tweeted recently positionned by counted tweets.

twitter-viz-network.pjs file

Visualize tweets within a network of Twitter accounts

A faire.

Visualize a word cloud of hashtags

load(Twitter::ME); foreach ($channel->status as $status){ $text = $status->text; $words = explode(" ",$text); foreach ($words as $word){ if (preg_match("/#/",$word)){ $date = intval(date("U", strtotime($status->created_at))); $hashtags[]["name"] = $word; $hashtags[count($hashtags)-1]["date"] = $date; } } } //$hashtags = array_unique($hashtags); $hashtags_count = count($hashtags); $width=800; $height=200; $processingpreloadcode = " float[][] e = new float[$hashtags_count][7]; "; $processingsetupcode = " void setup(){ frameRate(15); size($width,$height); strokeWeight(1); "; $processingdrawcode = " } void draw(){ background(255); for (int j=0;j<$hashtags_count;j++){ fill(e[j][3], e[j][4], e[j][5], e[j][6]); text(e[j][2],e[j][0]-10,e[j][1]); } "; $i=0; $oldest_hashtag_date=time(); $newest_hashtag_date=0; foreach ($hashtags as $hashtag){ if ($hashtag["date"] < $oldest_hashtag_date) $oldest_hashtag_date = $hashtag["date"]; if ($hashtag["date"] > $newest_hashtag_date) $newest_hashtag_date = $hashtag["date"]; } $step = ( $newest_hashtag_date - $oldest_hashtag_date ) / $hashtags_count; foreach ($hashtags as $hashtag){ $x = rand(0,$width-100); $y = 10 + rand(0,$height-10); //$r = rand(0,255); $g = rand(0,255); $b = rand(0,255); $r = $g = $b = 0; $hashtagname = $hashtag["name"]; $hashtagdate = $hashtag["date"]; $alpha = 255 - (( $newest_hashtag_date - $hashtagdate ) / $step ) * (200 / $hashtags_count ); $processingsetupcode .= "e[$i][0]=$x;"; $processingsetupcode .= "e[$i][1]=$y;"; $processingsetupcode .= "e[$i][2]=\"$hashtagname\";\n"; $processingsetupcode .= "e[$i][3]=$r;"; $processingsetupcode .= "e[$i][4]=$g;"; $processingsetupcode .= "e[$i][5]=$b;"; $processingsetupcode .= "e[$i][6]=$alpha;"; $i++; } file_put_contents("twitter-hashtags-cloud.pjs",$processingpreloadcode.$processingsetupcode.$processingdrawcode."}"); ?>
Own hashtags randomly positionned and with alpha proportionnal to age.

twitter-hashtags-cloud.pjs file

Explore a twitter network centered on self

Last replies:"; $channel = $twitter->load(Twitter::REPLIES); foreach ($channel->status as $status){ $name = $status->user->name; $extended_network["$name"]["name"] = $name; $text = $status->text; $words = explode(" ",$text); foreach ($words as $word){ if (preg_match("/@/",$word) && !preg_match("/utopiah/i",$word) ){ $extended_network["$name"]["further"][] = $word; } } } $network_count = count($extended_network); $width=800; $height=200; $processingpreloadcode = " float[][] e = new float[$network_count][7]; "; $processingsetupcode = " void setup(){ frameRate(15); size($width,$height); strokeWeight(1); "; $processingdrawcode = " } void draw(){ background(255); for (int j=0;j<$network_count;j++){ fill(e[j][3], e[j][4], e[j][5], e[j][6]); text(e[j][2],e[j][0]-10,e[j][1]); } "; $i=0; foreach ($extended_network as $node){ $x = rand(0,$width-100); $y = 10 + rand(0,$height-10); $r = rand(0,255); $g = rand(0,255); $b = rand(0,255); //$r = $g = $b = 0; $name = $node["name"]; $alpha = 255; if (isset($node["further"])) foreach ($node["further"] as $far_node){ $name .= "[$far_node] "; $alpha -= 20; } $processingsetupcode .= "e[$i][0]=$x;"; $processingsetupcode .= "e[$i][1]=$y;"; $processingsetupcode .= "e[$i][2]=\"$name\";"; $processingsetupcode .= "e[$i][3]=$r;"; $processingsetupcode .= "e[$i][4]=$g;"; $processingsetupcode .= "e[$i][5]=$b;"; $processingsetupcode .= "e[$i][6]=$alpha;\n"; $i++; } file_put_contents("twitter-replies-extra.pjs",$processingpreloadcode.$processingsetupcode.$processingdrawcode."}"); ?>
Using last replies to display last people mentioning myself (thus always removed) and listing others.

twitter-replies-extra.pjs file

Last mentions (of \"$search_keyword\"):"; $results = $twitter->search($search_keyword); foreach ($results as $result) { echo "
  • ".Twitter::clickable($result->text)." posted at $result->created_at by $result->form_user"; } ?>