Permalink
Browse files

Add This Week's Most Discerning Followers to Dashboard and Followers …

…page

Use Web Intents for user avatar links
Closes #973
  • Loading branch information...
1 parent 0f8f6c6 commit 70bcbd8577fc0327aabebf5b3576a634335b753f @ginatrapani ginatrapani committed Nov 3, 2011
View
11 tests/TestOfFollowMySQLDAO.php
@@ -71,13 +71,13 @@ protected function buildData() {
'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
$builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>14,
- 'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
+ 'last_seen'=>'-1d', 'first_seen'=>'-1d', 'network'=>'twitter'));
$builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>15,
- 'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
+ 'last_seen'=>'-1d', 'first_seen'=>'-8d', 'network'=>'twitter'));
$builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>1623457890,
- 'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
+ 'last_seen'=>'-2d', 'first_seen'=>'-2d', 'network'=>'twitter'));
$builders[] = FixtureBuilder::build('follows', array('user_id'=>1623457890, 'follower_id'=>1324567890,
'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
@@ -233,6 +233,11 @@ public function testGetLeastLikelyFollowers(){
$result = $this->DAO->getLeastLikelyFollowers(1324567890, 'twitter', 1, $page = 2);
$this->assertEqual($result[0]["user_id"], 1623457890);
+
+ $result = $this->DAO->getLeastLikelyFollowersThisWeek(1324567890, 'twitter', 15);
+ $this->assertIsA($result, "array");
+ $this->assertEqual(count($result), 1);
+ $this->assertEqual($result[0]["user_id"], 1623457890);
}
public function testGetEarliestJoinerFollowers(){
View
4 webapp/_lib/controller/class.DashboardController.php
@@ -210,8 +210,8 @@ private function loadDefaultDashboard() {
//follows
$follow_dao = DAOFactory::getDAO('FollowDAO');
- $least_likely_followers = $follow_dao->getLeastLikelyFollowers($this->instance->network_user_id, 'twitter',
- 12);
+ $least_likely_followers = $follow_dao->getLeastLikelyFollowersThisWeek($this->instance->network_user_id,
+ 'twitter', 12);
$this->addToView('least_likely_followers', $least_likely_followers);
//follower count history
View
25 webapp/_lib/model/class.FollowMySQLDAO.php
@@ -269,7 +269,7 @@ public function getMostFollowedFollowers($user_id, $network, $count = 20, $page
public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page = 1) {
$start_on_record = ($page - 1) * $count;
- $q = "SELECT u.*, ROUND(100*friend_count/follower_count,4) ";
+ $q = "SELECT u.*, ROUND((100*(friend_count/follower_count)),4) ";
$q .= "AS LikelihoodOfFollow, ".$this->getAverageTweetCount()." ";
$q .= "FROM #prefix#users AS u INNER JOIN #prefix#follows AS f ";
$q .= "ON u.user_id = f.follower_id ";
@@ -288,6 +288,29 @@ public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page =
return $this->getDataRowsAsArrays($ps);
}
+ public function getLeastLikelyFollowersThisWeek($user_id, $network, $count = 20, $page = 1) {
+ $start_on_record = ($page - 1) * $count;
+
+ $q = "SELECT u.*, ROUND((100*(friend_count/follower_count)),4) ";
+ $q .= "AS likelihood_of_follow, ".$this->getAverageTweetCount()." ";
+ $q .= "FROM #prefix#users AS u INNER JOIN #prefix#follows AS f ";
+ $q .= "ON u.user_id = f.follower_id ";
+ $q .= "WHERE f.first_seen >= date_sub(current_date, INTERVAL 7 day) ";
+ $q .= "AND f.user_id = :user_id AND f.network=:network AND f.network=u.network AND active=1 ";
+ $q .= "AND follower_count > 1000 AND friend_count > 0 ";
+ $q .= "ORDER BY likelihood_of_follow ASC, u.follower_count DESC ";
+ $q .= "LIMIT :start_on_record, :count ;";
+ $vars = array(
+ ':user_id'=>(string)$user_id,
+ ':network'=>$network,
+ ':count'=>(int)$count,
+ ':start_on_record'=>(int)$start_on_record
+ );
+ if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
+ $ps = $this->execute($q, $vars);
+ return $this->getDataRowsAsArrays($ps);
+ }
+
public function getEarliestJoinerFollowers($user_id, $network, $count = 20, $page = 1) {
$start_on_record = ($page - 1) * $count;
View
12 webapp/_lib/model/interface.FollowDAO.php
@@ -155,7 +155,7 @@ public function getOldestFollow($network);
public function getMostFollowedFollowers($user_id, $network, $count = 20, $page = 1);
/**
- * Gets the followes with highest follower:friend count.
+ * Gets the followers with highest follower:friend count.
* @param int $user_id
* @param str $network
* @param int $count
@@ -165,6 +165,16 @@ public function getMostFollowedFollowers($user_id, $network, $count = 20, $page
public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page = 1);
/**
+ * Gets the followers with highest follower:friend count first seen by ThinkUp in the past 7 days.
+ * @param int $user_id
+ * @param str $network
+ * @param int $count
+ * @param int $page defaults to 1
+ * @return array - numbered keys, with arrays - named keys
+ */
+ public function getLeastLikelyFollowersThisWeek($user_id, $network, $count = 20, $page = 1);
+
+ /**
* Gets the followers with the earliest join date.
* @param int $user_id
* @param str $network
View
4 webapp/_lib/view/dashboard.tpl
@@ -171,11 +171,11 @@
{/if}
{if $least_likely_followers}
<div class="clearfix">
- <h2>Most Discerning Followers</h2>
+ <h2>This Week's Most Discerning Followers</h2>
<div class="clearfix">
{foreach from=$least_likely_followers key=uid item=u name=foo}
<div class="avatar-container" style="float:left;margin:7px;">
- <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
</div>
{/foreach}
<div class="clearfix small prepend">
View
7 webapp/plugins/twitter/model/class.TwitterPlugin.php
@@ -250,9 +250,12 @@ public function getDashboardMenuItems($instance) {
$followers_ds1 = new Dataset('leastlikely', 'FollowDAO', "getLeastLikelyFollowers", array(
$instance->network_user_id, 'twitter', 13, '#page_number#'));
- $followers_ds1->addHelp('userguide/listings/twitter/dashboard_friends-mostactive');
$followers_menu_item->addDataset($followers_ds1);
+ $followers_ds9 = new Dataset('leastlikelythisweek', 'FollowDAO', "getLeastLikelyFollowersThisWeek", array(
+ $instance->network_user_id, 'twitter', 13, '#page_number#'));
+ $followers_menu_item->addDataset($followers_ds9);
+
$followers_ds2 = new Dataset("popular", 'FollowDAO', "getMostFollowedFollowers", array(
$instance->network_user_id, 'twitter', 13, '#page_number#'));
$followers_ds2->addHelp('userguide/listings/twitter/dashboard_followers-mostfollowed');
@@ -455,7 +458,7 @@ public function getDashboardMenuItems($instance) {
//List membership count history
$group_membership_history_tpl = Utils::getPluginViewDirectory('twitter').'twitter.listmembershipcount.tpl';
- $group_trend_tab = new MenuItem('List stats', 'Your list membership count over time',
+ $group_trend_tab = new MenuItem('List stats', 'Your list membership count over time',
$group_membership_history_tpl, 'followers');
$group_trend_tab_ds = new Dataset("list_membership_count_history_by_day", 'GroupMembershipCountDAO',
'getHistory', array($instance->network_user_id, 'twitter', 'DAY', 15));
View
18 webapp/plugins/twitter/view/followers.tpl
@@ -1,18 +1,28 @@
+{if $leastlikelythisweek|@count >1}
+ <h2>This Week's Most Discerning Followers</h2>
+ {foreach from=$leastlikelythisweek key=tid item=u name=foo}
+ <div class="avatar-container" style="float:left;margin:7px;">
+ <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ </div>
+ {/foreach}
+ <div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-leastlikely&u={$instance->network_username}&n=twitter">More...</a></div>
+{/if}
+
{if $leastlikely|@count >1}
- <h2>Most Discerning</h2>
+ <h2>All-Time Most Discerning Followers</h2>
{foreach from=$leastlikely key=tid item=u name=foo}
<div class="avatar-container" style="float:left;margin:7px;">
- <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
</div>
{/foreach}
<div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-leastlikely&u={$instance->network_username}&n=twitter">More...</a></div>
{/if}
{if $popular|@count >1}
- <h2>Most Popular</h2>
+ <h2>Most Popular Followers</h2>
{foreach from=$popular key=tid item=u name=foo}
<div class="avatar-container" style="float:left;margin:7px;">
- <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
</div>
{/foreach}
<div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-mostfollowed&u={$instance->network_username}&n=twitter">More...</a></div>

0 comments on commit 70bcbd8

Please sign in to comment.